Opencv imread一帧

时间:2016-09-25 18:51:12

标签: opencv imread

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

#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 ]

提前多多感谢:)

1 个答案:

答案 0 :(得分:1)

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

你已经有了图像矢量,所以你可以这样做:

Mat colorImage = images [i];

和btw。没有必要这样做:

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);
}

因为你正在分配新的空间,除非你直接捕获这些帧:

cap >> images[i];