-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
separated the webcam module into web and webcam modules #12
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef INTELCAM_H | ||
#define INTELCAM_H | ||
|
||
#include <librealsense2/rs.hpp> | ||
#include <iostream> | ||
#include <vector> | ||
#include <cmath> | ||
|
||
const float TIME_INTERVAL = 0.01; // Time interval in seconds | ||
const double RAD_TO_DEG = 180.0 / M_PI; | ||
|
||
|
||
using namespace std | ||
|
||
class realIntelCam | ||
{ | ||
public: | ||
|
||
RealIntelCam(); | ||
|
||
void update_camera_position(); | ||
|
||
vector<float> get_location(); | ||
|
||
vector<float> get_angle(); | ||
|
||
private: | ||
//Essential to initiate connection | ||
rs2::pipeline pipeline; | ||
rs2::config configure; | ||
rs2::pipeline_profile profile; | ||
// the acceleration in 3D previous: 0->x, 1->y, 2->z current 3->x, 4->y, 5->z | ||
float acceleration[]{}; | ||
// average velocity aka speed | ||
float velocity[]{}; | ||
// calculated location | ||
float camera_location[]; | ||
//calculated angle | ||
float camera_angle[]; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef WEB_INTERFACE_HPP | ||
#define WEB_INTERFACE_HPP | ||
|
||
int web(Mat *frame); | ||
|
||
#endif // WEBCAM_INTERFACE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
build_/mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/src/sample_submodule build_/mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/src/grass_killer build_/mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/src/imu_interface | ||
mkdir -p /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/build/objs | ||
mkdir -p /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/build | ||
g++ -I /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/include -c /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/src/sample_submodule/submodule.cpp -o /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/build/objs/submodule.o | ||
g++ -I /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/include -c /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/src/sample_submodule/arg.cpp -o /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/build/objs/arg.o | ||
g++ -I /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/include -c /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/src/grass_killer/grass_killer.cpp -o /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/build/objs/grass_killer.o | ||
g++ -I /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/include -c /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/src/imu_interface/measure.cpp -o /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/build/objs/measure.o | ||
[[[[ BUILDING NAVI ]]]] | ||
g++ /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/build/objs/main.o /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/build/objs/submodule.o /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/build/objs/arg.o /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/build/objs/grass_killer.o /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/build/objs/measure.o -o /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/navi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
GENERATED_OBJS := web_interface.o | ||
|
||
include submodule.general.mk | ||
|
||
build_$(DIR): | ||
$(call build,web_interface.cpp) | ||
clean_$(DIR): | ||
test_$(DIR): | ||
@echo testing the module $(DIR)! | ||
test_webcam_interface: test_$(DIR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include <websocketpp/config/asio_no_tls.hpp> | ||
#include <websocketpp/server.hpp> | ||
#include <thread> | ||
|
||
using namespace std; | ||
using namespace cv; | ||
|
||
// Alias for websocketpp server | ||
typedef websocketpp::server<websocketpp::config::asio> server; | ||
|
||
/*! | ||
* Handles the connection to the WebSocket server. | ||
* Captures frames from the webcam, encodes them, | ||
* and sends them via the WebSocket connection. | ||
* | ||
* \param hdl The connection handle. | ||
* \param s The WebSocket server. | ||
* \param cap The OpenCV VideoCapture object. | ||
*/ | ||
void handle_connection(websocketpp::connection_hdl hdl, server& s, Mat *frame) { | ||
while (true) { | ||
try { | ||
if (!frame->empty()) { | ||
// Convert OpenCV frame to byte vector | ||
vector<uchar> buffer; | ||
imencode(".jpg", *frame, buffer); | ||
s.send(hdl, buffer.data(), buffer.size(), websocketpp::frame::opcode::binary); | ||
} | ||
else { | ||
cerr << "Couldn't capture frame from webcam." << endl; | ||
break; | ||
} | ||
} catch (websocketpp::exception const & e) { | ||
cout << "Caught websocket exception: " << e.what() << endl; | ||
} | ||
} | ||
} | ||
|
||
/*! | ||
* Initializes and runs the WebSocket server, capturing frames | ||
* from the webcam and sending them via open WebSocket connections. | ||
* | ||
* Clears all access log channels, initializes the OpenCV webcam, | ||
* defines the WebSocket server connection handler, listens on port 6969, | ||
* and finally starts the accept loop and the ASIO io_service event loop. | ||
* | ||
* \return 0 if the server ran successfully, otherwise -1. | ||
*/ | ||
int web(Mat *frame) { | ||
// Create a WebSocket server | ||
server s; | ||
// Clear all access log channels to prevent frames being logged | ||
// If frames are logged, then it makes the WebSocket server very slow | ||
s.clear_access_channels(websocketpp::log::alevel::all); | ||
|
||
s.set_open_handler([&s,frame](websocketpp::connection_hdl hdl) { | ||
thread video_thread(handle_connection, hdl, ref(s), ref(frame)); | ||
video_thread.detach(); | ||
}); | ||
|
||
// Listen on port 6969 | ||
s.init_asio(); | ||
s.listen(6969); | ||
s.start_accept(); | ||
s.run(); | ||
|
||
return 0; | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be committed.