0

I'm working on a stereo disparity program, I have left and right images that I'm trying to read in. However I'm getting an error when trying to debug, but it works fine if I just build it...So I've just reduced the code to something very simple...

#include <bunch of opencv bits...>
using namespace std;
using namespace cv;
int main()
{
 Mat Left= imread("Left.png", 0); //read images as grayscale
 Mat Right= imread("Right.png", 0);
 while (true) {
 imshow("Left",Left);
 imshow("Right",Right);
 }
}

Running with debug (F5) I get to the line imshow("Left",Left); and it crashes, reporting OpenCV Error: Bad flag (parameter or structure field) (unrecognized or unsupported array type) ....blah blah

Stepping through the code I can see that nothing is read stored in Left or Right

However where things get really confusing is if I just build the program (F7) and run the .exe from explorer (Misc Projects\SteroExp\Debug).... it runs completely fine.

My thoughts.... Does VS run the debug version from a different temp directory somewhere on the PC where the images aren't stored?

I'm using... W7 64bit, VS2010, C++, OpenCV 2.3.1

asked Aug 3, 2012 at 9:57
2
  • smells like undefined behaviour Commented Aug 3, 2012 at 9:58
  • hmmm does this mean I can never debug this program? Commented Aug 3, 2012 at 10:27

2 Answers 2

1

First, double-check that the working directory in Project | Properties | Debugging> WorkingDirectory is set to a directory that contains those two files.

answered Aug 3, 2012 at 10:29
Sign up to request clarification or add additional context in comments.

2 Comments

It was set to "$(ProjectDir)", not sure where that points to but I changed it to the "Misc Projects\SteroExp\Debug" dir. Now it works, thanks. ah the default working dir is "Misc Projects\SteroExp\SteroExp", where the project files are stored.
Select <Edit...> from the Working Directory dropdown and hit Macros>>. Type ProjectDir and see its actual value. It should point to the directory of the Project (the one that contains the .vcxproj file).
1

The problem is the current working directory. When you run from explorer the current directory is 'Misc Projects\SteroExp\Debug' but when you from from the debugger it's 'Misc Projects\SteroExp'. The answer is to move your image files to the correct directory.

answered Aug 3, 2012 at 10:15

1 Comment

I just tried moving Left.png and Right.png to "Misc Projects\SteroExp" but it still wont run in debug.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.