Assertion failed error python

asked 2014-07-14 03:38:01 -0600

drgs gravatar image

updated 2014-07-14 06:25:43 -0600

Hello ! I am trying to merge two images by the following line of code :

mrg = cv2.merge((filteredImg, img, filteredImg))

This is what I'm trying to do (the first picture is 'img', the second one is 'filteredImg' and the third one should be 'mrg'. I've got these results in MATLAB and I'm trying to do the same thing with OpenCV):

This is the first picture, 'img' This is the second image, with the filtered applied. In my code it is 'filteredImg' This is the expected result. I've got it in MATLAB and that's what I wanted to do in OpenCV too

When I try to run the script, I get the following error:

OpenCV Error: Assertion failed(mv[i].size == mv[0].size && mv[i].depth() == depth) in merge. (error -215)

How can I solve this problem ? Thanks in advance.

edit retag flag offensive close merge delete

Comments

Start by adding exactly how you initialized the filteredImg and img element!

StevenPuttemans gravatar imageStevenPuttemans ( 2014-07-14 04:13:21 -0600 )edit

Also, looking at docs it seems you are calling the function incorrectly. It should be an array of input images and an output image! You are using the old cv interface with cv2 functionality ... can't happen :D

StevenPuttemans gravatar imageStevenPuttemans ( 2014-07-14 04:16:04 -0600 )edit

This is how I initialized the 'img' element :img = cv2.imread(' ',0) and this is how I initialized the filteredImg element: cv2.filter2D(img.astype(np.float32), -1, kernel1). If you say that I called the function incorrectly, then how should I write it ? I'm a beginner, I don't have experience in OpenCV.

drgs gravatar imagedrgs ( 2014-07-14 06:01:42 -0600 )edit
1

^^ this should have gone into your question ..

cv2.merge is to merge several single channel Mat's(like an array of Mats) into a multichannel one. what did you intent ?

berak gravatar imageberak ( 2014-07-14 06:04:53 -0600 )edit
1

I intended to create the composite of two images using this cv2.merge function. I'm trying to find the best opencv alternative to MATLAB's imfuse() function.

drgs gravatar imagedrgs ( 2014-07-14 06:08:30 -0600 )edit
1

so, cv2.merge is the wrong function to use. try cv2.addWeighted

berak gravatar imageberak ( 2014-07-14 06:16:25 -0600 )edit

I tried both cv2.add and cv2.addWeighted, but I don't get the expected result. In MATLAB, everything works just fine. I will upload the pictures in a few minutes.

drgs gravatar imagedrgs ( 2014-07-14 06:18:15 -0600 )edit

Please place all info inside your original question by using the edit button ;) This will help people to give you better results.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-07-14 06:19:30 -0600 )edit

I don't see the added value of the second image except for the coloring in the third image which is basically the same contrasts as in the grayscale image. Care to explain a bit more what you want to happen? Do you want to superimpose the edges on top of the original image, but in a colored way?

StevenPuttemans gravatar imageStevenPuttemans ( 2014-07-14 07:00:38 -0600 )edit