下载地址: https://github.com/opencv/opencv/releases
参照官方说明: https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html
本机已经安装了cmake、Git、所以只需安装[required]中的部分:
sudo apt install libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
cd opencv-3.4.6
mkdir build
注意: 有目录opencv_contrib-3.4.6/是因为安装了OpenCV的扩展包,里面有好多强大的库。
cd build
cmake -D CMAKE_BUILD_TYPE=Release
-D CMAKE_INSTALL_PREFIX=/usr/local/opencv346
-D PYTHON_DEFAULT_EXECUTABLE=$(which python3)
-D WITH_TBB=ON -D WITH_EIGEN=ON ..
CMAKE_INSTALL_PREFIX=/usr/local/opencv346: 意思是安装到/usr/local/opencv346
具体参数参照官方说明
sudo make
sudo make install
sudo gedit /etc/ld.so.conf.d/opencv.conf
sudo ldconfig
sudo gedit /etc/bash.bashrc
末尾添加:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/opencv346/lib/pkgconfig
export PKG_CONFIG_PATH
source /etc/bash.bashrc
sudo updatedb
到此安装OpenCV 3.4.6完毕。
下载地址: https://github.com/opencv/opencv_contrib/releases
注意: 其实解压到喜欢的目录即可,这里解压到OpenCV的安装目录。
cmake -D CMAKE_BUILD_TYPE=Release
-D CMAKE_INSTALL_PREFIX=/usr/local/opencv346
-D PYTHON_DEFAULT_EXECUTABLE=$(which python3)
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-3.4.6/modules
-D WITH_TBB=ON
-D WITH_EIGEN=ON ..
这里比上面的cmake多了:
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-3.4.6/modules
OPENCV_EXTRA_MODULES_PATH指定的就是opencv_contrib-3.4.6的目录。具体说明可参照这里
sudo make
sudo make install
进入:/home/jincheng/mytool/opencv-3.4.6/samples/cpp/example_cmake
依次执行:
cmake .
make
./opencv_example
配置CLion环境
在CMakeLists.txt添加以下两行即可。
find_package(OpenCV REQUIRED)
target_link_libraries(test_opencv ${OpenCV_LIBS})
#include
using namespace cv;
int main() {
Mat img = imread("/home/jincheng/CLionProjects/test-opencv/hj.jpeg");
imshow("滑稽", img);
waitKey(0);
}