GVKun编程网logo

Ubuntu 下编译安装与卸载OpenCV(ubuntu怎么卸载opencv)

3

本文将为您提供关于Ubuntu下编译安装与卸载OpenCV的详细介绍,我们还将为您解释ubuntu怎么卸载opencv的相关知识,同时,我们还将为您提供关于apt-getupdate失败ubuntu:

本文将为您提供关于Ubuntu 下编译安装与卸载OpenCV的详细介绍,我们还将为您解释ubuntu怎么卸载opencv的相关知识,同时,我们还将为您提供关于apt-get update 失败 ubuntu:Tempory failure resolving 'cn.archive.ubuntu.com ubuntu、Debian 9 / Debian 10 / Ubuntu 18.04 / Ubuntu 18.10 快速开启 BBR 加速 或 关闭 BBR 加速、install nginx on ubuntu install ubuntu usb install ubuntu 14.04 ubuntu install jd、Intel RealSense D435i Installation on Linux (Ubuntu 16.04 and Ubuntu 18.04)的实用信息。

本文目录一览:

Ubuntu 下编译安装与卸载OpenCV(ubuntu怎么卸载opencv)

Ubuntu 下编译安装与卸载OpenCV(ubuntu怎么卸载opencv)

Ubuntu 18.04 下安装opencv 3.4.10,以及多版本安装和编写CmakeLists.txt问题,最后介绍如何彻底卸载opencv。

帮高师妹搭环境,希望她能送我一篇毕业论文 [doge]

一、源码下载

OpenCV官网

github地址

或者直接下载

二、安装依赖

官方编译安装说明

  • 安装依赖

    sudo apt install build-essential
    
    sudo apt install 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
    

    error:无法定位软件包 libjasper-dev:
    sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
    再次运行第3步。

三、编译安装

  • 解压源码

    tar xvzf opencv-3.4.10.tar.gz
    
  • 将解压后的包移动到/opt

    sudo mv opencv-3.4.10 /opt
    
  • 创建编译文件夹

    cd /opt/opencv-3.4.10
    
    mkdir build && cd build/
    
  • 编译

    # cmake -DWITH_GTK_2_X=ON -DCMAKE_INSTALL_PREFIX=/usr/local ..
    cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_GTK=ON ..
    # CMAKE_BUILD_TYPE=RELEASE:表示编译发布版本
    # CMAKE_INSTALL_PREFIX:表示生成动态库的安装路径,可以自定义
    # WITH_GTK=ON:这个配置是为了防止GTK配置失败:即安装了libgtk2.0-dev依赖,还是报错未安装
    # OPENCV_GENERATE_PKGCONfig=YES:表示自动生成OpenCV的pkgconfig文件,否则需要自己手动生成。
    
    # 线程数最好大点,加快速度,查看cpu线程: 
    # grep 'processor' /proc/cpuinfo | sort -u | wc -l
    make -j12
    
    sudo make install
    
  • 查看安装结果路径

    pkg-config --cflags --libs opencv
    
    sudo find / -iname "*opencv*"
    

