user2735131
user2735131

Reputation:

in opencv for c what function does the exact same thing as Mat::convertTo and cvtColor()

Im trying to understand opencv's c function cvSaveImage and pertaining to the 2.4.6 documentation here:

The function save-image saves the image to the specified file. The image format is
chosen based on the filename extension (see (load-image) for the list of extensions). Only 8-bit (or 16-bit unsigned (+16u+) in case of PNG,JPEG 2000, and TIFF) single- channel or 3-channel (with ‘BGR’ channel order) images can be saved using this function. If the format, depth or channel order is different, use Mat::convertTo() , and cvtColor() to convert it before saving. Or, use the universal XML I/O functions to save the image to XML orYAML format.

it says "If the format, depth or channel order is different, use Mat::convertTo() , and cvtColor() to convert it before saving."

what functions would do the same thing in the c interface. if possible please in include example code in your reply.

Upvotes: 1

Views: 818

Answers (1)

Marco
Marco

Reputation: 2897

Hm.. I think you are looking for cvCvtColor:

void cvCvtColor(const CvArr *src, CvArr *dst, int code) 

Converts an image from one color space to another.

http://opencv.willowgarage.com/documentation/c/miscellaneous_image_transformations.html

For example if you have a RGBA image and want to convert it to BGR for saving:

cvCvtColor(rgba_src, bgr_dst, CV_RGBA2BGR)

In actual code it would be something like:

/* Create an IplImage with 3 channels and 8 bits per channel,
   with the same dimensions that rgba_src*/
IplImage *bgr_dst = cvCreateImage(cvGetSize(rgba_src), IPL_DEPTH_8U, 3);

cvCvtColor(rgba_src, bgr_dst, CV_RGBA2BGR);
cvReleaseImage(&rgba_src);

Something like that. Remember that you should not release rgba_src if it is a frame from a capture device.

Upvotes: 2

Related Questions