Ask Your Question

im a beginner of opencv. plz help me

asked 2017-09-12 08:22:23 -0500

i've just installed opencv 3.3 ver and visual studio 17

whenever i run this code

include "cv.hpp"

include "iostream"

using namespace std; using namespace cv;

int main() {

Mat img;

img = imread("lena.png", 1);
if (img.empty())
    return -1;

imshow("img", img);

return 0;


a gary window advent but disappear without displaying lena.png.

i read others' code. some write namedWindow. others don't

but their results are same.

what is problem?? code ?? or settings?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-09-12 08:40:09 -0500

berak gravatar image

updated 2017-09-12 08:49:36 -0500

"what is problem?? " -- your image was not loaded (path problem ?) , and the program returned -1.

(your code assumes, the image is in the same folder, where your program starts. if you started your prog from the ide, it will start from the debug (or release) folder, NOT from your project folder)

edit flag offensive delete link more


thanks for replying. i placed lena.png on right forder where the project is. so if i add namedWindow statement it works right

small_but_strong gravatar imagesmall_but_strong ( 2017-09-12 08:53:34 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-09-12 08:22:23 -0500

Seen: 63 times

Last updated: Sep 12