mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-03 20:04:58 +00:00
rtsp stream opencv using gstreamen
This commit is contained in:
@@ -289,12 +289,23 @@ void sendKobukiData(TKobukiData &data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CapnSend() {
|
void CapnSend() {
|
||||||
VideoCapture cap(0);
|
int fps = 15;
|
||||||
|
int width = 800;
|
||||||
|
int height = 600;
|
||||||
|
|
||||||
|
VideoCapture cap("/dev/video0");
|
||||||
if (!cap.isOpened()) {
|
if (!cap.isOpened()) {
|
||||||
cerr << "Error: Could not open camera" << endl;
|
cerr << "Error: Could not open camera" << endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VideoWriter out("appsrc ! videoconvert ! video/x-raw,format=I420 ! x264enc speed-preset=ultrafast bitrate=600 key-int-max=" + to_string(fps * 2) + " ! video/x-h264,profile=baseline ! rtspclientsink location=rtsp://localhost:8554/mystream",
|
||||||
|
CAP_GSTREAMER, 0, fps, Size(width, height), true);
|
||||||
|
if (!out.isOpened()) {
|
||||||
|
cerr << "Error: Can't open video writer" << endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Mat frame;
|
Mat frame;
|
||||||
while (true) {
|
while (true) {
|
||||||
cap >> frame; // Capture a new image frame
|
cap >> frame; // Capture a new image frame
|
||||||
@@ -303,15 +314,10 @@ void CapnSend() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert the image to a byte array
|
// Write the frame to the RTSP stream
|
||||||
vector<uchar> buf;
|
out.write(frame);
|
||||||
imencode(".jpg", frame, buf);
|
|
||||||
auto* enc_msg = reinterpret_cast<unsigned char*>(buf.data());
|
|
||||||
|
|
||||||
// Publish the image data
|
|
||||||
client.publishMessage("kobuki/cam", string(enc_msg, enc_msg + buf.size()));
|
|
||||||
cout << "Sent image" << endl;
|
cout << "Sent image" << endl;
|
||||||
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // Send image every 200ms
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000 / fps)); // Control the frame rate
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user