Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
962 views
in Technique[技术] by (71.8m points)

c++ - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 };

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...