Ask Your Question
0

When merging channels, assertion failed error occurs.

asked 2019-04-28 06:31:59 -0500

hua gravatar image

I separate BGR channels and operate on each channel and finally want to merge the enhanced BGR channels together into the output image. But the following error occurs.

/* Final Image */
vector<Mat> finalImgCh(3);
Mat finalImage(src.size(), CV_8UC3);
finalImgCh.push_back(Norm_b); // image type = CV_8UC1
finalImgCh.push_back(Norm_g);
finalImgCh.push_back(Norm_r);
merge(finalImgCh, finalImage);
namedWindow("Final Enhanced Image", WINDOW_FREERATIO);
imshow("Final Enhanced Image", finalImage);
waitKey(0);

Expected result: Want to get the final colour image with image type CV_8UC3.

Acutal resutl:

OpenCV(3.4.1) Error: Assertion failed (mv[i].size == mv[0].size && mv[i].depth() == depth) in cv::merge, file c:\opencv\3.4.1\opencv-3.4.1\modules\core\src\merge.cpp, line 458
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-04-28 07:24:26 -0500

berak gravatar image

updated 2019-04-28 07:28:24 -0500

this is more a c++ problem.

if you want to use push_back() , you have to start with an empty vector, not one with 3 empty Mat's in it.

the way you do it now, leads to 6 Mat's in your vector, the 1st 3 being invalid.

maybe you want to brush up your c++ skills, and look at initializer lists, like:

vector<Mat> finalImgCh {Norm_b,Norm_g,Norm_r}; // c++11 way
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-04-28 06:31:59 -0500

Seen: 759 times

Last updated: Apr 28 '19