After playing around a little bit with the RPi camera, let's write a simple C++ program using the OpenCV functions to display an image. In this program, we first read an image from a particular folder and then we display this image in a new window:
To display the image, we first need an image. Inside the pi folder, I have created a new folder called Data and inside it, I have copied one image called Car.png. In the same folder, I have created the DisplayImage.cpp file, inside which we are going to write the program to display the image. The DisplayImage.cpp program can be download from the Chapter06 folder of this book's GitHub repository. The code is as follows:
#include <iostream>
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main()
{
Mat img;
img = imread("Car.jpg")...