简体   繁体   English

在opencv for c中,什么功能与Mat :: convertTo和cvtColor()完全相同

[英]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: 我试图理解opencv的c函数cvSaveImage并与此处的2.4.6文档有关:

The function save-image saves the image to the specified file. 功能save-image将图像保存到指定文件。 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. 使用此功能只能保存8位(在PNGJPEG 2000TIFF情况下为16位无符号(+ 16u +))单通道或3通道(具有'BGR'通道顺序)图像。 If the format, depth or channel order is different, use Mat::convertTo() , and cvtColor() to convert it before saving. 如果格式,深度或通道顺序不同,请在保存之前使用Mat::convertTo()cvtColor()进行转换。 Or, use the universal XML I/O functions to save the image to XML or YAML format. 或者,使用通用XML I / O功能将图像保存为XML或YAML格式。

it says "If the format, depth or channel order is different, use Mat::convertTo() , and cvtColor() to convert it before saving." 它说:“如果格式,深度或通道顺序不同,请在保存之前使用Mat::convertTo()cvtColor()进行转换。”

what functions would do the same thing in the c interface. 哪些函数在c接口中会执行相同的操作。 if possible please in include example code in your reply. 如果可能的话,请在回复中包含示例代码。

Hm.. I think you are looking for cvCvtColor : 嗯..我想您正在寻找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 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: 例如,如果您有RGBA图像,并想将其转换为BGR以进行保存:

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. 请记住,如果rgba_src是来自捕获设备的帧,则不应释放它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM