change camera logic

This commit is contained in:
2024-12-11 15:37:31 +01:00
parent 60ba177dc2
commit 7f786d5197

View File

@@ -293,32 +293,39 @@ void sendKobukiData(TKobukiData &data)
void CapnSend() void CapnSend()
{ {
std::string pipeline = "libcamerasrc ! video/x-raw,width=640,height=480,framerate=30/1 ! videoconvert ! appsink"; VideoCapture cap;
VideoCapture cap(pipeline, cv::CAP_GSTREAMER); if (!cap.open("/dev/video0", cv::CAP_V4L2))
if (!cap.isOpened())
{ {
cerr << "Error: Could not open camera" << endl; cerr << "Error: Could not open camera with /dev/video0" << endl;
return; if (!cap.open("/dev/video1", cv::CAP_V4L2))
}
Mat frame;
while (true)
{
cap >> frame; // Capture a new image frame
if (frame.empty())
{ {
cerr << "Error: Could not capture image" << endl; cerr << "Error: Could not open camera with /dev/video1" << endl;
continue; if (!cap.open("/dev/media2", cv::CAP_V4L2))
{
cerr << "Error: Could not open camera with /dev/video1" << endl;
return;
}
}
}
Mat frame;
while (true)
{
cap >> frame; // Capture a new image frame
if (frame.empty())
{
cerr << "Error: Could not capture image" << endl;
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()));
cout << "Sent image" << endl;
std::this_thread::sleep_for(std::chrono::milliseconds(400)); // Send image every 1000ms
} }
// 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()));
cout << "Sent image" << endl;
std::this_thread::sleep_for(std::chrono::milliseconds(400)); // Send image every 1000ms
} }
}