2012-06-18 58 views
1

我正在使用VideoCapture capture(filename);從文件加載視頻。當我在Visual Studio(發佈模式)下運行該程序時,它工作得很好,像我期望的那樣加載視頻。當我在Visual Studio之外運行(通過雙擊explorer目錄中的圖標),視頻無法找到並且捕獲設備返回null,即使它是相同的文件,並且路徑是硬編碼和絕對路徑。OpenCV VideoCapture無法在Visual Studio外工作

任何想法?

更新:也嘗試使用舊的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文件... 我也嘗試在Visual Studio中顯示幀,所以我知道它實際上是在它認爲它打開時閱讀視頻。

+0

我不是說我不相信你,但硬編碼和絕對路徑的確切程度如何? – AJG85

+0

硬編碼,因爲不作爲運行時參數傳遞,但在編譯時寫入exe。絕對的,如在開始與驅動器,而不是相對於運行目錄。 – Jason

+0

一個很好的嘗試就是使用運行FILE * myFile = fopen(filename,「r」); std :: cout << myFile; FCLOSE(MYFILE);確保你可以到達文件。 – Steve

回答

1

檢查所有需要的DLL的是在同一文件夾作爲您的exe文件(或PATH)

+0

將所有OpenCV dll複製到與exe相同的目錄中。沒有運氣。 – Jason

1

確保您使用絕對視頻路徑(如果沒有,嘗試將視頻複製到exe文件路徑)和如果您使用發佈模式,則所有dll必須處於發佈模式。如果你給我一個小項目,也許我會解決這個問題。

+0

新增示例代碼 – Jason

相關問題