Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opencv copy 3 channel IplImage to 4 channel IplImage

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!

like image 404
Sharpie Avatar asked Jan 19 '23 02:01

Sharpie


1 Answers

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.

like image 101
Kristóf Marussy Avatar answered Jan 31 '23 08:01

Kristóf Marussy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!