iOS 中的 OpenCV 无法正确解码帧

发布于 2025-01-04 21:44:09 字数 1738 浏览 0 评论 0原文

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

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

实际工作的东西 - 框架高度和宽度正确确定

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

    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);

I'm trying to use OpenCV on iOS to do some pixel analysis on video frames. I've tried several .MOV files (all MPEG-4 AVC) but none of them seem to decode properly.

Problems:
- All cvGetCaptureProperty calls return a value of 1
- cvGrabFrame(capture) always returns true (it doesn't seem to find the last frame)

Things that are actually working
- Frame height and width are correctly determined

Any ideas? I have OpenCV 2.3.2 from http://aptogo.co.uk/2011/09/opencv-framework-for-ios/

    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);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文