OpenCv image display in cpp program. Here is a sample program in c++ for reading and displaying an image in opencv. If you do not know about the OpenCv computer vision/image processing library, you can follow the link opencv introduction & installation.

opencv image display in cpp program

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

main (int argc, char **argv)
  Mat image;
  image = imread (argv[1], CV_LOAD_IMAGE_COLOR);	// Read the file

  if (!		// Check for invalid input
      cout << "unable to open image" << std::endl;
      return -1;
  imshow ("Display window", image);	// Show image inside it.
  waitKey (0);			// Wait for a keystroke in the window
  return 0;

How to compile:

g++ image.cpp `pkg-config --cflags --libs opencv` -o demo

Run the exe demo:

#./demo image.png

opencv image display in cpp program

Related Contents to follow