【问题标题】:cvCreateFileCapture always returns "NULL"cvCreateFileCapture 总是返回“NULL”
【发布时间】:2012-08-03 17:32:50
【问题描述】:

我正在使用 Xcode 4.3.3 和 OpenCV 2.4 制作一个 iphone 应用

我使用“cvCreateFileCapture("simtom.mp4")”从“.mp4”文件中获取帧,但不幸的是,cvCreateFileCapture() 总是返回“NULL”。

有什么问题?

这是我的源代码。

 CvCapture *m_pMusicVideo;     

 m_pMusicVideo = cvCreateFileCapture("simtom.mp4");

【问题讨论】:

    标签: ios opencv ffmpeg


    【解决方案1】:

    确保 simtom.mp4 文件与可执行文件位于同一文件夹中。如果您将它与源文件放在同一文件夹中,则不会找到它。在 Xcode 4 中,这意味着派生数据文件夹。转到 Xcode -> Preferences -> Locations 看看它在哪里。

    编辑

    我没有意识到您正在尝试在 iOS 下运行。 (我在您的问题中添加了该标签。)那么,您的问题是 simtom.mp4 文件没有与应用程序一起被复制到 iPhone。为了实现这一点,您需要将 simtom.mp4 嵌入到您的应用程序包中并从那里打开它。您应该能够使用

    获取文件的路径
    [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"simtom.mp4"];
    

    您将文件包含在目标的构建阶段中的捆绑包中:

    这里是开发者文档on NSBundle resources。一般的Bundle Programming Guide也不错。

    【讨论】:

    • 我移到路径“/Users/1w1w/Library/Developer/Xcode/DerivedData/ARDemo-hiarxwwvdhkhsceukxohkbyxxguy/Build/Products/Debug-iphoneos/”中的“simtom.mp4”但是 cvCreateFileCapture()仍然返回 NULL。我该如何解决这个 cvCreateFileCapture() 问题?
    • 哦。我看到了你编辑的答案。所以我知道我的“simtom.mp4”不在“Bundle Resources”中。然后我在“Bundle Resources”中添加了我的“simtom.mp4”。所以我正确地检查了我的“simtom.mp4”是“捆绑资源”。但是我的 cvCreateFileCapture() 仍然返回 NULL。我肯定在我的“捆绑资源”中添加了“simtom.mp4”。所以我猜opencv 2.4 处理'.mp4'文件可能有一些问题。你知道opencv 2.4中关于cvCreateFileCapture()的内容吗?
    • 您无法使用cvCreateFileCapture("simtom.mp4"); 打开它。.mp4 文件与捆绑包中的可执行文件不在同一个文件夹中。您需要预先添加文件路径。这就是[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"simtom.mp4"]; 的用途。
    猜你喜欢
    • 2014-03-04
    • 2016-11-02
    • 2014-05-06
    • 2012-06-05
    • 2014-05-30
    • 2014-02-23
    • 2017-10-12
    • 2013-08-16
    • 2016-03-28
    相关资源
    最近更新 更多