iOS中的OpenCV无法正确解码帧

时间:2012-02-13 02:31:50

标签: iphone objective-c ios opencv

我正在尝试在iOS上使用OpenCV对视频帧进行一些像素分析。我已经尝试了几个.MOV文件(所有MPEG-4 AVC),但它们似乎都没有正确解码。

问题: - 所有cvGetCaptureProperty调用返回值1 - cvGrabFrame(capture)总是返回true(它似乎没有找到最后一帧)

实际工作的事情 - 正确确定框架高度和宽度

有什么想法吗?我有来自http://aptogo.co.uk/2011/09/opencv-framework-for-ios/

的OpenCV 2.3.2
    NSURL *file = [[NSBundle mainBundle] URLForResource:@"sky" withExtension:@"MOV"];

    CvCapture* capture = cvCaptureFromFile([[file path] UTF8String]);
    if (!capture)
    {
        NSLog(@"Error loading file");
        return;
    }

    cvQueryFrame(capture);

    int width = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
    int height = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
    NSLog(@"dimensions = %dx%d", width, height); // returns 1x1

    double framesPerSecond = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
    NSLog(@"framesPerSecond = %f", framesPerSecond); // returns 1

    int frameCount = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT);
    NSLog(@"frameCount = %d", frameCount); // returns 1

    int frameCounter = 0;

    while (cvGrabFrame(capture))
    {
        frameCounter++;

        //NSLog(@"got a frame! %d", frameCounter);

        if (frameCounter % 50 == 0)
        {
            IplImage* frame = cvRetrieveFrame(capture);

            NSLog(@"frame width: %d", frame->width); // works correctly
            NSLog(@"frame height: %d", frame->height); // works correctly
        }

        if (frameCounter > 1000)
            break; // this is here because the loop never stops on its own

    }

    cvReleaseCapture(&capture);

0 个答案:

没有答案