[問題] 關於OpenCV的VideoCapture

看板C_and_CPP (C/C++)作者時間15年前 (2011/01/03 15:58), 編輯推噓3(306)
留言9則, 4人參與, 最新討論串1/2 (看更多)
開發平台(Platform): (Ex: VC++, Gcc, Linux, ...) VC++ 2010 額外使用到的庫(Library Used) (Ex: OpenGL, ...) OpenCV 2.2 問題(Question): 影片檔還沒讀完就產生"Unhandled exception" 餵入的資料(Input): 320*320 30fps wmv 7秒 預期的正確結果(Expected Output): f會跑到最後一個frame 錯誤結果(Wrong Output): Unhandled exception at 0x558bed66 (opencv_highgui220d.dll) in test.exe: 0xC0000005: Access violation reading location 0x00000018. 程式碼(Code): (請善用置底文標色功能) int main(int argc, char** argv) { int f = 0; VideoCapture cap = VideoCapture("test03.wmv"); if(!cap.isOpened()) // check if we succeeded return -1; Mat gray; namedWindow("gray",CV_WINDOW_AUTOSIZE); for(;;) { Mat frame; cap >> frame; // get a new frame from file cvtColor(frame, gray, CV_BGR2GRAY); imshow("gray", gray); f++; printf("%d\n",f); } return 0; } 補充說明(Supplement): cvtColor就算不用還是有相同問題 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.120.13.168

01/03 16:05, , 1F
改測其他影片檔試試.
01/03 16:05, 1F

01/03 16:08, , 2F
試過了 也是會跑出錯誤
01/03 16:08, 2F

01/03 17:23, , 3F
確定是影片沒讀完就壞掉嗎??
01/03 17:23, 3F

01/03 17:23, , 4F
我想有沒有可能是已經讀完了,可是你沒離開迴圈又繼續讀
01/03 17:23, 4F

01/03 20:24, , 5F
要知道frame的數目 跳出for迴圈
01/03 20:24, 5F

01/03 23:30, , 6F
樓上的方法OK!! 為啥cap.get(CV_CAP_PROP_FRAME_COUNT)
01/03 23:30, 6F

01/03 23:30, , 7F
會抓到很奇怪的數字
01/03 23:30, 7F

01/03 23:59, , 8F
用float or double
01/03 23:59, 8F

01/04 12:13, , 9F
用float 還是抓到不是我想要的數字
01/04 12:13, 9F
文章代碼(AID): #1D8O6u-1 (C_and_CPP)
文章代碼(AID): #1D8O6u-1 (C_and_CPP)