Install openCV 4.0.0 on Ubuntu 18.04 and 18.10

Linux作業系統安裝、設定與管理 (CentOS、Ubuntu)
回覆文章
inho
文章: 55
註冊時間: 2017-12-08, 23:00

Install openCV 4.0.0 on Ubuntu 18.04 and 18.10

文章 inho » 2018-03-02, 23:21

主要參考網站:

1、https://help.ubuntu.com/community/OpenCV
2、https://www.learnopencv.com/install-ope ... ntu-18-04/
3、https://www.pyimagesearch.com/2018/08/1 ... on-ubuntu/ (openCV 4.0)
4、https://www.pyimagesearch.com/2018/05/2 ... ll-opencv/ (openCV 3.4)

其他參考網站:

1、https://linuxize.com/post/how-to-instal ... ntu-18-04/
2、https://linuxconfig.org/install-opencv- ... aver-linux
3、http://www.codebind.com/cpp-tutorial/in ... buntu-cpp/

successful installation test:
dpkg is the typical way to get software package versions.

$ dpkg -l | grep libopencv

#=== look at the headers or libs installed. pkg-config can tell you where they are:
$ pkg-config --cflags opencv
$ pkg-config --libs opencv

#=== check opencv version
$ pkg-config --modversion opencv

如果前述指令出現問題,
參考解決方案:
1、尋找 /usr/local/lib 底下有無 pkgconfig 目錄,(/usr/local/lib/pkgconfig), 沒有的話就 mkdir pkgconfig. 然後建制一個 opencv.pc 的檔案,內容為:
#==================================================================================
# opencv pkg-config source file

prefix=/usr/local
exec_prefix=${prefix}/bin
includedir=${prefix}/include/opencv4
libdir=${prefix}/lib

Name: opencv
Description: The opencv library
Version: 4.0.0
Cflags: -I${includedir}/
Libs: -L${libdir}/ -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_calib3d -lopencv_ccalib -lopencv_core -lopencv_datasets -lopencv_dnn_objdetect -lopencv_dnn -lopencv_dpm -lopencv_face -lopencv_features2d -lopencv_flann -lopencv_freetype -lopencv_fuzzy -lopencv_gapi -lopencv_hfs -lopencv_highgui -lopencv_imgcodecs -lopencv_img_hash -lopencv_imgproc -lopencv_line_descriptor -lopencv_ml -lopencv_objdetect -lopencv_optflow -lopencv_phase_unwrapping -lopencv_photo -lopencv_plot -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_shape -lopencv_stereo -lopencv_stitching -lopencv_structured_light -lopencv_superres -lopencv_surface_matching -lopencv_text -lopencv_tracking -lopencv_videoio -lopencv_video -lopencv_videostab -lopencv_xfeatures2d -lopencv_ximgproc -lopencv_xobjdetect -lopencv_xphoto
#==================================================================================
讓 gcc或 g++ compiler時 的 $(shell pkg-config --cflags libs opencv) 可根據這個檔案內容找到相關的 include files 及lib files,以上 libs檔案名稱可以再 check /usr/local/lib裡的 opencv 相關 .o檔
#==================================================================
2、然後在 home dir 底下~/.bashrc 檔案最後面加入這二行:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
#=== Sample Makefile =====
CXX ?= g++
CXXFLAGS += -c -Wall $(shell pkg-config --cflags opencv)
LDFLAGS += $$(pkg-config --libs opencv)
all: opencv_example
opencv_example: example.o; $(CXX) $< -o $@ $(LDFLAGS)
%.o: %.cpp; $(CXX) $< -o $@ $(CXXFLAGS)
clean: ; rm -f example.o opencv_example
===================================================

回覆文章