배열은 데이터 컬렉션을 저장하고 검색하는 편리한 방법입니다. OpenCV에서는 이 개념을 사용하여 이미지 배열에 여러 이미지를 로드하고 배열의 인덱스 번호를 사용하여 표시할 수 있습니다.
다음 프로그램은 행렬 배열에 여러 이미지를 로드하고 인덱스 번호로 호출되는 배열의 이미지를 보여줍니다.
예시
#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;
} 출력