四、配置

  • 第一种将opencv库添加到系统路经方法
    sudo gedit /etc/ld.so.conf.d/opencv.conf
    
    添加:
    /usr/local/lib
    
    sudo ldconfig
    
  • 第二种将opencv库添加到系统路经方法
    sudo gedit /etc/ld.so.conf.d
    
    添加:
    include /etc/ld.so.conf.d/*.conf
    include /usr/local/lib
    # cmake编译时填的动态库安装路径加上/lib
    
    sudo ldconfig
    
  • 添加环境变量
    sudo gedit /etc/bash.bashrc
    
    添加:export PKG_CONfig_PATH=$PKG_CONfig_PATH:/usr/local/lib/pkgconfig
    
    source /etc/bash.bashrc
    

五、测试

  • 查看opencv版本

    pkg-config opencv --modversion
    
  • 运行源码示例

    cd /opt/opencv-3.4.10/smaples/cpp/example_cmake
    
    cmake .
    
    make -j12
    
    ./opencv_example
    

    报错:Gtk-Message: Failed to load module "canberra-gtk-module"
    解决方法:sudo apt-get install libcanberra-gtk-module

  • demo测试

    // main.cpp
    
    #include <stdio.h>
    #include <opencv2/opencv.hpp>
    
    using namespace cv;
    
    int main()
    {
        Mat image;
        image = imread("../1.png");
        if(!image.data)
        {
            printf("No image data \n");
            return -1;
        }
        namedWindow("display Image",WINDOW_AUTOSIZE);
        imshow("display Image",image);
        cvWaitKey(0);
        return 0;
    }
    
    # CMakeLists.txt
    
    cmake_minimum_required(VERSION 3.10)
    
    project(test_opencv)
    
    find_package(OpenCV required)
    INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_Dirs})
    
    add_executable(${PROJECT_NAME} main.cpp)
    target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
    

六、安装多版本opencv

  • OpenCV多版本共存(3.4.10 和 4.1.5):
    # 调用4.1.5时:
    
    sudo gedit ~/.bashrc
    
    在文件末尾加上:
    export PKG_CONfig_PATH=/opt/opencv-4.1.5/build/lib/pkgconfig
    export LD_LIBRARY_PATH=/opt/opencv-4.1.5/build/lib
    
    source ~/.bashrc
    
    # 想用之前的(3.4.10),注释这两行就行
    
    # 查询OpenCV的版本
    pkg-config --modversion opencv
    # 3.4.10
    pkg-config --modversion opencv4
    # 4.1.5
    
  • CMakeLists.txt 编写
    # 只有一个版本的OpenCV:
    find_package(OpenCV required)
    # 会自动生成OpenCVConfig.cmake文件,其指定了CMake找OpenCV的路径,其.h文件在哪等
    
    # 多版本OpenCV时,需要找到所需版本对应的OpenCVConfig.cmake文件,
    # 并将其路径添加到工程的CMakeLists.txt中:
    set(OpenCV_DIR "/opt/opencv-4.1.5/build")  
    find_package(OpenCV required) 
    include_directories(${OpenCV_INCLUDE_Dirs})
    

七、彻底卸载opencv

  • 第一种自动卸载
    # 如果删掉了build,再安装上面编译生成一个
    cd /opt/opencv-3.4.10/build
    
    sudo make uninstall
    
    cd ..
    
    sudo rm -r build
    
  • 第二种手动卸载
    sudo rm -r /usr/local/include/opencv2 /usr/local/include/opencv /usr/include/opencv /usr/include/opencv2 /usr/local/share/opencv /usr/local/share/OpenCV /usr/share/opencv /usr/share/OpenCV /usr/local/bin/opencv* /usr/local/lib/libopencv*
    
  • 第三种卸载手动卸载
    # 会删除python的opencv环境
    
    sudo apt autoremove opencv-doc opencv-data libopencv-dev libopencv2.4-java libopencv2.4-jni python-opencv libopencv-core2.4 libopencv-gpu2.4 libopencv-ts2.4 libopencv-photo2.4 libopencv-contrib2.4 libopencv-imgproc2.4 libopencv-superres2.4 libopencv-stitching2.4 libopencv-ocl2.4 libopencv-legacy2.4 libopencv-ml2.4 libopencv-video2.4 libopencv-videostab2.4 libopencv-objdetect2.4 libopencv-calib3d2.4
    
  • 手动确定删除哪些
    sudo find / -name "*opencv*" -exec rm -i {} \
    
  • 直接删除
    cd /usr
    
    find . -name "*opencv*" | xargs sudo rm -rf
    
  • 检查是否卸载完成
    pkg-config opencv --libs
    
    pkg-config opencv --modversion
    

apt-get update 失败 ubuntu:Tempory failure resolving 'cn.archive.ubuntu.com ubuntu

apt-get update 失败 ubuntu:Tempory failure resolving 'cn.archive.ubuntu.com ubuntu

当运行apt-get update后出现如下错误时:
E: Some index files Failed to download,they have been ignored,or old ones used instead.

可以将目录下/var/lib/apt/lists/partial/所有的文件清掉,再次运行apt-get update即可!自带源在大陆不好。


出现以下错误:

ubuntu:Tempory failure resolving ''cn.archive.ubuntu.com ubuntu


修改dns:

1,重启生效:

sudovi/etc/resolvconf/resolv.conf.d/base(这个文件默认是空的)

在里面插入:
nameserver8.8.8.8
nameserver8.8.4.4

如果有多个DNS就一行一个

修改好保存,然后执行

sudoresolvconf-u

再看/etc/resolv.conf,最下面就多了2行:

cat/etc/resolv.conf
#Dynamicresolv.conf(5)fileforglibcresolver(3)generatedbyresolvconf(8)
#DONOTEDITTHISFILEBYHAND--YOURCHANGESWILLBEOVERWRITTEN
可以看到我们的设置已经加上了,然后再ping一个域名,当时就可以解析了,无需重启。


2,重启失效:

配置文件地址 /etc/resolv.conf

使用编辑器打开

改为如下内容:
search localdomain
nameserver 202.96.128.86 希望修改成的DNS
nameserver 202.96.128.166 备用DNS

重启网络:sudo /etc/init.d/networking restart。即可

Debian 9 / Debian 10 / Ubuntu 18.04 / Ubuntu 18.10 快速开启 BBR 加速 或 关闭 BBR 加速

Debian 9 / Debian 10 / Ubuntu 18.04 / Ubuntu 18.10 快速开启 BBR 加速 或 关闭 BBR 加速

如果使用的是 Debian 9、Debian 10、Ubuntu 18.04、Ubuntu 18.10 等内核高于 4.9 版本的系统,均可以使用此方法开启 BBR 加速,若你使用了 Ubuntu 19.04 的系统无需开启,系统默认就开启了。虽然 BBR 没有锐速那么暴力,但是兼容性和稳定性占优势,推荐大家使用。对与什么是 BBR 我就不详细说明了,这是一款由谷歌推出的 TCP 单边加速的拥塞控制算法。

 

开启 BBR

1. 修改 sysctl.conf 系统参数

echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf

 

2. 保存并生效

sysctl -p

得到返回值如下:(最后两行有就可以了)

image.png

 

3. 查看是否已开启 BBR

sysctl net.ipv4.tcp_available_congestion_control

若得到返回值带有 bbr 则成功开启,如:

image.png

 

4. 检查 BBR 是否成功启动

lsmod | grep bbr

如返回信息则表示已经成功开启:

image.png

 

如果不确定自己的系统是支持快速开启 bbr 可以查看使用下面的命令查看内核,只要 4.9 及以上版本均可直接开启:

uname -r

image.png

 

关闭 BBR

若想要关闭 bbr 加速也很简单,只需要将第二步的返回内容在 sysctl.conf 内删除或注释掉即可。

 

1. 修改配置文件

vi /etc/sysctl.conf

进入配置文件,将添加的内容在最后,若找不到往下翻,按 i 键或 Insert 键开启编辑,注释或删除内容后,按 ESC 键退出编辑,键入

:wq

保存并退出。

image.png

 

2. 保存配置

sysctl -p

 

3. 重启系统生效

reboot

 

3. 查看是否已关闭 BBR

sysctl net.ipv4.tcp_available_congestion_control

image.png

 

 

install nginx on ubuntu install ubuntu usb install ubuntu 14.04 ubuntu install jd

install nginx on ubuntu install ubuntu usb install ubuntu 14.04 ubuntu install jd

Intel RealSense D435i Installation on Linux (Ubuntu 16.04 and Ubuntu 18.04)

Intel RealSense D435i Installation on Linux (Ubuntu 16.04 and Ubuntu 18.04)

1. Install 3rd-party dependencies

1.1 apt-get update

sudo apt-get update
  • 1

1.2 install libusb-1.0, libglfw, freeglut,

sudo apt-get install libusb-dev libusb-1.0-0-dev libglfw3 libglfw3-dev freeglut3 freeglut3-dev
  • 1

1.3 Install libpng12-dev

1.3.1 On Ubuntu 16.04, run the following command:

sudo apt-get install libpng12-dev

1.3.2 On Ubuntu 18.04, run the following command:

wget -q -O /tmp/libpng12.deb http://security.ubuntu.com/ubuntu/pool/main/libp/libpng/libpng12-0_1.2.54-1ubuntu1.1_amd64.deb

sudo dpkg -i /tmp/libpng12.deb

2. Debian Package Installation

2.1 Add Intel server to the list of repositories :

echo 'deb http://realsense-hw-public.s3.amazonaws.com/Debian/apt-repo xenial main' | sudo tee /etc/apt/sources.list.d/realsense-public.list
  • 1

It is recommended to backup /etc/apt/sources.list.d/realsense-public.list file in case of an upgrade.

2.2 Register the server’s public key :

sudo apt-key adv --keyserver keys.gnupg.net --recv-key 6F3EFCDE
sudo apt-key adv --keyserver keys.gnupg.net --recv-key C8B3A55A6F3EFCDE || sudo apt-key adv -- keyserver hkp://keyserver.ubuntu.com:80 --recv-key C8B3A55A6F3EFCDE
  • 1
  • 2

Refresh the list of repositories and packages available :

sudo apt-get update
  • 1

2.3 Install the librscalibrationtool package which includes Intel® RealSense™ Dynamic Calibrator:

sudo apt-get install librscalibrationtool
  • 1

说明:

librscalibrationtool适用设备为 Intel RealSense D400, D410, D415, D420, D430, D435.
安装后的使用说明见: /usr/share/doc/librscalibrationtool/README.md

2.4 Failure – (Optional) Developers shall also install librscalibrationapi package:

sudo apt-get install librscalibrationapi
  • 1

Problem:

librscalibrationapi : Depends: libpng12-dev but it is not installable
分析: 自Ubuntu18.04以后,libpng12-dev已经被弃用

3. Checking Package Installation

After the debian package install finishes, check for files installed. Under debian convention, the executables are installed under /usr/bin, library files under /usr/lib, and other files including sample code under /usr/share/doc.
For example, for Calibration Tool, librscalibrationtool, the files are installed as below:

sudo dpkg -L librscalibrationtool
  • 1

4. Video4Linux backend

  1. In order to run demos install:
sudo apt-get install librealsense2-dkms
sudo apt-get install librealsense2-utils
  • 1
  • 2

The above two lines will deploy librealsense2 udev rules, kernel drivers, runtime library and executable demos and tools.
Reconnect the Intel RealSense depth camera and run: realsense-viewer

  1. Developers shall install additional packages:
sudo apt-get install librealsense2-dev
sudo apt-get install librealsense2-dbg
  • 1
  • 2

With dev package installed, you can compile an application with librealsense using g++ -std=c++11 filename.cpp -lrealsense2 or an IDE of your choice.

  1. Verify that the kernel is updated :
modinfo uvcvideo | grep "version:" 
  • 1

should include realsense string

5. Test Installation

  1. Print the tool version to screen:
/usr/bin/Intel.Realsense.DynamicCalibrator -v
  • 1
  1. To print device information to screen, connect a camera device to the system and execute the following command:
/usr/bin/Intel.Realsense.DynamicCalibrator -list
  • 1

6. Perform Calibration for Camera

/usr/bin/Intel.Realsense.DynamicCalibrator
  • 1

* Problem (not fixed):

I can see the RGB, Depth and Gyro information without problems when I run realsense-vieweror subscribe to the realsense-ros topics. But when I run/usr/bin/Intel.Realsense.DynamicCalibrator
And click on Start Calibration I get the Failed to start Calibration Error as seen:
在这里插入图片描述
PS: relative issue discussion on github:
https://github.com/IntelRealSense/librealsense/issues/3990

我们今天的关于Ubuntu 下编译安装与卸载OpenCVubuntu怎么卸载opencv的分享已经告一段落,感谢您的关注,如果您想了解更多关于apt-get update 失败 ubuntu:Tempory failure resolving 'cn.archive.ubuntu.com ubuntu、Debian 9 / Debian 10 / Ubuntu 18.04 / Ubuntu 18.10 快速开启 BBR 加速 或 关闭 BBR 加速、install nginx on ubuntu install ubuntu usb install ubuntu 14.04 ubuntu install jd、Intel RealSense D435i Installation on Linux (Ubuntu 16.04 and Ubuntu 18.04)的相关信息,请在本站查询。

本文标签:

上一篇Ubuntu Desktop开启VNC远程访问(ubuntu vnc 远程桌面)

下一篇ubuntu 20.01利用apt部署logstash并添加到自启动服务(ubuntu配置apt)