Ask Your Question

Revision history [back]

Assertion failed with cv::merge, only in release mode

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.0.1 that I compiled myself from the 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

Assertion failed "Assertion failed" with cv::merge, only in release modemode 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.0.1 3.1.0 that I compiled myself from the 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

"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