Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV: transforming 3 channel image into 4 channel

I am trying to change 3-channel image into 4-channel like this:

cv::VideoCapture video;
video.open("sample.avi");
cv::Mat source;
cv::Mat newSrc;
int from_to = { 0,0, 1,1, 2,2, 3,3 };
for ( int i = 0; i < 1000; i ++ )
{
   video >> source;
   cv::mixChannels ( source, 2, newSrc, 1, from_to, 4 );
}

Then I got

too many input arguments in function call

for the 'mixChannels' line. Besides, I am not sure whether I am giving the arguments correctly for my goal. Can someone help me? Thank you.

like image 308
E_learner Avatar asked Nov 19 '12 10:11

E_learner


2 Answers

You can convert 3 channel image to 4 channel as follows:

cv::Mat source = cv::imread(path);

cv::Mat newSrc(source.size(), CV_MAKE_TYPE(source.depth(), 4));

int from_to[] = { 0,0, 1,1, 2,2, 2,3 };

cv::mixChannels(&source,1,&newSrc,1,from_to,4);

This way channel 4 will be a duplicate of channel 3. By using a negative number in the from_to list, the output channel is zero filled. eg:

int from_to[] = { 0,0, 1,1, 2,2, -1,3 };
like image 176
sgarizvi Avatar answered Sep 19 '22 09:09

sgarizvi


What is the 4th channel supposed to contain? How about:

VideoCapture cap(0);
Mat frame;
cap >> frame;

Mat RGBA(frame.size(), CV_8UC4, camData);
cv::cvtColor(frame, RGBA, CV_BGR2RGBA, 4);
like image 20
Herr von Wurst Avatar answered Sep 22 '22 09:09

Herr von Wurst