什么是图像数组?使用 C++ 中的示例进行说明。
数组是一种便于存储和检索数据集合的方法。在 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; }
输出
广告