Ask Your Question

Benoit_rosa's profile - activity

2016-03-12 18:12:06 -0500 commented question "Assertion failed" with cv::merge, in release mode but not in debug (Win/x64)

Ok, there might be some problem on my config then. I'll double check.

If I remember well, the bug was not appearing if I was linking my release build against libopencvworld310d.lib, which is the debug one ...

2016-03-12 17:18:56 -0500 commented question "Assertion failed" with cv::merge, in release mode but not in debug (Win/x64)

Interesting. Are you compiling in release mode this code ? http://pastebin.com/CFLWrwfM

Note that the part making the bug on my computer is commented out. You would have to uncomment line 30 and comment out line 33.

2016-03-12 16:59:19 -0500 received badge  Editor (source)
2016-03-09 05:50:03 -0500 commented question "Assertion failed" with cv::merge, in release mode but not in debug (Win/x64)

Yes, sorry, it is 3.1.0 and not 3.0.1.

I checked the build and no, I'm not linking debug opencv to release build. That was indeed my first thought. My config is win/x64/ocv3.1/no ocl.

2016-03-09 00:56:57 -0500 asked a question "Assertion failed" with cv::merge, in release mode but not in debug (Win/x64)

Hi,

On Visual studio, I am getting an Assertion failed error linked to the use of the cv::merge function. The error is as following: OpenCV Error : Assertion failed <mv && n > 0> in cv::merge

This is a runtime error that it is happening only in release mode, with the code running nicely in debug mode. I am compiling this using Visual Studio 2012, with OpenCV 3.1.0 that I compiled myself from source.

The error is happening when trying to merge 3 channels back into a RGB image, let's say something like:

(get B,G,R images from code. Matrices are valid and image same type and size)

std::vector<cv::Mat> array_to_merge ;

array_to_merge.push_back(B);
array_to_merge.push_back(G);
array_to_merge.push_back(R);

cv::merge(array_to_merge,result);

Looking at the OpenCV source code, I actually found that the function that is called is in modules/core/src/convert.cpp, line 341:

void cv::merge(InputArrayOfArrays _mv, OutputArray _dst)
{
    CV_OCL_RUN(_mv.isUMatVector() && _dst.isUMat(),
               ocl_merge(_mv, _dst))

    std::vector<Mat> mv;
    _mv.getMatVector(mv);
    merge(!mv.empty() ? &mv[0] : 0, mv.size(), _dst);
}

It looks to me like the line _mv.getMatVector(mv); does not copy the contents of _mv into mv, leaving an empty MatVector to be called in the last line, then raising the exception. Why it happens only in release mode is beyond my understanding. This is however confirmed by the fact that this code is running both in debug and release modes :

(get B,G,R images from code. Matrices are valid and image same type and size)

std::vector<cv::Mat> array_to_merge ;

array_to_merge.push_back(B);
array_to_merge.push_back(G);
array_to_merge.push_back(R);

cv::merge(&array_to_merge[0], array_to_merge.size(), result);

(then do something or display the image)

Looking at this problem, what I see is a rather unusual problem but triggering a bug in a consistent manner. I have found and posted a workaround here, but should I make a ticket on GitHub? Or is there some problem in my simple code that I don't understand and is causing the bug?

FYI, a full code example is here: http://pastebin.com/CFLWrwfM