Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

image display with imread not functioning

Hi everybody. I am new to OpenCV, I was following the material here link text Here is my code

#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
 #include <iostream>

using namespace cv;
using namespace std;
int main( int argc, char** argv )
 char* imageName = argv[1];

 Mat image;

 image = cvLoadImage("D:\\b.png",1);
 if( argc != 2  )
     cout <<  "Could not open or find the image" << std::endl ;

   return -1;

 Mat gray_image;
 cvtColor( image, gray_image, CV_BGR2GRAY );

 imwrite( "D:\\C++\\output.jpg", gray_image);

 namedWindow( imageName, CV_WINDOW_AUTOSIZE );
 namedWindow( "Gray image", CV_WINDOW_AUTOSIZE );

 imshow( imageName, image );
 imshow( "Gray image", gray_image );

 return 0;

Everything is working, I open a png image, convert it to gray scale and save it to a jpg image. It functions well, however, this error appear:

Could not open or find the image

RUN FAILED (exit value -1, total time: 1s)

I am using Netbean 7.4 on windows 8.1 64 bit.

Strange is that the image is successfully processed and saved, but not display and the error appears.