首页 > 系统相关 >Ubuntu下配置opencv环境

Ubuntu下配置opencv环境

时间:2023-01-03 19:04:59浏览次数:64  
标签:lopencv 配置 LIBRARY opencv cuda Ubuntu dev CUDA


目录

  • ​​安装准备​​
  • ​​安装cmake​​
  • ​​安装依赖环境​​
  • ​​下载opencv​​
  • ​​安装​​
  • ​​解压​​
  • ​​cmake​​
  • ​​编译​​
  • ​​安装​​
  • ​​配置环境​​
  • ​​检验​​
  • ​​Resources​​
  • 操作系统:Ubuntu18.04.4
  • 版本:opencv3.2.0

安装准备

安装cmake

sudo apt-get install cmake

安装依赖环境

sudo apt install  build-essential

sudo apt install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

sudo apt install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

第三行中,可能会出现 【无法定位软件包libjasper-dev 的错误提示】

sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main" sudo apt update sudo apt upgrade sudo apt install libjasper1 libjasper-dev

下载opencv

​https://opencv.org/releases/​

安装

解压

在opencv3文件夹下新建build文件夹

cmake

进入​​build/​

sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..

【由于网络问题无法下载​​ippicv_linux_20151201.tgz​​文件的解决办法】

Ubuntu下配置opencv环境_ubuntu

  1. 找到​​3rdparty/ippicv/downloader.cmake​​文件

set(OPENCV_ICV_URL "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${IPPICV_BINARIES_COMMIT}/ippicv") set(IPPICV_BINARIES_COMMIT "81a676001ca8075ada498583e4166079e5744668")

  1. 通过这两个语句拼接得到下载地址:https://raw.githubusercontent.com/opencv/opencv_3rdparty/81a676001ca8075ada498583e4166079e5744668/ippicv/ippicv_linux_20151201.tgz
  2. 将下载好的文件上传到服务器
  3. 替换路径为​​"file:///root​

【The following variables are used in this project, but they are set to NOTFOUND.解决方案】

cuda9不再支持2.0架构

1.在/home/mario/Projects/opencv-3.1.0/cmake下找到FindCUDA.cmake文件

1. 找到行:

find_cuda_helper_libs(nppi)

然后替换为:

find_cuda_helper_libs(nppial) find_cuda_helper_libs(nppicc) find_cuda_helper_libs(nppicom) find_cuda_helper_libs(nppidei) find_cuda_helper_libs(nppif) find_cuda_helper_libs(nppig) find_cuda_helper_libs(nppim) find_cuda_helper_libs(nppist) find_cuda_helper_libs(nppisu) find_cuda_helper_libs(nppitc)

2. 找到行:

set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppi_LIBRARY};${CUDA_npps_LIBRARY}")

然后替换为:(注意后面的"",实际输入的时候把这个反斜杠去掉,弄成一行,这里只是作为显示换行加的"")

set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppial_LIBRARY};${CUDA_nppicc_LIBRARY};\ ${CUDA_nppicom_LIBRARY};${CUDA_nppidei_LIBRARY};${CUDA_nppif_LIBRARY};${CUDA_nppig_LIBRARY};\ ${CUDA_nppim_LIBRARY};${CUDA_nppist_LIBRARY};${CUDA_nppisu_LIBRARY};${CUDA_nppitc_LIBRARY};${CUDA_npps_LIBRARY}")

3. 找到行:

unset(CUDA_nppi_LIBRARY CACHE)

然后替换为:

unset(CUDA_nppial_LIBRARY CACHE) unset(CUDA_nppicc_LIBRARY CACHE) unset(CUDA_nppicom_LIBRARY CACHE) unset(CUDA_nppidei_LIBRARY CACHE) unset(CUDA_nppif_LIBRARY CACHE) unset(CUDA_nppig_LIBRARY CACHE) unset(CUDA_nppim_LIBRARY CACHE) unset(CUDA_nppist_LIBRARY CACHE) unset(CUDA_nppisu_LIBRARY CACHE) unset(CUDA_nppitc_LIBRARY CACHE)

  1. 在/home/mario/Projects/opencv-3.1.0/cmake下找到OpenCVDetectCUDA.cmake文件

找到以下几行:

... set(__cuda_arch_ptx "") if(CUDA_GENERATION STREQUAL "Fermi") set(__cuda_arch_bin "2.0") elseif(CUDA_GENERATION STREQUAL "Kepler") set(__cuda_arch_bin "3.0 3.5 3.7") ...

