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
相关推荐
moonsims35 分钟前
全国产化行业自主无人机智能处理单元-AI飞控+通信一体化模块SkyCore-I
人工智能·无人机
MUTA️39 分钟前
ELMo——Embeddings from Language Models原理速学
人工智能·语言模型·自然语言处理
海豚调度1 小时前
Linux 基金会报告解读:开源 AI 重塑经济格局,有人失业,有人涨薪!
大数据·人工智能·ai·开源
T__TIII1 小时前
Dify 插件非正式打包
人工智能
jerwey1 小时前
大语言模型(LLM)按架构分类
人工智能·语言模型·分类
令狐少侠20111 小时前
ai之RAG本地知识库--基于OCR和文本解析器的新一代RAG引擎:RAGFlow 认识和源码剖析
人工智能·ai
小叮当爱咖啡1 小时前
Seq2seq+Attention 机器翻译
人工智能·自然语言处理·机器翻译
shadowcz0071 小时前
奥特曼论人工智能、OpenAI与创业
人工智能·百度
AI人工智能+1 小时前
应用俄文OCR技术,为跨语言交流与数字化管理提供更强大的支持
人工智能·ocr·文字识别
UQI-LIUWJ2 小时前
李宏毅LLM笔记: AI Agent
人工智能·笔记