2016-09-25 92 views
0

我最近使用这段代码从一个摄像头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

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

你已经有图像的载体,所以你只是做:

垫colorImage =图像[I]

和btw。没有必要为这样的:

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

因为你无论如何,除非你直接捕捉帧像这样分配新空间