2
votes

I added imshow("result",result) at the end of opencv sample (stitching_detailed.cpp) which is in opencv source files, But it doesnt show image . if I save it to .jpg and then reopen it using imread it will work fine. does anybody know why? this code save file in result.jpg but doesnt show image!! Strange!

imwrite("result.jpg", result); namedWindow("resultwindow", WINDOW_AUTOSIZE); imshow("resultwindow", result); waitKey(0);

The code below will show the image, but time is important for me I don't wanna save file and then read it (My project is real time stitching)

imwrite(result_name, result);
Mat result2=imread("result.jpg");
namedWindow("resultwindow", WINDOW_AUTOSIZE);
imshow("resultwindow", result2);
waitKey(0);

It's really strange. try it . you will see , Please anybody help me where is wrong?!! how to show stitched image in stitching_Detailed.cpp?

1
add a waitKey(some_millis); after the imshow, else nothing will be drawn to it. - berak
I did add waitkey(0) and waitkey(5000) ,both didnt worked - Ali Jahani
I think maybe imwrite do sth to "Mat result" to be showable and savable that imshow doesnt do this .Is it? - Ali Jahani
Try it yourself in the mentioned code. Its really a bug . I did work a lot with imshow in showing real-time projects but never seen this before in other codes! something is special with this Matrix that imshow cant show it - Ali Jahani
Try using WINDOW_AUTOSIZE instead of WINDOW_NORMAL. Just to be sure. Indeed, I think you could omit your cvNamedWindow statements. At least, use namedWindow instead. Probably not a solution but could narrow down the possibilities. - Miki

1 Answers

1
votes

Actually, that's not a bug. result is a 3 channel matrix of int16, and you cannot display it with imshow (it shows a gray image).

Just convert it to a regular Mat3b like:

Mat3b visibleResult;
convertScaleAbs(result, visibleResult);
imshow("visibleResult", visibleResult);
waitKey();

and you should be able to see it.

Hope it helps!