increase image compression level and re-enabled thread

This commit is contained in:
2025-01-22 13:46:47 +01:00
parent 69eba455f9
commit 0a8b96a45a

View File

@@ -421,7 +421,7 @@ void sendKobukiData(TKobukiData &data)
}
void CapnSend() {
int COMPRESSION_LEVEL = 80;
int COMPRESSION_LEVEL = 90;
VideoCapture cap(0); // Open the camera
if (!cap.isOpened()) {
cerr << "Error: Could not open camera" << endl;
@@ -446,17 +446,17 @@ void CapnSend() {
}
}
// Compress the image (JPEG compression with adjustable quality)
vector<uchar> buf;
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, buf, compression_params);
imencode(".jpg", frame, imgbuf, compression_params);
// Convert the vector<uchar> buffer to a string (no casting)
string enc_msg(buf.begin(), buf.end());
string enc_msg(imgbuf.begin(), imgbuf.end());
// Publish the compressed image data (MQTT, in this case)
client.publishMessage("kobuki/cam", enc_msg);