簡體   English   中英

使用OpenCV VideoCapture和C ++向量顯示文件中的圖像

[英]Displaying Images from file using OpenCV VideoCapture, and C++ vectors

我正在使用OpenCV VidoeCapture從文件中讀取圖像序列-我相信我正在正確地執行此部分-然后將其放入c ++向量中,以便稍后處理。 為了測試這一點,我編寫了以下內容,該內容將讀取圖像,將它們放入向量中,然后逐一顯示向量中的圖像。 但是,當我運行此程序時,沒有圖像出現。 怎么了?

我正在使用樹莓派,不知道有什么區別。

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <vector>
#include <iostream>

using namespace cv;
using namespace std;


vector<Mat> imageQueue;


int main(int argc, char** argv)
{
  string arg = ("/home/pi/pictures/ceilingSequence/%02d.jpg");
  VidoeCapture sequence(arg);

  if(!sequence.isOpened()) {
    cout << "Failed to open image sequence" << endl;
    return -1;
  }

  Mat image;
  for(;;)
  {
    sequence >> image;
    if(image.empty()) {
       cout << "End of sequence" << endl;
       break;
    }
    imageQueue.push_back(image);
  }

  for(int i = 0; i < 10; i++)
  {
    //display 10 images
    Mat readImage;
    readImage = imageQueue[i];
    namedWindow("Current Image", CV_WINDOW_AUTOSIZE);
    imshow("Current Image", readImage);
    sleep(2);
  }


return 0;
}

請用waitKey(2000)替換sleep(2)。 //假設您要等待2秒

即使您通常對按鍵都不感興趣,也需要正確更新opencv / highgui圖形循環。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM