Ask Your Question
-1

opencv assertion failed (ssize.width >0 && ......) and assertion failed (mv && n >0)

asked 2018-10-31 22:45:43 -0600

MomoLuo gravatar image

updated 2018-11-01 05:22:55 -0600

code:

if (!Img.empty())       {
        std::cout << "can load picture" <<  "\n";
            printf("Img.tpye()= %d Img.channels()=%d", dImg.type(), Img.channels());    
    }
    minMaxLoc(Img,    &minVal, &maxVal, NULL, NULL, Img>0);
  1. result: Img.tpye()=5 Img.channels()=1

exception caught: OpenCV(3.4.3) c:\build\3_4_winpack-build-win64-vc15\opencv\mod ules\core\src\minmax.cpp:753: error: (-215:Assertion failed) (cn == 1 && (_mask. empty() || _mask.type() == CV_8U)) || (cn > 1 && _mask.empty() && !minIdx && !ma xIdx) in function 'cv::minMaxIdx'

I first met the assertion fail in the function minMaxLoc , I am sure that there is nothing wrong with my input because I imwrite and check it successfully.

code:

//minMaxLoc(Img,    &minVal, &maxVal, NULL, NULL, Img>0);
minVal = 15.5;
maxVal = 21.5;

OpenCV(3.4.3) Error: Assertion failed (mv && n > 0) in cv::merge, file c:\build \3_4_winpack-build-win64-vc15\opencv\modules\core\src\merge.cpp, line 284

Then I just guess the max and min values of instead of using this function , but another assertion fail happens. I get this project from my classmate, but it works normally in his computer with the same VS2015 and OPENCV 3.4.3

I finally solve this because I use wrong vc lib. My vs version is 2015 but I use vc15 lib library .After changing to vc14 , it works.

edit retag flag offensive close merge delete

Comments

thanks for the edit !

can we see the code, too ?

berak gravatar imageberak ( 2018-11-01 01:04:12 -0600 )edit
1

I have already done. It works in others computers, so I think nothing wrong with this.

MomoLuo gravatar imageMomoLuo ( 2018-11-01 01:30:39 -0600 )edit

but it works normally in his computer

i very much doubt so ;)

berak gravatar imageberak ( 2018-11-01 02:16:09 -0600 )edit

I have solve this for a long time ,even change the opencv version and vs version and now everything might be the same.

MomoLuo gravatar imageMomoLuo ( 2018-11-01 02:35:37 -0600 )edit

sorry to say so, but the problem is just lack of discipline on your side ...

berak gravatar imageberak ( 2018-11-01 02:37:08 -0600 )edit

I think I have find a fital problem. I use the vc15 but my vs version is 2015

MomoLuo gravatar imageMomoLuo ( 2018-11-01 03:33:25 -0600 )edit

did you mean "final" ?

and yes, use vc14 libs for VS2015

berak gravatar imageberak ( 2018-11-01 03:38:00 -0600 )edit

please start a new question, if you run into further problems.

berak gravatar imageberak ( 2018-11-01 03:55:07 -0600 )edit

I can not answer my owner question. I think I need to tell other new users this point ,what should I do ?

MomoLuo gravatar imageMomoLuo ( 2018-11-01 04:11:05 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2018-11-01 04:27:43 -0600

MomoLuo gravatar image

I have finally solved this. vs(Visual Studio) 2015 match to vc(Visual C++)14 lib vs 2017 match to vc15 lib I made a mistake, my vs version is 2015 but the lib library I use vc15 .After changing to vc14, my code finally works.

edit flag offensive delete link more
0

answered 2018-11-01 02:13:16 -0600

berak gravatar image

updated 2018-11-01 02:16:43 -0600

  1. you can only use minMaxLoc IF your image was loaded correctly. so that call should go into the if block, too !

  2. minMaxLoc only works on single channel images (see docs, again, please). maybe you need to load your image using the IMREAD_GRAYSCALE flag.

  3. you used the 'mask' argument wrong. it should not be the same image, and it would need a single channel, binary image here. i guess, you don't need it at all.

edit flag offensive delete link more

Comments

The mask is discreteImg>0 ,sorry to miss this.

MomoLuo gravatar imageMomoLuo ( 2018-11-01 02:19:25 -0600 )edit

however, omitting the IMREAD_GRAYSCALE flag will read a 3 channel image, so please use that flag.

you can also print out type() and channels()

berak gravatar imageberak ( 2018-11-01 02:23:53 -0600 )edit

Hi, the outcome is :discreteImg.tpye()=5 discreteImg.channels()=1 I once thought that if the input Mat is umempty ,the function minMaxLoc will work normally.

MomoLuo gravatar imageMomoLuo ( 2018-11-01 02:33:42 -0600 )edit

type() == 5 would mean: float.

so again, there must be code there doing some conversion, which you don't show.

berak gravatar imageberak ( 2018-11-01 02:36:02 -0600 )edit

What will happen if the input of minMaxLoc type is 5? I just delete the imwrite and imread part. Now the input is origin image. What conversion should I do?

MomoLuo gravatar imageMomoLuo ( 2018-11-01 02:43:26 -0600 )edit

it should work all fine.

and again, if we only see (outdated) parts of your code, you leave us guessing

berak gravatar imageberak ( 2018-11-01 02:48:25 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-10-31 21:19:17 -0600

Seen: 3,720 times

Last updated: Nov 01 '18