For Nvidia jetson realsense depth map in touchdesigner, I needed to turn the OpenCV Mat into a single string to send OSC out in C++ using OSCPP.
Here’s the code I used to do that:
cv::Mat processedImage;
if(image.type() != CV_8UC1) {
image.convertTo(processedImage, CV_8UC1);
} else {
processedImage = image;
}
// flatten image data
std::vector<unsigned char> imageData;
if (processedImage.isContinuous()) {
// assign starrtbyte, till endbyte to imageData
imageData.assign(processedImage.data, processedImage.data + processedImage.total());
} else {
// if image is in multiple rows, for every row
for (int i = 0; i < processedImage.rows; i++) {
// join rows
imageData.insert(imageData.end(), processedImage.ptr<unsigned char>(i), processedImage.ptr<unsigned char>(i) + processedImage.cols);
}