問(wèn)題描述
這個(gè)問(wèn)題必須重復(fù)多次,但它不起作用,有時(shí)仍然沒(méi)有答案.信息來(lái)源主要是這些
http://www.laganiere.name/opencvCookbook/chap1s1_2.shtml
http://www.youtube.com/watch?v=dgcXYQijV6c
This question must be duplicate many times, but it just doesn't work and sometimes it still remains unanswered. Sources of information are mainly these
http://www.laganiere.name/opencvCookbook/chap1s1_2.shtml
http://www.youtube.com/watch?v=dgcXYQijV6c
這是我認(rèn)為應(yīng)該/可以做的總結(jié).(現(xiàn)在它對(duì)我有用.)希望我從一開(kāi)始就提到了所有內(nèi)容,目的是編寫一個(gè)非常清晰的教程.
This is the summation of what I think one should/can do. (And now it works for me.) Hopefully I mentioned everything from the very beginning, the aim is to write a very clear tutorial.
為 QtCreator 安裝 OpenCV
- 我已經(jīng)安裝了 MS Visual Studio 2010 Professional.(我作為學(xué)生有免費(fèi)許可證)-我認(rèn)為這沒(méi)有必要,只是提一下
- 下載:適用于 Windows 32 位的 Qt 5.0.1(MinGW 4.7,823 MB)
2.1 安裝: 警告,Qt 使用的所有內(nèi)容(例如 OpenCV)必須位于名稱中不包含空格的目錄中.- 即程序文件"是錯(cuò)誤的.(但我不希望不同的程序文件直接堆積在 C 上,所以我只創(chuàng)建了一個(gè)文件夾Programs",其中安裝了所有重要的東西) - 下載: cmake-2.8.10.2-win32-x86.exe - 為所有用戶安裝(這可以在程序文件中)
- 下載: OpenCV-2.4.0.exe,解壓到:C:Programsopencv24 - 它將創(chuàng)建一個(gè)目錄opencv";添加另一個(gè)文件夾opencv_bin".現(xiàn)在看起來(lái)像這樣:
C:Programsopencv24opencv*
C:Programsopencv24opencv_bin - 設(shè)置 PATH 環(huán)境變量,以便有一個(gè)到 MinGW 編譯器的鏈接.例如C:ProgramsQtQt5.0.1ToolsMinGWin;
- 啟動(dòng) cmake-gui.exe
6.1 源碼:設(shè)置OpenCV的默認(rèn)目錄;C:Programsopencv24opencv
6.2 binaries:設(shè)置opencv_bin目錄;C:Programscopencv24opencv_bin
6.3 點(diǎn)擊配置:- 選擇MinGW Makefiles和Specify native compilers,點(diǎn)擊下一步
- 字段 C 用于 gcc.exe;C:/Programs/Qt/Qt5.0.1/Tools/MinGW/bin/gcc.exe
- Field C++ 用于 g++.exe;C:/Programs/Qt/Qt5.0.1/Tools/MinGW/bin/g++.exe 字段fortran可以為空,點(diǎn)擊完成
- I have already MS Visual Studio 2010 Professional installed. (I have a free licence as a student) - I think this is not necessary, just a mention
- Download: Qt 5.0.1 for Windows 32-bit (MinGW 4.7, 823 MB)
2.1 Install: Warning, everything that Qt uses (e.g. OpenCV) must be in directories that don't contain white-spaces in their names. - i.e. "Program Files" is wrong. (But I don't want different program files to accumulate directly on C, so I've only made a folder "Programs" in which everything important is installed) - Download: cmake-2.8.10.2-win32-x86.exe - Install for all users (this can be in Program Files)
- Download: OpenCV-2.4.0.exe, extract to: C:Programsopencv24 - it'll create a dir "opencv"; add another folder "opencv_bin". Now it looks like this:
C:Programsopencv24opencv*
C:Programsopencv24opencv_bin - Set PATH environment variable, so that there be a link to MinGW compiler. e.g. C:ProgramsQtQt5.0.1ToolsMinGWin;
- Start cmake-gui.exe
6.1 source code: set the default dir for OpenCV; C:Programsopencv24opencv
6.2 binaries: set the opencv_bin dir; C:Programscopencv24opencv_bin
6.3 click configure:- Choose MinGW Makefiles and Specify native compilers, click next
- Field C is for gcc.exe; C:/Programs/Qt/Qt5.0.1/Tools/MinGW/bin/gcc.exe
- Field C++ is for g++.exe; C:/Programs/Qt/Qt5.0.1/Tools/MinGW/bin/g++.exe Field fortran can be empty, click finish
- WITH_QT - 必須被選中.
- WITH_TBB、WITH_IPP、WITH_CUDA - 必須取消選擇
- CMAKE_BUILD_TYPE - 單擊并輸入文本調(diào)試"(不帶引號(hào)). 清除搜索字段中的文本.
- WITH_QT - must be selected.
- WITH_TBB, WITH_IPP, WITH_CUDA - must be unselected
- CMAKE_BUILD_TYPE - click and enter a text "Debug" (without quotes). Clear the text from the Search field.
現(xiàn)在我在 QtCreator 中創(chuàng)建了一個(gè)新的控制臺(tái)應(yīng)用程序.
Now I have created a new console app in QtCreator.
//cvHello.pro
QT += core
QT -= gui
TARGET = cvHello
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
INCLUDEPATH += C:/Programs/opencv24/opencv_bin2/install/include
LIBS += "C:/Programs/opencv24/opencv_bin2/bin/*.dll"
SOURCES += main.cpp
OTHER_FILES +=
img.JPG
和主文件:
//main.cpp
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv/cv.h"
using namespace std;
int main()
{
cout << "Hello World!" << endl;
cv::Mat mat;
mat = cv::imread("img.JPG");
cvNamedWindow("hello");
cv::imshow("hello",mat);
cvWaitKey(0);
return 0;
}
推薦答案
我終于開(kāi)始開(kāi)心了.在調(diào)整這個(gè)問(wèn)題時(shí),我不得不嘗試各種方法,如何定義LIBS.手動(dòng)列出它們有幫助,起初我寫錯(cuò)了.
Finally I am starting to be happy. When adjusting this question I had to try all ways, how to define LIBS. Listing them manually helped, at first I wrote them somehow wrongly.
最后是這樣的:
LIBS += -LC:\Programs\opencv24\opencv_bin2\bin
libopencv_core240d
libopencv_highgui240d
libopencv_imgproc240d
libopencv_features2d240d
libopencv_calib3d240d
順便說(shuō)一句,如果我犯了任何語(yǔ)法錯(cuò)誤,我很抱歉我的英語(yǔ).:)
Btw if I've made any grammar mistakes, I am sorry for my english. :)
這篇關(guān)于如何在 QtCreator 中鏈接 opencv 并使用 Qt 庫(kù)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!