2012-05-13 5 views
5

openCV 2.2 프로젝트에서 작업하고 있습니다. AVI 파일의 각 프레임에서 처리해야하지만 코드를 실행하면 파일의 첫 번째 프레임 만 캡처합니다. CV_CAP_PROP_POS_FRAMES이 (가) 작동하지 않는 것 같습니다. 어떤 아이디어가 좋을까요?AVI에서 OpenCV 프레임 캡처

CvCapture* capture = cvCaptureFromAVI("test1.avi"); 

    IplImage *img = 0; 

    if (!cvGrabFrame(capture)) { 
      printf("Error: Couldn't open the image file.\n"); 
      return 1; 
    } 

    int numFrames = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT); 
    int posFrame = 1; 
    for(int i =0; i <= numFrames; i++){ 
     cvSetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES, i); 
       posFrame = cvGetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES); 

       img = cvGrabFrame(capture); 
       cvNamedWindow("Image:", CV_WINDOW_AUTOSIZE); 
       cvShowImage("Image:", img); 
       printf("%i\n",posFrame); 

       cvWaitKey(0); 

       cvDestroyWindow("Image:"); 
    } 
+0

2.3.1 또는 2.4를 사용하지 않는 이유는 무엇입니까? – Alex

+0

나는 그것을 opencv 2.3.1로 tred 시켰고 여전히 문제가 존재한다. –

답변

8

OpenCV 2.3을 사용하면 어떨까요? 더 직접적이고 효율적이며 눈에 더 분명하다고 생각합니다.

VideoCapture _videoSource; 

if(!_videoSource.open("test1.avi")) 
{ 
    exit(1);   // Exit if fail 
} 
_videoSource.set(CV_CAP_PROP_CONVERT_RGB, 1); 

Mat frame; 
namedWindow("Image"); 
int posFrame; 

while(1) 
{ 
    _videoSource >> frame; 
    posFrame=_videoSource.get(CV_CAP_PROP_POS_FRAMES); 
    imshow("output", frame); 
    return 0; 
} 

이와 비슷한 것이 작동해야합니다.

관련 문제