opencv imread一帧

Opencv imread a frame

我最近使用这段代码来保存来自网络摄像头的帧数据

#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <opencv2/opencv.hpp>
using namespace cv;

#include <fstream>
using namespace std;

int main(int argc, char** argv)
{
VideoCapture cap(0); // open the default camera
if (!cap.isOpened())  // check if we succeeded
    return -1;

cap.set(CV_CAP_PROP_FPS, 15);

Mat edges;
namedWindow("image", 1);
std::vector<cv::Mat> images(100);
for (int i = 0; i < 100; ++i) {
    // this is optional, preallocation so there's no allocation
    // during capture
    images[i].create(480, 640, CV_8UC3);
}
for (int i = 0; i < 100; ++i)
{
    Mat frame;
    cap >> frame; // get a new frame from camera
    frame.copyTo(images[i]);
}
cap.release();

for (int i = 0; i < 100; ++i)
{
    imshow("image", images[i]);
    if (waitKey(30) >= 0) break;
}

在此之后,我想使用imread 来分析新拆分的帧。但是,我想不出一种方法来实现这一点。

我试过了:Mat colorImage = imread(images[i]);

然而,它会导致:

error C2664: 'cv::Mat cv::imread(const cv::String &,int)': cannot convert argument 1 from 'std::vector<cv::Mat,std::allocator<_Ty>>' to 'const cv::String &' with [ _Ty=cv::Mat ]

提前致谢:)

imread 函数用于从磁盘打开图像。

您已经有了图像矢量,所以您只需这样做:

Mat colorImage = images[i];

顺便说一句。不需要这个:

for (int i = 0; i < 100; ++i) {
    // this is optional, preallocation so there's no allocation
    // during capture
    images[i].create(480, 640, CV_8UC3);
}

因为你正在分配新的 space 除非你像这样直接捕获帧:

cap >> images[i];