First time here? Check out the FAQ!

Ask Your Question
0

Accessing Mat causes crash

asked Apr 23 '13

abraker95 gravatar image

I tried to make a simple image loading test and displaying it on a window using the imshow method and it crashed. Then I tried to narrow the problem down to a simpler example like the following:

Mat C = (Mat_<double>(3,3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
cout << "C = " << endl << " " << C << endl << endl;

It gave me an an assertion failure:

    OpenCV Error: Assertion failed <0 <= d && d <= CV_MAX_DIM && _sizes) in create, file C:/slave/builds/WinInstallerMegaPack/src/opencv/modules/core/src/matrix.cpp, line 187 terminate called after throwing an instance of 'cv::Exception'
 what(): C:/slave/builds/WinInstallerMegaPack/src/opencv/modules/core/src/matrix.cpp:187: error: (-215) 0 <= d && d <= CV_MAX_DIM && _sizes in function create

I'll have to resort to using the "C" part of the OpenCV library, but I would like to now how I can get Mat working so I could use C++.

I'm using Code::Blocks 12.11 and OpenCV 2.4.5

Preview: (hide)

2 answers

Sort by » oldest newest most voted
1

answered Apr 23 '13

updated Apr 23 '13

Looking at the documentation for the Mat_ object type I found this sample code.

Mat_<double> M(20,20);
for(int i = 0; i < M.rows; i++)
    for(int j = 0; j < M.cols; j++)
        M(i,j) = 1./(i+j+1);

So I am guessing the problem with your code is that you are assigning values to the matrix the same moment that you are creating it. Use a for loop structure to fill the elements that can easily be read ouy from a Mat_ type by indexing.

Preview: (hide)

Comments

Hmm, his code works perfectly fine for me using OpenCV 2.4.4...

Guanta gravatar imageGuanta (Apr 24 '13)edit

Mat_ doesn't work for me either. I commented out the code line by line and the declaration itself is causing the crash "Mat_<double> M(20,20);" There must something wrong during constructing. Declaring the Mat object without initializing it works. Taking the initialization process piece by piece, it crashed when a called the create method.

abraker95 gravatar imageabraker95 (Apr 24 '13)edit

try to assign a type when instantiating: Mat_<double> M(20,20,CV_8UC1);

StevenPuttemans gravatar imageStevenPuttemans (Apr 24 '13)edit

@steven: Isn't Mat_&lt;double&gt; M(20,20,CV_8UC1); a contradiction - double and CV_8UC1 shouldn't work.

Guanta gravatar imageGuanta (Apr 25 '13)edit

Right :D Excuse me for that. Make it Mat_<double> M(20,20,CV_64F). Or make it Mat_<uchar> M(20,20,CV_8UC1)...

StevenPuttemans gravatar imageStevenPuttemans (Apr 25 '13)edit
2

Oh we have to be careful here: Mat_<double> M(20,20,CV_64F) works but only because CV_64 is a macro/enum which is translated to '6' . So would you actually would do here is creating a 20x20 matrix and fill it with '6' . So don't mix templated matrices with non-templated ones, i.e. either write Mat_<double> M(20,20) (or Mat1d M(20,20)), or Mat M(20,20, CV_64F).

Guanta gravatar imageGuanta (Apr 25 '13)edit

Correct again! :D

StevenPuttemans gravatar imageStevenPuttemans (Apr 25 '13)edit

back to topic: I tried the code of abraker95 again using OpenCV 2.4.5 and it works perfectly so he must doing sth else wrong or it could be a compiler thing.

Guanta gravatar imageGuanta (Apr 25 '13)edit

Could it be a difference in operating systems? I'm running Windows XP. If not, try compiling it under the latest Code::Blocks and see if you get the same error. The only other thing I can think of is having a wrong dll. When I first used OpenCV it gave me runtime errors related to libstdc++-6.dll. I replaced Code::Block's version of the dll with another one it the runtime error went away. Unfortunately I don't know what version each one is, but I have the topic where I got it from here: http://answers.opencv.org/question/3740/opencv-243-mingw-cannot-run-program/

abraker95 gravatar imageabraker95 (Apr 25 '13)edit

As far as I know, windows XP doesn't make a difference for building software...

StevenPuttemans gravatar imageStevenPuttemans (Apr 25 '13)edit
1

answered Apr 27 '13

briselec gravatar image

using opencv 2.4.5 and codeblocks 12.11 on windows 7

I was getting the same assertion failures whenever I attempted to create a Mat object. Built opencv from source using cmake and codeblocks and so far it appears to have fixed the problem.

Preview: (hide)

Comments

I'll try that since I used the prebuilt binaries. My best guess is that there are some incapatabilities with the prebuilt OpenCV and the compiler I'm using. I wonder under what gcc the prebuilt binaries were built under.

abraker95 gravatar imageabraker95 (Apr 28 '13)edit

Still no luck. I tried different versions too. It might be far fetched but any idea is better than nothing at this point: perhaps it is the libstdc++-6.dll; what version of the dll does opencv 2.4.5 support?

abraker95 gravatar imageabraker95 (May 7 '13)edit

Which compiler suite are you using - from mingw.org or tdm-gcc or something else? Which exception handling method?
Do you have another compiler installation on your drive that it could be using instead? e.g. c:\MinGW

briselec gravatar imagebriselec (May 11 '13)edit

Question Tools

2 followers

Stats

Asked: Apr 23 '13

Seen: 6,964 times

Last updated: Apr 27 '13