修改为:

... set(__cuda_arch_ptx "") if(CUDA_GENERATION STREQUAL "Kepler") set(__cuda_arch_bin "3.0 3.5 3.7") elseif(CUDA_GENERATION STREQUAL "Maxwell") set(__cuda_arch_bin "5.0 5.2") ...

  1. 找到cudafp16.h的头文件​​/usr/local/cuda-9.0/include/cudafp16.h​​​,将这个文件拷贝到opencv目录的cudev下​​opencv-3.2.0/modules/cudev/include/opencv2/cudev​​​,然后在该目录下的​​common.hpp​​的文件添加:

#include <cuda_fp16.h>

编译

【Unsupported gpu architecture 'compute_20’解决方案】

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D CUDA_GENERATION=Kepler ..

hint: 添加Kepler

安装

sudo make install

配置环境

打开​​/etc/ld.so.conf​​在文件中加上一行

include /usr/loacal/lib
sudo ldconfig

打开​​/etc/bash.bashrc​​,在文件中添加

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
source /etc/bash.bashrc

检验

pkg-config opencv --modversion
Package opencv was not found in the pkg-config search path.解决方案
创建​​opencv.pc​​文件
cd /usr/local/lib
sudo mkdir pkgconfig
cd pkgconfig
sudo touch opencv.pc
添加如下信息
prefix=/usr/local
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib

Name: opencv
Description: The opencv library
Version:4.0.1
Cflags: -I${includedir}/opencv4
Libs: -L${libdir} -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core
~
将文件导出到环境变量
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

Resources

标签:lopencv,配置,LIBRARY,opencv,cuda,Ubuntu,dev,CUDA
From: https://blog.51cto.com/doubleZ/5986595

相关文章

  • Ubuntu配置OpenCV终极解决方案
    安装依赖一定要安装全,避免之后出现各种奇怪的问题sudoapt-getinstallbuild-essentialsudoapt-getinstallcmakegitlibgtk2.0-devpkg-configlibavcodec-devlibavfo......
  • 从零开始配置NVIDIA Jetson Nano(踩坑史)
    文章目录​​烧录​​​​供电​​​​摄像机​​​​软件环境​​​​下载软件​​​​Resources​​烧录下载​​Jetson下载中心|NVIDIADeveloper​​​并解压得到镜......
  • 解决ROS配置中cv_bridge问题
    cv_bridge—opencv和ros连接起来的桥问题描述在JetsonNano+ROS环境上catkin_make时出现cv_bridge问题如下CMakeErrorat/home/nano/catkin_ws/devel/share/cv_bridge/c......
  • argocd 同步策略--忽略某个配置同步
    背景当我在k8s中用cronhpa+hpa实现定时pod扩容的同时还能兼容平时的hpa弹性伸缩。cronhpa通过修改hpa的minReplicas与maxReplicas,从而实现pod的伸缩。但是,当hpa......
  • Mysql主从同步配置
    一、主数据库的配置1.my.cnf(Linux)/my.ini(Windows)在配置文件参数选项[mysqld]下面添加如下内容log_bin=mysql-binserver_id=1innodb_flush_log_at_trx_commit=......
  • Ubuntu常用快捷键
    转载自https://blog.csdn.net/tjcwt2011/article/details/126390094一、打开Terminal的快捷键是Ctrl+Alt+T二、中止运行Ctrl+C一般最常用的是cd,ls, mkdir,rmdir,......
  • aws binami 配置免费 ssl
    参考链接:https://docs.bitnami.com/aws/faq/administration/generate-configure-certificate-letsencrypt/#步骤bitnami@ip-172-26-15-147:/opt/bitnami/wordpress$su......
  • EMQX(EMQTT)ubuntu下的安装与简单使用
    代码部分是大佬写的需要可以参考 点击这里运行要求gcc-c++erlanggcc--version//查看是否安装gcc出现版本则是已安装,未安装可以参考https://blog.csdn.n......
  • terraform环境配置
    官网​​https://www.terraform.io/​​下载地址​​https://developer.hashicorp.com/terraform/downloads​​环境配置将下载的二进制放在此目录下C:\ProgramFiles\terra......
  • mosh部署配置
    mosh主要用海外服务器连接方式适用于低带宽、高延时的海外服务器连接部署moshyuminstall-yprotobuf-develncurses-develwget-chttps://mosh.org/mosh-1.4.0.tar.gztar......