opencv 安装
工具
bash
sudo apt-get install cmake
依赖包
bash
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff4.dev libswscale-dev libjasper-dev
bash
sudo make
sudo make install
- 配置环境
bash
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
bash
sudo ldconfig
bash
sudo vim /etc/bash.bashrc
bash
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
bash
source /etc/bash.bashrc
bash
sudo updatedb
测试
bash
cd opencv-3.4.1/samples/cpp/example_cmake
cmake .
make
./opencv_example
bash
cd /home/syh/temp/opencv2/helloworld
vim CMakeLists.txt
cmake .
make
./helloworld
bash
vim zz.cpp
vim
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/videoio.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
cout << "Built with OpenCV " << CV_VERSION << endl;
Mat image = imread("000001.JPEG");
cout << image.cols <<"," << image.rows << endl;
resize(image, image, Size(360, 202));
cout << "after resize:" << endl;
cout << image.cols <<"," << image.rows << endl;
cvtColor(image, image, CV_RGB2GRAY);
}
bash
vim CMakeLists.txt
vim
# cmake needs this line
cmake_minimum_required(VERSION 2.8)
# Define project name
project(helloworld_project)
# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
find_package(OpenCV REQUIRED)
# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
if(CMAKE_VERSION VERSION_LESS "2.8.11")
# Add OpenCV headers location to your include paths
include_directories(${OpenCV_INCLUDE_DIRS})
endif()
# Declare the executable target built from your sources
add_executable(helloworld zz.cpp)
# Link your application with OpenCV libraries
target_link_libraries(helloworld PRIVATE ${OpenCV_LIBS})
Error
bash
undefined reference to TIFFReadEncodedStrip@LIBTIFF_4.0'
# 解决方案
sudo mv /usr/local/anaconda3/lib/libtiff.so* ~/temp