2016-09-25 76 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); 
} 

因爲你無論如何,除非你直接捕捉幀像這樣分配新空間