use libcamera with picam

This commit is contained in:
2024-12-11 16:30:14 +01:00
parent 8158c85d6e
commit c2886d32c9

View File

@@ -281,12 +281,12 @@ void sendKobukiData(TKobukiData &data) {
} }
} }
void CapnSend() { void CapnSend() {
// Use OpenNI2 backend to access the Astra camera // Use GStreamer pipeline to access the Astra camera with libcamera
VideoCapture cap(cv::CAP_OPENNI2); std::string pipeline = "libcamerasrc ! video/x-raw,width=640,height=480,framerate=30/1 ! videoconvert ! appsink";
VideoCapture cap(pipeline, cv::CAP_GSTREAMER);
if (!cap.isOpened()) { if (!cap.isOpened()) {
cerr << "Error: Could not open Astra camera with OpenNI2 backend" << endl; cerr << "Error: Could not open camera with GStreamer pipeline" << endl;
return; return;
} }
@@ -304,8 +304,9 @@ void CapnSend() {
auto* enc_msg = reinterpret_cast<unsigned char*>(buf.data()); auto* enc_msg = reinterpret_cast<unsigned char*>(buf.data());
// Publish the image data // Publish the image data
client.publishMessage("kobuki/cam-", string(enc_msg, enc_msg + buf.size())); 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(400)); // Send image every 1000ms
std::this_thread::sleep_for(std::chrono::milliseconds(1000)); // Send image every 1000ms
} }
} }