Ubuntu上開發OpenCV C++程式
安裝開發套件
sudo apt-get install libopencv-dev python-opencv
手動編譯程式
參考這篇
http://stackoverflow.com/questions/23162399/linking-opencv-libraries-with-g
指令會是
g++ test.cpp $(pkg-config --libs --cflags opencv) -o test
這是用pkg-config列出安裝的開發套件資訊, pkg-confif --cflags opencv會印出
-I/usr/include/opencv
這是gcc用的設定include目錄option,確實我們可以在目錄下找到opencv.hpp,完整路徑是/usr/include/opencv2/opencv.hpp。而pkg-config --libs opencv會印出
/usr/lib/x86_64-linux-gnu/libopencv_calib3d.so /usr/lib/x86_64-linux-gnu/libopencv_contrib.so /usr/lib/x86_64-linux-gnu/libopencv_core.so /usr/lib/x86_64-linux-gnu/libopencv_features2d.so /usr/lib/x86_64-linux-gnu/libopencv_flann.so /usr/lib/x86_64-linux-gnu/libopencv_gpu.so /usr/lib/x86_64-linux-gnu/libopencv_highgui.so /usr/lib/x86_64-linux-gnu/libopencv_imgproc.so /usr/lib/x86_64-linux-gnu/libopencv_legacy.so /usr/lib/x86_64-linux-gnu/libopencv_ml.so /usr/lib/x86_64-linux-gnu/libopencv_objdetect.so /usr/lib/x86_64-linux-gnu/libopencv_ocl.so /usr/lib/x86_64-linux-gnu/libopencv_photo.so /usr/lib/x86_64-linux-gnu/libopencv_stitching.so /usr/lib/x86_64-linux-gnu/libopencv_superres.so /usr/lib/x86_64-linux-gnu/libopencv_ts.so /usr/lib/x86_64-linux-gnu/libopencv_video.so /usr/lib/x86_64-linux-gnu/libopencv_videostab.so -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab
除此之外如果想要知道有哪些開發套件可以用pkg-config --list-all
使用CMake編譯
參考官方資料
http://docs.opencv.org/2.4/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html
先安裝cmake
sudo apt-get install cmake
寫cmake用的檔案CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project( MyModule )
find_package( OpenCV REQUIRED )
add_executable( MyModule test.cpp )
target_link_libraries( MyModule ${OpenCV_LIBS} )
其中MyModule是最後編譯的執行檔名
用cmake產生makefile後用make編譯
cmake ./
make
用cmake產生makefile後用make編譯
cmake ./
make
留言