Assertion Failed on LocateRoi with OpenCV

Hello to all!

I'm having a problem with an openCV program which compiles correctly but when it runs it aborts giving this error:

    OpenCV Error: Assertion failed (dims <= 2 && step[0] > 0) in locateROI, file /home/user/Desktop/HOME/src/OpenCV/modules/core/src/matrix.cpp, line 647
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/user/Desktop/HOME/src/OpenCV/modules/core/src/matrix.cpp:647: error: (-215) dims <= 2 && step[0] > 0 in function locateROI

Aborted

Open in new window


I'm using ubuntu with the latest openCV libraries but it gives me the same error also on Leopard with Eclipse.

The matrix.cpp file is inside my openCV source folder.

I'm not able to understand why i'm getting this error. Can you help me, please? Thanks a lot.

P.S. I can add the code i'm using if needed.
P.P.S. I've already tryed to ask to opencv yahoo group without any success :(
marcusbarnetAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Infinity08Commented:
>> P.S. I can add the code i'm using if needed.

That would be useful, yes :)
marcusbarnetAuthor Commented:
The problem is that my project has several files and I don't know which is the file with the error because the projects compiles without errors or warnings.

However, since the error refers to LocateRoi, i try to post the source file which use that function.

http://lnx.mangaitalia.net/xample/drawUtils.cpp
http://lnx.mangaitalia.net/xample/drawUtils.h

It looks like to be a size problem..
marcusbarnetAuthor Commented:
May be, it can help the error log which i receive if i run it on leopard:

Ulchiorra-3:~ user$ /Users/roccogalati/Documents/workspace/BGDEMO/Debug/BGDEMO ; exit;
OpenCV Error: Assertion failed (dims <= 2 && step[0] > 0) in locateROI, file /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_graphics_opencv/work/OpenCV-2.2.0/modules/core/src/matrix.cpp, line 647
terminate called after throwing an instance of 'cv::Exception'
  what():  /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_graphics_opencv/work/OpenCV-2.2.0/modules/core/src/matrix.cpp:647: error: (-215) dims <= 2 && step[0] > 0 in function locateROI

Abort trap
logout

Open in new window

I've realized that on my Mac there is no matrix.cpp in /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_graphics_opencv/work/OpenCV-2.2.0/modules/core/src/.
In reality, the location doesn't exist and if I search for matrix.cpp file with Finder i have no result.

I don't know if a code error or some libraries error.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Infinity08Commented:
>> The problem is that my project has several files and I don't know which is the file with the error because the projects compiles without errors or warnings.

You can run the application in the debugger to find out where exactly it goes wrong.

Or alternatively, you can add print statements to narrow it down to a specific line of code.


>> However, since the error refers to LocateRoi, i try to post the source file which use that function.

I don't see any use of the locateROI function in that code.


>> It looks like to be a size problem..

It looks like you're trying to use a matrix that hasn't been properly initialized, or that has been corrupted.
marcusbarnetAuthor Commented:
This code works great on a virtual machine which runs Ubuntu.

The same code doesn't run on my pcs.

I've tryed to add some print statement in order to debug the code but the problem is that it first diplays that error and then write down all the print statements before to end with "abort trap".

These are all the projects files, if this can help:

http://lnx.mangaitalia.net/xample/BGDEMO.cpp
http://lnx.mangaitalia.net/xample/BGFGClassifier.cpp
http://lnx.mangaitalia.net/xample/BGFGClassifier.h
http://lnx.mangaitalia.net/xample/drawUtils.h
http://lnx.mangaitalia.net/xample/drawUtils.cpp
http://lnx.mangaitalia.net/xample/stereoUtils.cpp
http://lnx.mangaitalia.net/xample/stereoUtils.h
http://lnx.mangaitalia.net/xample/surfFeatures.cpp
http://lnx.mangaitalia.net/xample/surfFeatures.h

I really don't know how to solve the problem.
marcusbarnetAuthor Commented:
May be it was a memory problem because i did this change on ubuntu:

  string fname0 = "frame0.jpg";
  string fname1 = "frame1.jpg";

in BGDEMO.cpp file and now it works great.

I've tryed to do the same thing on Leopard but it didn't work and displays the same error.

However, now it works on ubuntu.
I think the problem on ubuntu was that the string fname0 and fname1 was not properly declared and generated an exception in cv::Mat but i'm not so sure.

Someone have some advices in order to solve the problem in Leopard, too?
Thanks.
Infinity08Commented:
>> However, now it works on ubuntu.

I assume the problem isn't actually fixed - just hidden.

Did you try running the code in a debugger to see where it crashes ?
marcusbarnetAuthor Commented:
Unfortunately, i don't know how the eclipse debugger works because I've always used print statement in order to find errors.

This is what happens when i debug it:

1) this is the first screenshot: http://lnx.mangaitalia.net/xample/debug1.png
   It gives "out of bound" in frame0
   And it gives "out of bound" also in cv::Mat
   http://lnx.mangaitalia.net/xample/debug2.png

2) then, it goes on BGFGClassifier bg(frame0, frame1, M0, N0);
    and this is the screenshot: http://lnx.mangaitalia.net/xample/debug3.png

3) if I try to continue, it gives me this error:
   http://lnx.mangaitalia.net/xample/debug4.png

and then it aborts.

I think if there is a problem it is in BGFGClassifier.cpp because it is where BGFGClassififer is used.
Did you checked my files project which I've posted some post above?

This is the disassembly code: http://lnx.mangaitalia.net/xample/disassembly
you can see the multiple call to KILL() in this code.

I really don't know why it happens :(



 
marcusbarnetAuthor Commented:
In addition to my previous post,
this is the debug screenshot on ubuntu:
http://lnx.mangaitalia.net/xample/debub.png

