[英]Displaying Images from file using OpenCV VideoCapture, and C++ vectors
I am reading in an image sequence from a file using an OpenCV VidoeCapture - I believe I am doing this part correctly - and then putting them in a c++ vector, for processing at a later point. 我正在使用OpenCV VidoeCapture从文件中读取图像序列-我相信我正在正确地执行此部分-然后将其放入c ++向量中,以便稍后处理。 To test this, I wrote the following that would read in images, put them in a vector, and then display those images from the vector one by one.
为了测试这一点,我编写了以下内容,该内容将读取图像,将它们放入向量中,然后逐一显示向量中的图像。 However, when I run this, no images appear.
但是,当我运行此程序时,没有图像出现。 What's wrong?
怎么了?
I am using a raspberry pi, I don't know if that makes any difference. 我正在使用树莓派,不知道有什么区别。
#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;
}
please replace the sleep(2) with a waitKey(2000). 请用waitKey(2000)替换sleep(2)。 // assuming you want to wait for 2 seconds
//假设您要等待2秒
even if you're not interested in keypresses in general, it is needed to update the opencv / highgui graphics loop correctly. 即使您通常对按键都不感兴趣,也需要正确更新opencv / highgui图形循环。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.