opencv 安装

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
相关推荐
可喜~可乐5 分钟前
循环神经网络(RNN)入门指南:从原理到实践
人工智能·rnn·深度学习·神经网络·机器学习·lstm
Allen_LVyingbo14 分钟前
医院大数据平台建设:基于快速流程化工具集的考察
大数据·网络·人工智能·健康医疗
黑色叉腰丶大魔王28 分钟前
数据挖掘:定义、挑战与应用
人工智能·数据挖掘
Adenialzz36 分钟前
Rectified Flow 原理简介与示例代码解读
人工智能·深度学习·机器学习·计算机视觉·diffusion
看星猩的柴狗1 小时前
机器学习-高斯混合模型
人工智能·机器学习
power-辰南2 小时前
机器学习之数据分析及特征工程详细分析过程
人工智能·python·机器学习·大模型·特征
少说多想勤做2 小时前
【前沿 热点 顶会】AAAI 2025中与目标检测有关的论文
人工智能·深度学习·神经网络·目标检测·计算机视觉·目标跟踪·aaai
橙子小哥的代码世界4 小时前
【计算机视觉基础CV-图像分类】05 - 深入解析ResNet与GoogLeNet:从基础理论到实际应用
图像处理·人工智能·深度学习·神经网络·计算机视觉·分类·卷积神经网络
leigm1234 小时前
深度学习使用Anaconda打开Jupyter Notebook编码
人工智能·深度学习·jupyter
Aileen_0v06 小时前
【玩转OCR | 腾讯云智能结构化OCR在图像增强与发票识别中的应用实践】
android·java·人工智能·云计算·ocr·腾讯云·玩转腾讯云ocr