and this is the assembly code:
http://lnx.mangaitalia.net/xample/codeu
Infinity08Commented:
>> I've tryed to add some print statement in order to debug the code but the problem is that it first diplays that error and then write down all the print statements

The reason for that is that you don't end what you print with a newline character. Do that, and you should see the output appear as it occurs.


Furthermore, I notice that you don't check for error cases. For each function call you make, make sure that it succeeded by checking the return value (or whatever else the documentation for the function says about how it signals errors).
Doing that gives more robust code, which in turn makes debugging easier (and makes catching/avoiding this kind of problem trivial).


>> 3) if I try to continue, it gives me this error:

When the crash occurs in the debugger, check the call stack. The debugger should be able to lead you to the exact line where the crash occurred.
If it doesn't, then run the program in the debugger again, after setting a breakpoint somewhere before where you expect the problem occurs, then step through the code until the crash occurs. Look for any abnormal variable contents etc. while you do that.
marcusbarnetAuthor Commented:
>>When the crash occurs in the debugger, check the call stack. The debugger should be able to lead you to the exact line where the crash occurred.

When i try to do this, it ends calling __kill() at 0x949cde42      (-stack-list-frames error) and I can't understand the line or the code which generated the error.
I tryed to set a breakpoint, but it fails in any case without prompt me any usuful information.

I don't know if i'm doing some mistakes, what happens if you try to debug the code with your IDE?

Infinity08Commented:
You want to check further up in the call stack - ie. before the locateROI function is called.


>> I tryed to set a breakpoint, but it fails in any case without prompt me any usuful information.

A breakpoint is used to stop running the code in the debugger, so you can analyze the current state. Once you're at a breakpoint, you can step through the code one line at a time, and analyze how the state changes.
The useful information is obtained by looking at the program state - especially right before the issue occurs.

Learning to use a debugger is important ;)


Btw, don't forget the two other pieces of advice I gave in my previous code (adding newlines to printf statements, and checking for errors after every function call).
marcusbarnetAuthor Commented:
I've added newlines to printf without any success :(

I'm not really very good with debugger because i never used it.
I've tryed to find a good tutorial on the net in order to be able to use the a debugger but i've found nothing useful.

May be I have to abort my little project, it's very difficult for me to solve this problem alone, it would take months in order to understand where is the problem.
Infinity08Commented:
>> I've added newlines to printf without any success :(

Adding newlines at the end of printf's should make them show up in the output earlier ... assuming you have a line based console.


>> I'm not really very good with debugger because i never used it.

A debugger isn't actually very complicated. You can learn most of the stuff by just experimenting with it.
Some of the things you should play with eg., is setting breakpoints, and then stepping through the code. Try getting the hang of that.


>> May be I have to abort my little project, it's very difficult for me to solve this problem alone

It shouldn't, if you :

(a) modify the code to check for error cases after every function call
(b) make good use of the debugger whenever the code does crash despite (a)

There's a very good chance that just doing (a) will already point out what the problem is.
marcusbarnetAuthor Commented:
It's very strange, i changed the main file code by adding some print statement with the newlines as you said before and now it works fine! It doesn't crash!

This is the file with the printf:
http://lnx.mangaitalia.net/xample/BGDEMO_statements.cpp

I really don't know how this can solve the problem.
I know that it's just a lucky case, but I think the problem is in some memory leackage.
Do you think it's possible?

Now i'm trying to experiments some operations with the debugger, but it won't display me messages errors, this time so I don't know what to check.
Infinity08Commented:
>> It's very strange, i changed the main file code by adding some print statement with the newlines as you said before and now it works fine! It doesn't crash!

If all you did was add print statements, then you likely hid the problem, rather than fixing it.


>> Now i'm trying to experiments some operations with the debugger, but it won't display me messages errors, this time so I don't know what to check.

Get it back to the state where you could reliably make it crash - just to make it more convenient to debug the issue.
marcusbarnetAuthor Commented:
I solved nothing with the debugger: i set the breakponts but the program fails always before to reach them.

I think i'll abort the project because i'm not able. :(
Anyway, thank you for your help ;)
Infinity08Commented:
>> i set the breakponts but the program fails always before to reach them.

That means you have to set them earlier ;)


>> I think i'll abort the project because i'm not able. :(

That's of course your choice.

But have you adapted the code to check all return codes for errors like I suggested earlier ?
marcusbarnetAuthor Commented:
It crashes after the calling to: BGFGClassifier bg(frame0, frame1, M0, N0);
in the main file.

I used assert macros in order to test the code and it seems to be ok in that points.

Unfortunately, I didn't have the time to adapt all the code because it's very long.
I used the debugger and I setted a lot of breakpoints and it crashes with the kill() function after the BGFGClassifier bg call.
Infinity08Commented:
>> It crashes after the calling to: BGFGClassifier bg(frame0, frame1, M0, N0);

Then set the breakpoint at that line, then step into until you reach the failing assertion. And then you'll be able to see what's wrong.
marcusbarnetAuthor Commented:
I did this but when it fails, all the variabiles content goes away and the only thing I can check its the assembly code.

This is the debug screenshot which i get:
http://lnx.mangaitalia.net/xample/last_debug.png 
Infinity08Commented:
You have to check the data RIGHT BEFORE it fails.
marcusbarnetAuthor Commented:
yep, but it is no possible because before data looks ok and then when i proceede to the next step it fails.
Infinity08Commented:
But you know where it'll fail, so when you run it in the debuigger, you can check the data just before it fails.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
marcusbarnetAuthor Commented:
Thanks for the help! :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.