[問題] opencv VideoCapture 與 CvCapture
補充一下
opencv 2.47 Visual studio 2012 winsows 7
http://docs.opencv.org/modules/highgui/doc
參考如上網頁,有註明
In C API the black-box structure CvCapture is used instead of VideoCapture.
但我想問的是
如果我今天要使用的lib function
所需的參數是 Mat 而非 IplImage *
該怎麼處理呢
如下code範例
CvCapture *capture;
IplImage *frame;
capture = cvCaptureFromCAM(0) ;
if(!capture){
return -1;
}
cvNamedWindow("frame", 0);
frame = cvQueryFrame(capture);
cvShowImage("frame", frame);
------------- Work!
Mat frame;
// for vidoe
VideoCapture capture(filename);
if(!capture.isOpened()){
exit(1);
}
if(!capture.read(frame)) {
exit(1);
}
imshow("Frame", frame);
----------------- Work!
因目前要用的lib function參數要第二種
但又要讀來自camera的frame,而非video的
所以改成如下
Mat frame;
// google大神說 參數0就是去找camera
VideoCapture capture(0);
if(!capture.isOpened()){
exit(1);
}
if(!capture.read(frame)) {
cerr << "Unable to read next frame." << endl;
exit(1);
}
imshow("Frame", frame);
---- 編譯成功 但會印說 Unable to read next frame.
請問這種問題該如何處理
謝謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.45.174.245
※ 編輯: Laleh 來自: 114.45.174.245 (12/10 21:17)
推
12/10 22:15, , 1F
12/10 22:15, 1F
→
12/10 22:18, , 2F
12/10 22:18, 2F
推
12/10 22:20, , 3F
12/10 22:20, 3F
→
12/11 01:26, , 4F
12/11 01:26, 4F
→
12/11 01:28, , 5F
12/11 01:28, 5F
推
12/11 19:02, , 6F
12/11 19:02, 6F
我有用while loop
只是為了方便上面省略
結果一樣
我在懷疑是否是我
VideoCapture capture(0); 這邊參數帶錯?
我畫面完全沒東西 QQ
補上
Mat frame;
void processCamera(){
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) // check if we succeeded
exit(1);
for(;;)
{
cap >> frame; // get a new frame from camera
imshow("frame", frame);
if(waitKey(10) >= 0) break;
}
}
煩請高少
謝謝!
※ 編輯: Laleh 來自: 114.45.174.245 (12/11 23:28)
推
12/12 00:44, , 7F
12/12 00:44, 7F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章