What is Image Array? Explain with an example in C++


An array is a convenient method to store and retrieve the collection of data. In OpenCV, we can use this concept to load multiple images in an image array and show them using the array's index number.

The following program loads multiple images in a matrix array and shows the array's images called by the index number.

Example

#include<iostream>
#include<opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main(int argc,const char** argv) {
   Mat myImage_array[3];//declaring a matrix named myImage//
   namedWindow("PhotoFrame1");//declaring the window to show the image//
   namedWindow("PhotoFrame2");//declaring the window to show the image//
   namedWindow("PhotoFrame3");//declaring the window to show the image//
   myImage_array[0]= imread("cat.jpg");//loading the image named cat in the matrix//
   myImage_array[1] = imread("cat.jpg");//loading the image named cat in the matrix//
   myImage_array[2] = imread("cat.jpg");//loading the image named cat in the matrix//  
   imshow("PhotoFrame1", myImage_array[0]);//display the image which is stored in the 'img' in the "MyWindow" window//
   imshow("PhotoFrame2", myImage_array[1]);//display the image which is stored in the 'img' in the "MyWindow" window//
   imshow("PhotoFrame3", myImage_array[2]);//display the image which is stored in the 'img' in the "MyWindow" window//  
   waitKey(0);//wait till user press any key  
   return 0;
}

Output

Updated on: 10-Mar-2021

622 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements