4 Commits

Author SHA1 Message Date
ff89b8a742 revert and change port number 2025-01-14 15:07:44 +01:00
eaee4ebd60 change port 2025-01-14 15:06:54 +01:00
a4ba54161a change streaming protocol to udp 2025-01-14 15:04:06 +01:00
2448691e63 rtsp stream opencv using gstreamen 2025-01-14 14:55:59 +01:00

View File

@@ -289,12 +289,23 @@ void sendKobukiData(TKobukiData &data) {
}
void CapnSend() {
VideoCapture cap(0);
int fps = 15;
int width = 800;
int height = 600;
VideoCapture cap("/dev/video0");
if (!cap.isOpened()) {
cerr << "Error: Could not open camera" << endl;
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 ! mpegtsmux ! udpsink host=127.0.0.1 port=5001",
CAP_GSTREAMER, 0, fps, Size(width, height), true);
if (!out.isOpened()) {
cerr << "Error: Can't open video writer" << endl;
return;
}
Mat frame;
while (true) {
cap >> frame; // Capture a new image frame
@@ -303,15 +314,10 @@ void CapnSend() {
continue;
}
// Convert the image to a byte array
vector<uchar> buf;
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()));
// Write the frame to the UDP stream
out.write(frame);
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
}
}