# How to setup Qt and OpenCV 3.4.xx on Ubuntu 20.04 ###### tags: `Linux` > References: https://docs.opencv.org/4.x/db/df5/tutorial_linux_gcc_cmake.html https://shengyu7697.github.io/opencv-3-4-7-build-install-in-ubuntu/ ## Make OpenCV with cmake 1. Install package for cmake ``` sudo apt-get install build-essential cmake ``` 2. Download source from opencv offical github and unzip https://github.com/opencv/opencv/tree/3.4.15 3. Compile opencv and install (Use opencv 3.4.15) ``` cd opencv-3.4.15 //file name is the version you download mkdir -p build && cd build cmake .. make -j4 sudo make install sudo ldconfig -v ``` 4. Check if opencv is installed ``` $ opencv_version 3.4.15 ``` ## Qt CMakeLists.txt setup 1. Create QT project `File -> New file or Project...` 2. Choose a template  3. Set **Define Bulid System** to **CMake**  4. After created project navigate to **CMakeLists.txt** 5. Append following scripts before `target_link_libraries(qt_cmake_test PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)` ``` set(OpenCV_LIBS "opencv_calib3d" "opencv_core" "opencv_dnn" "opencv_features2d" "opencv_flann" "opencv_highgui" "opencv_imgcodecs" "opencv_imgproc" "opencv_ml" "opencv_objdetect" "opencv_photo" "opencv_shape" "opencv_stitching" "opencv_superres" "opencv_video" "opencv_videoio" "opencv_videostab" ) set(OpenCV_INCLUDE_DIRS "/usr/local/include" "/usr/local/include/opencv" ) ``` 5. Append `${OpenCV_LIBS}` ``` arget_link_libraries(qt_cmake_test PRIVATE Qt${QT_VERSION_MAJOR}::Widgets ${OpenCV_LIBS}) ``` 6. Append following scripts in the end ``` include_directories( ${OpenCV_INCLUDE_DIRS} ) message(STATUS ${OpenCV_LIBS}) message(STATUS ${OpenCV_INCLUDE_DIRS}) ``` 7. All done!
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up