记录OpenCV从安装到使用中遇到的问题。

Install

Windows

Install Reference

Linux

Install Reference

# 
sudo apt update
sudo apt install -y build-essential
sudo apt install -y cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
# download source file
#
cd opencv
mkdir build
cd build
# config
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
#cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=YES -D CMAKE_INSTALL_PREFIX=/usr/local .. # for use `pkg-config --modversion opencv4` to check opencv4 install
#cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local/opencv3v411 .. # for old version
make -j8
sudo make install
# check
pkg-config --modversion opencv
# uninstall
sudo make uninstall

Use

Windows

Linux

CMake

set(CMAKE_PREFIX_PATH /usr/local/opencv3v411) # insert this line for using other version
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(XXX ${OpenCV_LIBS})

语法

踩坑

imshow()的显示问题

A common mistake for OpenCV newcomers is to call cv::imshow() in a loop through video frames, without following up each draw with cv::waitKey(30). In this case, nothing appears on screen, because highgui is never given time to process the draw requests from cv::imshow().