UnableToLoad
UnableToLoad

Reputation: 315

cvSetImageData and cvCreateImage c++ equivalent interface

Is there any c++ opencv interface that can do the same operation of these two functions?

Hi, I'm actually using these two functions in this way

IplImage *image;
ARUint8 *dataPtr; // unsigned chars, in format ARGB
cv::Size size;

//do stuff

image = cvCreateImage(*size, IPL_DEPTH_8U, channels );

cvSetImageData( image, dataPtr, size->width * channels );

The fitst one creates is used to initialize an empty IplImage *image, the second one to copy the raw data from an external source (dataPtr) to the image itself.

I know that the first one should be trivial, replacing the IplImage con un cv::Mat, the problem is that I don't know how to pass the parameter "IPL_DEPTH_8U" to the constructor.

To copy the data with the c++ interface, i have no clue...

PS: ARUint8 *dataPtr is my source of data, I cannot have another source, but then I need to convert it to opencv data representation

Thanks in advance!

Upvotes: 0

Views: 7066

Answers (1)

WildCrustacean
WildCrustacean

Reputation: 5966

Like you suspected, in the C++ interface you do this via the constructor for cv::Mat. You will have to use the appropriate type corresponding to IPL_DEPTH_8U (probably CV_8U or CV_8UC3 depending on how many channels you have).

One of the constructor overloads can take a raw pointer to existing data, so you could do it like this:

cv::Mat image(size, CV_8U, (void*)dataPtr);

Note also that the cv::Mat constructor can take a step argument, which is needed if your data has padding at the end of the rows, or any other more complicated format.

You can also always browse the OpenCV documentation for Mat::Mat online for more details.

Upvotes: 1

Related Questions