Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Visual Studio throws an exception when I run a simple program

I am a newbie to Open CV and I am facing an odd error while compiling a simple open CV program. The program is as follows

#include <opencv2\highgui.hpp>
#include <opencv2\imgproc.hpp>
using namespace cv;
int main( int argc, char** argv )
{
  Mat image = imread( "image.jpg", 0 );
 Mat gray_image;
 cvtColor( image, gray_image, COLOR_BGR2GRAY);
 imwrite( "Gray_Image.jpg", gray_image);
 namedWindow( "Actual Image", WINDOW_AUTOSIZE );
 namedWindow( "Gray image", WINDOW_AUTOSIZE );
 imshow( "Actual Image", image );
 imshow( "Gray image", gray_image );
 waitKey(0);
 return 0;
}

It throws me an exception error saying

Unhandled exception at 0x7c812afb in helloworld.exe: Microsoft C++ exception: cv::Exception at memory location 0x0011e25c

I am able to continue compiling the program, by clicking on the continue option, and finally obtain the output too.

I tried using debugger/breakpoints and found the error in

cvtColor( image, gray_image, COLOR_BGR2GRAY);

I double checked the arguments for the same, but I am not able to resolve the exact error.