什麼是影像陣列?使用 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;
}

輸出

更新日期: 10-Mar-2021

740 次瀏覽

開啟您的 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.