ankit
ankit

Reputation: 517

Opencv 2.3.1 unable to read image

I am using Opencv 2.3.1 with visual studio 2008 on my windows 7 32 bit machine.I have just installed/extracted opencv 2.3.1 and it works fine with visual studio 2008 as I am not getting any errors while compiling a opencv code .My problem is that,the program is unable to read any image.
My code is

 #include "stdafx.h"
 #include <cv.h>
 #include <highgui.h>
 int main()
 {
 IplImage* img = cvLoadImage("C:\Users\Anks\Documents\Visual Studio 2008\Projects\examp_aishack\aishack.jpg");
 cvNamedWindow("myfirstwindow");
 cvShowImage("myfirstwindow", img);
 cvWaitKey(0);
 cvReleaseImage(&img);
 return 0;
 }

By compiling this I get zero error and but when I run it the console window appears and a blank(gray) window appear.It doesnot show the image. I have throughly searched internet ,but unable to solve my problem.Please help me. PS:I am a novice in opencv.

Upvotes: 2

Views: 1062

Answers (2)

bychance
bychance

Reputation: 282

Or you can use this style

C:/Users/Anks/Documents/Visual Studio 2008/Projects/examp_aishack/aishack.jpg

Besides IplImage, cvLoadImage and so on are out of date in OpenCV 2.0. You can read sample C++ codes and User Manual in OpenCV folder.

Upvotes: 2

karlphillip
karlphillip

Reputation: 93410

You need to escape the slashes:

IplImage* img = cvLoadImage("C:\\Users\\Anks\\Documents\\Visual Studio 2008\\Projects\\examp_aishack\\aishack.jpg");

and it's good practice to test if the loading was successful:

if (!img)
{
    // print error
    // return -1;
}

Upvotes: 3

Related Questions