YMDW
YMDW

Reputation: 411

Visual Studio debugger fails but program runs fine when built...?

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

Upvotes: 0

Views: 2049

Answers (2)

Nick
Nick

Reputation: 5805

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

Upvotes: 1

john
john

Reputation: 8027

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.

Upvotes: 1

Related Questions