0
votes

I have a uchar* raw from an API which represents an image raw data. The width, height and number of channels of this raw is already known. I have already pre-allocated an cv::Mat (OpenCV) with this width and height.

My question is - how is it possible to set raw into this cv::Mat. I would like to copy raw into cv::Mat instead of just switching pointers. Is there a function to accomplish this or I need to do so manually myself?

2
cv::Mat(size, CV_8UC1, raw).copyTo (yourPreallocatedImage);Micka

2 Answers

1
votes

I guess it isn't the most sophisticated way but it should work:

uchar* raw; cv::Mat image(size, type, raw); image = image.clone();

-1
votes
cv::Mat mat(cv::Size(width, height), CV_8UC1, raw, cv::Mat::AUTO_STEP);

copiedImage = mat.clone();