2015-11-19 38 views
0

我得到了Qt的造物主以下錯誤,QT-5.4 OpenCV的-3安裝: -連接錯誤在OpenCV的程序在Qt的造物主

:-1:錯誤:LNK1104:無法打開文件「opencv_ts300的.lib」

在我增加了我的項目的.pro文件 -

INCLUDEPATH += "E:\opencv\build\include" 

LIBS += -L"E:\opencv\build\x86\vc11\lib" 
LIBS += -lopencv_ts300d \ -lopencv_world300d \ -lopencv_ts300 \ -lopencv_world300d 

以下是我的main.cpp程序: -

#include "mainwindow.h" 
#include <QApplication> 
#include<opencv2/opencv.hpp> 

using namespace cv; // else would have to specify cv::cvtColor() etc. 


int main(int argc, char *argv[]) 
{ 

QApplication a(argc, argv); 
MainWindow w; 
w.show(); 
char * imageName ="2-dp.JPG" ; // read the name of image to be loaded called 3-dp.JPG 

Mat image;     // declare Mat type object to load image-matrix 

image = imread(imageName,1); // image object now contains image-matrix of the image loaded 

if(!image.data) // if image-data was invalid/non-existent/could not be read 
{ 
    printf("No image data to load \n"); // then print messg 
    return -1;       // and exit program with exit code -1 
} 

Mat gray_image;   // Mat object declared for the image after gray-scale conversion 

cvtColor(image, gray_image, CV_BGR2GRAY); // converts from BGR/RGB color space to gray scale 

/*imwrite ("Gray_Image.jpg",gray_image);*/ //writes image-data (converted to gray scale iamge) into disk in JPEG format at file path given 

namedWindow(imageName,CV_WINDOW_AUTOSIZE); // creates a named window for original image s.t window auto-scales its size as per image 
namedWindow("Gray Image",CV_WINDOW_AUTOSIZE); 

imshow(imageName,image); // displays the image on the namedWindow by giving name of namedWindow 
imshow("Gray Image",gray_image); 

waitKey(0); //waits forever till user presses key 


return a.exec(); 
} 

請幫忙!

回答

0

聯動

反斜線符號\不應該在一個行庫名稱之間使用。它不會給出問題中提到的錯誤消息,但是鏈接失敗並顯示相同的錯誤代碼。

反斜線符號可用於打破長行:

LIBS += -lopencv_ts300d \ 
     -lopencv_world300d 

否則庫應該在一個行中列出而不\

LIBS += -lopencv_ts300 -lopencv_world300 

運行時

有幾個問題可能會在運行時顯示。

有兩種庫類型:調試(由後綴d標記)和版本。他們不應該混合在一個版本。使用錯誤的庫類型可能會導致運行時崩潰,例如OpenCV in Qt crashes on deallocation of vector of lines when using HoughLinesP

它可以編寫qmake.pro文件只使用正確的庫取決於釋放或調試模式:

INCLUDEPATH += "E:\opencv\build\include" 

LIBS += -L"E:\opencv\build\x86\vc11\lib" 

CONFIG(release, debug|release) { 
    # release libraries 
    LIBS += -lopencv_ts300 -lopencv_world300 
} 

CONFIG(debug, debug|release) { 
    # debug libraries 
    LIBS += -lopencv_ts300d \ 
      -lopencv_world300d 
} 

注意,也有二進制動態加載庫在E:\opencv\build\x86\vc11\bin。如果在運行時找不到這些庫,應用程序應該會崩潰。該路徑可能被添加到系統PATH環境變量或所需的庫可能被複制到應用程序文件夾或系統PATH中列出的其他地方。


確保您使用的編譯器,鏈接器和Qt版本爲vc11。對於MSVC2013,應使用文件夾vc12E:\opencv\build\x86\vc12\lib)中的庫。