Creating a OpenCV 2.3.1 application using QT
1.本次環境選用 Ubuntu 10.10、OpenCV 2.3.1 、cuda 4.0、QT 4.6
首先開啟QT介面
2.利用QT開啟新專案
File->New File or Project
3.建立QT Console Application
4.建立專案名稱及存放路徑在新建視窗中點選QT C++ Project,再點選建立QT Console Application
5.專案設置部分在此先不設立,直接點選Finish完成在這裡建議建立下面三個資料夾/home/trong/QT/QT_opencv_test//home/trong/QT/QT_opencv_test/QT_opencv_release/home/trong/QT/QT_opencv_test/QT_openccv_debug並將上面位置修改成Name: QT_opencv_testCreate in: /home/trong/QT/QT_opencv_test
6.在QT中設置開發環境
7.利用Opencv 讀取影像開啟影像之動作當建立專案檔之後,其環境設定檔將為"檔名.pro"檔案,你必須要此設立相關include路徑,及lib路徑等,在opencv教學文件中提到,只要設輸入下列兩行,將可自動呼叫系統變數,並將需要使用之函數加入,但不知該版本的問題還是哪邊設定出了錯,依然無法使用該方式加入,因此只好手動將需要之include路徑及lib路徑輸入,如下圖所示。CONFIG += link_pkgconfigPKGCONFIG += opencv上述設定如下表所示
CONFIG += link_pkgconfig 
PKGCONFIG += opencv
INCLUDEPATH += /usr/local/opencv/include
LIBS += -L/usr/local/opencv/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann -lopencv_gpu
8.在QT中建立Build資料夾上述程式碼如下表
#include <opencv2/opencv.hpp> 
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
int main()
{
// read an image
cv::Mat image= cv::imread("beach.jpg");
// create image window named "My Image"
cv::namedWindow("My Image");
// show the image on window
cv::imshow("My Image", image);
// wait key for 5000 ms
cv::Mat result;
cv::flip(image,result,1);
cv::namedWindow("result image");
cv::imshow("result image",result);
cv::waitKey(5000);
return 1;
}
9.Build C++ 程式QT中你必須設定一個Build的資料夾,這個資料夾位置不可與專案檔在一起,因此自行建立一個資料夾供該Build使用Build directoryRelease:/home/trong/QT/QT_opencv_test/QT_opencv_releaseDebug:/home/trong/QT/QT_opencv_test/QT_openccv_debug
建立好的檔案如下圖所示當編寫好程式碼之後發現無任何錯誤,可使用下圖進行Build動作
10.執行該程式
你可以直接點選該執行檔進行檔案執行,執行結果如下圖所示
11.本次OpenCV所使用的相關函數
Note:• The function determines the type of an image by the content, not by the file extension.• On Microsoft Windows* OS and MacOSX*, the codecs shipped with an OpenCV image (libjpeg, libpng, libtiff, and libjasper) are used by default. So, OpenCV can always read JPEGs, PNGs, and TIFFs. On MacOSX, there is also an option to use native MacOSX image readers. But beware that currently these native image loaders give images with different pixel values because of the color management embedded into MacOSX.• On Linux*, BSD flavors and other Unix-like open-source operating systems, OpenCV looks for codecs supplied with an OS image. Install the relevant packages (do not forget the development files, for example, “libjpeg-dev”, in Debian* and Ubuntu*) to get the codec support or turn on the OPENCV_BUILD_3RDPARTY_LIBS flag in CMake.
Note: Qt backend supports additional flags:• CV_WINDOW_NORMAL or CV_WINDOW_AUTOSIZE: CV_WINDOW_NORMAL enables you to resize the window, whereas CV_WINDOW_AUTOSIZE adjusts automatically the window size to fit the displayed image (see imshow() ), and you cannot change the window size manually.• CV_WINDOW_FREERATIO or CV_WINDOW_KEEPRATIO: CV_WINDOW_FREERATIO adjusts the image with no respect to its ratio, whereas CV_WINDOW_KEEPRATIO keeps the image ratio.• CV_GUI_NORMAL or CV_GUI_EXPANDED: CV_GUI_NORMAL is the old way to draw the window without statusbar and toolbar, whereas CV_GUI_EXPANDED is a new enhanced GUI.By default, flags == CV_WINDOW_AUTOSIZE | CV_WINDOW_KEEPRATIO | CV_GUI_EXPANDED
Note: This function is the only method in HighGUI that can fetch and handle events, so it needs to be calledperiodically for normal event processing unless HighGUI is used within an environment that takes care of event processing.
Note: The function only works if there is at least one HighGUI window created and the window is active. If there areseveral HighGUI windows, any of them can be active.

.png)









.png)


.png)
 
 
沒有留言:
張貼留言