1

VideoCapture capture(filename);ファイルからビデオをロードするために使用しています。Visual Studio (リリース モード) でプログラムを実行すると、問題なく動作し、期待どおりにビデオが読み込まれます。Visual Studio の外で (エクスプローラー ディレクトリのアイコンをダブルクリックして) 実行すると、ビデオが見つからず、キャプチャ デバイスは null を返します。同じファイルであり、パスがハードコードされていて絶対です。

何か案は?

更新:また、古い CvCapture* を使用してみましたが、同じエラーが発生しました。

6/19 更新:

コード例を次に示します。

#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace std;
using namespace cv;

int main(int argc, char** args)
{
    const char* filename = "c:/testvideo.wmv";

    //Check to see if we can see the file
    FILE* myFile = fopen(filename, "r");
    if (myFile)
        cout<<"0: Found file"<<endl;
    else
        cout<<"0: File not found"<<endl;

    //First use the openCV new way of doing it
    VideoCapture capture1(filename);

    if (capture1.isOpened())
        cout<<"1: Opened the video successfully"<<endl;
    else
        cout<<"1: Could not open the video"<<endl;

    //Second, try the old way
    CvCapture* capture2 = cvCaptureFromFile(filename);
    if (capture2)
        cout<<"2: Opened the video successfully"<<endl;
    else
        cout<<"2: Could not open the video"<<endl;

    //Pause
    char c;
    cin>>c;

    return 0;
}

リリース モードで実行されている Visual Studio では、次のようになります。

0: File Found
1: Opened the video successfully
2: Opened the video successfully

ファイル システムから exe を実行すると (ダブルクリック)、次のようになります。

0: File Found
1: Could not open the video
2: Could not open the video

私は一度だけコンパイルしたので、ディレクトリにはexeが1つしかありません... Visual Studioでフレームを表示しようとしたので、実際にビデオが開いていると思ったときに実際にビデオを読んでいることがわかります。

4

2 に答える 2

1

必要なすべてのDLLがexeと同じフォルダ(またはPATH)にあるかどうかを確認します

于 2012-06-18T17:12:14.567 に答える
1

絶対ビデオ パスを使用していることを確認し (そうでない場合は、ビデオを exe パスにコピーしてみてください)、リリース モードを使用している場合は、すべての dll をリリース モードにする必要があります。小さなプロジェクトを送っていただければ、この問題を解決できるかもしれません。

于 2012-06-19T04:29:47.317 に答える