Search code examples
opencvimshowopencv-stitching

Imshow() doesnt work in stitching_detailed.cpp opencv


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?


Solution

  • 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!