mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-03 20:04:58 +00:00
attempt with gstreamer
This commit is contained in:
@@ -290,30 +290,19 @@ void sendKobukiData(TKobukiData &data)
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
}
|
||||
|
||||
void CapnSend()
|
||||
{
|
||||
VideoCapture cap;
|
||||
if (!cap.open("/dev/video0", cv::CAP_V4L2))
|
||||
{
|
||||
cerr << "Error: Could not open camera with /dev/video0" << endl;
|
||||
if (!cap.open("/dev/video1", cv::CAP_V4L2))
|
||||
{
|
||||
cerr << "Error: Could not open camera with /dev/video1" << endl;
|
||||
if (!cap.open("/dev/media2", cv::CAP_V4L2))
|
||||
{
|
||||
cerr << "Error: Could not open camera with /dev/video1" << endl;
|
||||
void CapnSend() {
|
||||
// Use GStreamer pipeline to access the PiCam
|
||||
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()) {
|
||||
cerr << "Error: Could not open camera with GStreamer pipeline" << endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Mat frame;
|
||||
while (true)
|
||||
{
|
||||
while (true) {
|
||||
cap >> frame; // Capture a new image frame
|
||||
if (frame.empty())
|
||||
{
|
||||
if (frame.empty()) {
|
||||
cerr << "Error: Could not capture image" << endl;
|
||||
continue;
|
||||
}
|
||||
@@ -321,11 +310,12 @@ void CapnSend()
|
||||
// Convert the image to a byte array
|
||||
vector<uchar> buf;
|
||||
imencode(".jpg", frame, buf);
|
||||
auto *enc_msg = reinterpret_cast<unsigned char *>(buf.data());
|
||||
auto* enc_msg = reinterpret_cast<unsigned char*>(buf.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;
|
||||
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
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user