Ask Your Question
1

display image prob ?

asked 2013-01-30 02:06:26 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

I’ve try to create a C++ program using OpenCV to open an image in my laptop, but it doesn’t work ! Here is my code:

#include "stdafx.h"
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"

int _tmain(int argc, _TCHAR* argv[])
{
IplImage* img =cvLoadImage("D:\Pictures\love.jpg");
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cvShowImage( "Example1", img );
cvWaitKey();
cvReleaseImage(&img );
cvDestroyWindow( "Example1" );
return 0;
}

After build & debug, a window popped up but had no image on it. And there are some warnings ad follow:

Warning 3 warning C4129: 'l' : unrecognized character escape sequence d:\document\study\university of technology\semester_8\computer vision\c++ projects\30-1 at home\30-1 at home\30-1 at home.cpp 11 1 30-1 at home

Warning 2 warning C4129: 'P' : unrecognized character escape sequence d:\document\study\university of technology\semester_8\computer vision\c++ projects\30-1 at home\30-1 at home\30-1 at home.cpp 11 1 30-1 at home

Warning 1 warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. c:\opencv2.2\include\opencv2\flann\logger.h 66 1 30-1 at home

I hope someone can help me solve this problem! Thanks !

[EDIT 1} here is my code after being changed:

#include "stdafx.h"
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

int _tmain(int argc, _TCHAR* argv[])
{
IplImage* img =cvLoadImage("D:/Pictures/love.jpg",CV_LOAD_IMAGE_UNCHANGED);
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cvShowImage( "Example1", img );
cvWaitKey();
cvReleaseImage(&img );
cvDestroyWindow( "Example1" );


return 0;
}

but that warning still occured !

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
3

answered 2013-01-30 02:40:07 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

There is a problem with your string "D:\Pictures\love.jpg"

I am guessing that you are running Windows, try either "D:\\Pictures\\love.jpg" or "D:/Pictures/love.jpg" one of them should work.

\ is a escape character and that is why it gives problems with windows paths.

[EDIT]

Regarding the last warning try adding this:

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
edit flag offensive delete link more

Comments

thanks Martin Peris! it works well ! but how can i solve the last warning ?

nqchanh gravatar imagenqchanh ( 2013-01-30 03:26:05 -0500 )edit

I just updated the answer with the solution to the last warning

Martin Peris gravatar imageMartin Peris ( 2013-01-30 03:54:48 -0500 )edit

If the last warning still occurs, try to remove the lines #ifdef _MSC_VER and #endif. Leaving only the line #define _CRT_SECURE_NO_WARNINGS

Martin Peris gravatar imageMartin Peris ( 2013-02-01 01:25:50 -0500 )edit

Thank you.

Pham Hieu gravatar imagePham Hieu ( 2014-11-29 16:56:43 -0500 )edit
3

answered 2013-01-30 02:43:44 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

You have to convert this line.

IplImage* img =cvLoadImage("D:\Pictures\love.jpg");

to

IplImage* img =cvLoadImage("D:\\Pictures\\love.jpg");
edit flag offensive delete link more

Comments

thanks Mostafa Sataki! it works well ! but how can i solve the last warning ?

nqchanh gravatar imagenqchanh ( 2013-01-30 03:25:18 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-01-30 02:06:26 -0500

Seen: 636 times

Last updated: Jan 30 '13