mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-05 12:54:57 +00:00
Compare commits
3 Commits
f493665275
...
0a8b96a45a
Author | SHA1 | Date | |
---|---|---|---|
0a8b96a45a | |||
69eba455f9 | |||
e262325565 |
@@ -407,6 +407,7 @@ std::string serializeKobukiData(const TKobukiData &data)
|
||||
json += "]}";
|
||||
return json;
|
||||
}
|
||||
|
||||
// create extra function to send the message every 100ms
|
||||
// needed it so it can be threaded
|
||||
void sendKobukiData(TKobukiData &data)
|
||||
@@ -420,7 +421,8 @@ void sendKobukiData(TKobukiData &data)
|
||||
}
|
||||
|
||||
void CapnSend() {
|
||||
VideoCapture cap(0);
|
||||
int COMPRESSION_LEVEL = 90;
|
||||
VideoCapture cap(0); // Open the camera
|
||||
if (!cap.isOpened()) {
|
||||
cerr << "Error: Could not open camera" << endl;
|
||||
return;
|
||||
@@ -444,14 +446,21 @@ 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());
|
||||
|
||||
// Publish the image data
|
||||
client.publishMessage("kobuki/cam", string(enc_msg, enc_msg + buf.size()));
|
||||
cout << "Sent image" << endl;
|
||||
vector<uchar> imgbuf;
|
||||
vector<int> compression_params;
|
||||
compression_params.push_back(IMWRITE_JPEG_QUALITY); // Set JPEG quality
|
||||
compression_params.push_back(COMPRESSION_LEVEL); // Adjust the quality level (0-100, lower = more compression)
|
||||
|
||||
// Encode the image into the byte buffer with the specified compression parameters
|
||||
imencode(".jpg", frame, imgbuf, compression_params);
|
||||
|
||||
// Convert the vector<uchar> buffer to a string (no casting)
|
||||
string enc_msg(imgbuf.begin(), imgbuf.end());
|
||||
|
||||
// Publish the compressed image data (MQTT, in this case)
|
||||
client.publishMessage("kobuki/cam", enc_msg);
|
||||
cout << "Sent compressed image" << endl;
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // Send image every 200ms
|
||||
}
|
||||
|
Reference in New Issue
Block a user