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

4

2 回答 2

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.

于 2012-08-03T10:15:07.043 回答
1

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

于 2012-08-03T10:29:09.347 回答