0

I am using CMake and OpenCV with C++ and am just trying to run a simple program:

#include "opencv/highgui.h"
#include "opencv/highgui.hpp"
#include "opencv/cv.h"
#include "opencv/cxcore.h"
#include "opencv/cxcore.hpp"
#include <stdio.h>
#include <iostream>

using namespace cv;
using namespace std;

int main()
{

   Mat image = imread("test.jpg", CV_LOAD_IMAGE_UNCHANGED);
   if (!image.data) //check whether the image is loaded or not
   {
         cout << "Image cannot be loaded." << endl;
   }
   else
   {
        cout<<"Image can be loaded."<<endl;
        cout<<"Size is "<<image.size().height<<","<<image.size().width<<endl;
        namedWindow( "Display window", CV_WINDOW_AUTOSIZE );
        imshow( "Display Image", image );
    }
}

When I cmake, I get no errors, and when I run the program by doing ./test, I get "Image can be loaded" along with the correct size of the image.

Why won't my program create a new window which displays the image?

Thank you!

user8333141
  • 29
  • 2
  • 16

1 Answers1

3

use cv::waitKey() after imshow. This is needed to proceed openCV rendering.

use waitKey(0) to pause until a key is pressed or waitKey(1) to pause as short as possible.

For further reference.

ThreeFx
  • 7,250
  • 1
  • 27
  • 51
Micka
  • 19,585
  • 4
  • 56
  • 74