Opencv copy 3 channel IplImage to 4 channel IplImage

吃可爱长大的小学妹 提交于 2019-12-06 05:35:24

问题


When I try to use cvCopy a IplImage consisting of 3 channels to a IplImage with 4 channels (I need the extra channel later) all I get is an error message.

Is there another way to increase the channel count of an IplImage without loosing the data that it already holds?

Thanks!


回答1:


Use cvMixChannels, like this:

CvMat * src; // your source image
CvMat * dst // your destination image
CvMat * zeros = cvCreateMat(src->cols, src->rows, CV_8UC1);
cvSet(zeros, cvScalar(0, 0, 0, 0));
CvArr * input[] = { src, zeros };
int from_to[] = { 0,0, 1,1, 2,2, 3,3 };
cvMixChannels(input, 2, &dst, 1, from_to, 4);

It will perform only the copy operations that are neccessary, unlike cvSplit and cvMerge.




回答2:


I am not sure, the way i'm gonna suggest is the easiest one :

  1. You can first split your image with cvSplit() into 3 separate images (one for each channel)
  2. Then you recompose a 4 channels one with 3 channels + the one you will add using the function cvMerge()....

Look at the documentation here,

  • Doc here ==> cvSplit()
  • Doc here ==> cvMerge()

Julien,



来源:https://stackoverflow.com/questions/6871978/opencv-copy-3-channel-iplimage-to-4-channel-iplimage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!