mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-03 20:04:58 +00:00
Merge branch 'main' of ssh://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79
This commit is contained in:
@@ -387,25 +387,29 @@ void sendKobukiData(TKobukiData &data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CapnSend()
|
void CapnSend() {
|
||||||
{
|
|
||||||
VideoCapture cap(0);
|
VideoCapture cap(0);
|
||||||
if (!cap.isOpened())
|
if (!cap.isOpened()) {
|
||||||
{
|
cerr << "Error: Could not open camera" << endl;
|
||||||
cerr << "Error: Could not capture image" << endl;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mat frame;
|
Mat frame;
|
||||||
while (true)
|
while (true) {
|
||||||
{
|
if (!cap.read(frame)) {
|
||||||
cap >> frame; // Capture a new image frame
|
cout << "Reconnecting camera" << endl;
|
||||||
if (frame.empty())
|
cap.release();
|
||||||
{
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
cerr << "Error: Could not capture image" << endl;
|
// Attempt to reconnect to the camera
|
||||||
|
cap.open(0);
|
||||||
|
if (!cap.isOpened()) {
|
||||||
|
cerr << "Error: Could not reconnect to camera" << endl;
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1)); // Wait before retrying
|
std::this_thread::sleep_for(std::chrono::seconds(1)); // Wait before retrying
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
} else {
|
||||||
|
cout << "Reconnected to camera" << endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert the image to a byte array
|
// Convert the image to a byte array
|
||||||
@@ -418,13 +422,5 @@ void CapnSend()
|
|||||||
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(200)); // Send image every 200ms
|
||||||
|
|
||||||
if (!cap.isOpened())
|
|
||||||
{
|
|
||||||
cerr << "Camera disconnected, attempting to reconnect..." << endl;
|
|
||||||
|
|
||||||
cap.open(0);
|
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1)); // Wait before retrying
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user