[問題] opencv VideoCapture 與 CvCapture

看板C_and_CPP (C/C++)作者 (Laleh)時間12年前 (2013/12/10 21:10), 編輯推噓4(403)
留言7則, 4人參與, 最新討論串1/1
補充一下 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
你的camera input是?
12/10 22:15, 1F

12/10 22:18, , 2F
筆電內建的
12/10 22:18, 2F

12/10 22:20, , 3F
沒接外接camera的情況下,你的code是可以擷取畫面左上角的
12/10 22:20, 3F

12/11 01:26, , 4F
read改用 capture << frame 試看看
12/11 01:26, 4F

12/11 01:28, , 5F
而且你不加迴圈怎麼讓它一直show圖?
12/11 01:28, 5F

12/11 19:02, , 6F
問一下不用frame=擷取的影像嗎?
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
如果真的不行 那就只能用Mat(Iplimage*)去轉換了
12/12 00:44, 7F
文章代碼(AID): #1IfnBPxC (C_and_CPP)
文章代碼(AID): #1IfnBPxC (C_and_CPP)