opencv 安装

opencv 安装

工具

sudo apt-get install cmake

依赖包

sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff4.dev libswscale-dev libjasper-dev
sudo make
sudo make install
  • 配置环境
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
sudo vim /etc/bash.bashrc  
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig  
export PKG_CONFIG_PATH  

source /etc/bash.bashrc  
sudo updatedb  

测试

cd opencv-3.4.1/samples/cpp/example_cmake

cmake .
make
./opencv_example

cd /home/syh/temp/opencv2/helloworld

vim CMakeLists.txt

cmake .
make
./helloworld

vim zz.cpp
#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);
}

vim CMakeLists.txt
# 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

undefined reference to TIFFReadEncodedStrip@LIBTIFF_4.0'

# 解决方案
sudo mv /usr/local/anaconda3/lib/libtiff.so* ~/temp

相关推荐

  1. opencv 安装

    2023-12-16 15:32:05       28 阅读
  2. OpenCV开发:编译安装opencv

    2023-12-16 15:32:05       40 阅读
  3. OpenCV 安装概述

    2023-12-16 15:32:05       34 阅读
  4. Opencv | Jupyter Notebook 安装

    2023-12-16 15:32:05       21 阅读
  5. linux安装opencv

    2023-12-16 15:32:05       15 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-16 15:32:05       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-16 15:32:05       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-16 15:32:05       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-16 15:32:05       20 阅读

热门阅读

  1. PHP获取数组中最大最小值和下标

    2023-12-16 15:32:05       31 阅读
  2. C语言——const函数

    2023-12-16 15:32:05       39 阅读
  3. centos网卡重命名方法

    2023-12-16 15:32:05       39 阅读
  4. 我为什么要当程序员?

    2023-12-16 15:32:05       46 阅读
  5. KafKa基本原理

    2023-12-16 15:32:05       34 阅读
  6. 叁[3],函数DispImage/DispObj

    2023-12-16 15:32:05       38 阅读
  7. 【视点合成】代码解读:生成demo视频

    2023-12-16 15:32:05       35 阅读
  8. 【贪心】LeetCode-406. 根据身高重建队列

    2023-12-16 15:32:05       32 阅读
  9. windows安装protoc-gen-go

    2023-12-16 15:32:05       44 阅读