Ask Your Question
0

Accessing Mat causes crash

asked 2013-04-23 09:40:34 -0500

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

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2013-04-23 11:18:09 -0500

updated 2013-04-23 11:19:19 -0500

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.

edit flag offensive delete link more

Comments

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

Guanta gravatar imageGuanta ( 2013-04-24 09:43:49 -0500 )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 ( 2013-04-24 11:09:00 -0500 )edit

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

StevenPuttemans gravatar imageStevenPuttemans ( 2013-04-24 14:24:04 -0500 )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 ( 2013-04-25 01:18:17 -0500 )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 ( 2013-04-25 01:20:20 -0500 )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 ( 2013-04-25 01:28:27 -0500 )edit

Correct again! :D

StevenPuttemans gravatar imageStevenPuttemans ( 2013-04-25 01:30:10 -0500 )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 ( 2013-04-25 01:32:04 -0500 )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 ( 2013-04-25 10:53:51 -0500 )edit

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

StevenPuttemans gravatar imageStevenPuttemans ( 2013-04-25 12:12:27 -0500 )edit
1

answered 2013-04-27 03:33:02 -0500

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.

edit flag offensive delete link more

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 ( 2013-04-28 13:10:02 -0500 )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 ( 2013-05-07 17:06:06 -0500 )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 ( 2013-05-11 06:19:44 -0500 )edit
Login/Signup to Answer

Question Tools

2 followers

Stats

Asked: 2013-04-23 09:40:34 -0500

Seen: 5,732 times

Last updated: Apr 27 '13