Assertion failed error python
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):
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.
Start by adding exactly how you initialized the filteredImg and img element!
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
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.
^^ 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 ?
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.
so, cv2.merge is the wrong function to use. try cv2.addWeighted
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.
Please place all info inside your original question by using the edit button ;) This will help people to give you better results.
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?