I am trying to compose cv::Mat
image from std::basic_string<char>
but the composed image is empty. Below is the code snippet:
std::basic_string<char> color_pixels = color_frame.data();
cv::Mat image(cv::Size(color_frame.width(), color_frame.height()),
CV_8UC4,
&color_pixels,
cv::Mat::AUTO_STEP);
Before proceeding further, I wanted to verify the data. Hence I checked width
, height
etc and found correct.
std::cout << "width:" << color_frame.width() <<
", height:" << color_frame.height() <<
", length:" << color_pixels.length() << std::endl;
width:1920, height:1080, length:8294400 // 1920 * 1080 * 4 = 8294400
I found a similar question here and tried to implement in my code as follows:
cv::Mat image(cv::Size(color_frame.width(), color_frame.height()),
CV_8UC4,
color_pixels.data(),
cv::Mat::AUTO_STEP);
Unfortunately, it is throwing following error:
error: invalid conversion from ‘const void*’ to ‘void*’
How to compose cv::Mat Image from std::basic_string? Any workaround, please?