Deepin环境安装配置(c++VScode+opencv+QT+python)

Deepin环境安装配置(c++VScode+opencv+QT+python)

Excerpt

一、 工具准备篇

1. .deb安装

sudo dpkg -i ***.deb

2. install vim/gedit 文本编辑器

sudo apt-get install vim

sudo apt-get install gedit

3. 更换apt国内源

# 备份原来的源

sudo cp /etc/apt/sources.list /etc/apt/sources_init.list

# 更换源 也可使用图形界面配置:系统设置 -> 软件和更新 选择下载服务器 -> “mirrors.aliyun.com”

sudo vi /etc/apt/sources.list

将以下国内源复制进文档:

deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

# 更新源

sudo apt-get update

#更新软件

sudo apt-get upgrade

4. 将系统自带python3链接到python

# 将系统自带的python3链接到python

sudo ln -s /usr/bin/python3.8 /usr/bin/python

5. 安装pip3

# 安装pip

sudo apt-get install python3-pip # 输入pip3 -V查看pip3的版本

# 更新pip3

sudo pip3 install --upgrade pip

# 将pip3链接到pip,可直接用pip命令

sudo ln -s /usr/bin/pip3 /usr/bin/pip

解决pip下载慢的问题

方法1:可以在使用pip的时候在后面加上-i参数,指定pip源

pip install scrapy -i https://pypi.tuna.tsinghua.edu.cn/simple

方法2:更换pip国内源

#创建pip文件夹

cd .config

sudo mkdir pip

cd pip

#创建pip.cong文件

sudo touch pip.conf

#编辑pip.conf文件

sudo vim pip.conf

在pip.conf文件中添加清华大学的pypi镜像,要是想用其他的镜像,替换成相应的地址即可。

[global]

index-url = https://pypi.tuna.tsinghua.edu.cn/simple

进入boot模式(sudo su),直接复制到终端运行

apt-get install python3-pipln -s /usr/bin/pip3 /usr/bin/pipmkdir ~/.config/pip(echo "[global]timeout=6index-url=https://pypi.tuna.tsinghua.edu.cn/simpleextra-index-url=    https://mirrors.aliyun.com/pypi/simple"echo "[install]trusted-host=    pypi.tuna.tsinghua.edu.cn    mirrors.aliyun.com") >> ~/.config/pip/pip.confpip3 install --upgrade pip

二、 VScode开发环境

1. 下载VScode

参考:https://zhuanlan.zhihu.com/p/112215618

首先在官网找到需要下载的文件,点击下载。

在浏览器或者下载软件中就可以看到这么一个下载地址了,将其复制下来(如下图箭头所指)。

Deepin环境安装配置(c++VScode+opencv+QT+python)_第1张图片

然后将红框内的部分更换为如下内容:vscode.cdn.azure.cn <--------就是左边这个

更新后的地址为:https://vscode.cdn.azure.cn/stable/ea3859d4ba2f3e577a159bc91e3074c5d85c0523/code_1.52.1-1608136922_amd64.deb

安装.deb

sudo dpkg -i code_1.52.1-1608136922_amd64.deb

2. 安装依赖、插件

安装依赖包:

sudo apt-get install gcc g++ gdb

安装VScode插件:

1.C/C++  
2.Code Runner  
3.Run in Terminal

三、安装OpenCV

参考:https://blog.csdn.net/WJ_SHI/article/details/107605439

1. 下载opencv源码 https://opencv.org/ eg: opencv-4.5.1.zip

2. 安装依赖

libjasper-dev包无法定位,增加库并更新atp

sudo add-apt-repository “deb http://security.ubuntu.com/ubuntu xenial-security main”

sudo apt-get update

# 安装opencv依赖

sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg-dev libtiff-dev libswscale-dev libpng-dev libjasper-dev

3. 安装opencv

# install cmake 工具

sudo apt-get install cmake

# 解压.zip,将解压后文件移动到/opt目录下

cd /*** # 下载的opencv-4.5.1.zip文件所在目录

unzip opencv-4.5.1.zip

sudo mv opencv-4.5.1 /opt

cd /opt/opencv-4.5.1

sudo mkdir build

cd build

sudo cmake …

sudo make

sudo make install

注意:最后所有文件将被安装到目录“/usr/local/”下面。

4. 修改环境变量配置

安装完成后,手动创建opencv.pc:

cd /usr/local/lib

sudo mkdir pkgconfig && cd pkgconfig

sudo gedit opencv.pc

然后添加:

prefix=/usr/local
exec_prefix=${prefix}
includedir=/usr/local/include
libdir=/usr/local/lib

Name: OpenCV
Description: Open Source Computer Vision Library
Version: 4.6.0
Libs: -L e x e c _ p r e f i x / l i b − l o p e n c v _ s t i t c h i n g − l o p e n c v _ s u p e r r e s − l o p e n c v _ v i d e o s t a b − l o p e n c v _ a r u c o − l o p e n c v _ b g s e g m − l o p e n c v _ b i o i n s p i r e d − l o p e n c v _ c c a l i b − l o p e n c v _ d n n _ o b j d e t e c t − l o p e n c v _ d p m − l o p e n c v _ f a c e − l o p e n c v _ p h o t o − l o p e n c v _ f r e e t y p e − l o p e n c v _ f u z z y − l o p e n c v _ h d f − l o p e n c v _ h f s − l o p e n c v _ i m g _ h a s h − l o p e n c v _ l i n e _ d e s c r i p t o r − l o p e n c v _ o p t f l o w − l o p e n c v _ r e g − l o p e n c v _ r g b d − l o p e n c v _ s a l i e n c y − l o p e n c v _ s t e r e o − l o p e n c v _ s t r u c t u r e d _ l i g h t − l o p e n c v _ p h a s e _ u n w r a p p i n g − l o p e n c v _ s u r f a c e _ m a t c h i n g − l o p e n c v _ t r a c k i n g − l o p e n c v _ d a t a s e t s − l o p e n c v _ t e x t − l o p e n c v _ d n n − l o p e n c v _ p l o t − l o p e n c v _ x f e a t u r e s 2 d − l o p e n c v _ s h a p e − l o p e n c v _ v i d e o − l o p e n c v _ m l − l o p e n c v _ x i m g p r o c − l o p e n c v _ c a l i b 3 d − l o p e n c v _ f e a t u r e s 2 d − l o p e n c v _ h i g h g u i − l o p e n c v _ v i d e o i o − l o p e n c v _ f l a n n − l o p e n c v _ x o b j d e t e c t − l o p e n c v _ i m g c o d e c s − l o p e n c v _ o b j d e t e c t − l o p e n c v _ x p h o t o − l o p e n c v _ i m g p r o c − l o p e n c v _ c o r e L i b s . p r i v a t e : − l d l − l m − l p t h r e a d − l r t C f l a g s : − I {exec\_prefix}/lib -lopencv\_stitching -lopencv\_superres -lopencv\_videostab -lopencv\_aruco -lopencv\_bgsegm -lopencv\_bioinspired -lopencv\_ccalib -lopencv\_dnn\_objdetect -lopencv\_dpm -lopencv\_face -lopencv\_photo -lopencv\_freetype -lopencv\_fuzzy -lopencv\_hdf -lopencv\_hfs -lopencv\_img\_hash -lopencv\_line\_descriptor -lopencv\_optflow -lopencv\_reg -lopencv\_rgbd -lopencv\_saliency -lopencv\_stereo -lopencv\_structured\_light -lopencv\_phase\_unwrapping -lopencv\_surface\_matching -lopencv\_tracking -lopencv\_datasets -lopencv\_text -lopencv\_dnn -lopencv\_plot -lopencv\_xfeatures2d -lopencv\_shape -lopencv\_video -lopencv\_ml -lopencv\_ximgproc -lopencv\_calib3d -lopencv\_features2d -lopencv\_highgui -lopencv\_videoio -lopencv\_flann -lopencv\_xobjdetect -lopencv\_imgcodecs -lopencv\_objdetect -lopencv\_xphoto -lopencv\_imgproc -lopencv\_core Libs.private: -ldl -lm -lpthread -lrt Cflags: -I exec_prefix/liblopencv_stitchinglopencv_superreslopencv_videostablopencv_arucolopencv_bgsegmlopencv_bioinspiredlopencv_ccaliblopencv_dnn_objdetectlopencv_dpmlopencv_facelopencv_photolopencv_freetypelopencv_fuzzylopencv_hdflopencv_hfslopencv_img_hashlopencv_line_descriptorlopencv_optflowlopencv_reglopencv_rgbdlopencv_saliencylopencv_stereolopencv_structured_lightlopencv_phase_unwrappinglopencv_surface_matchinglopencv_trackinglopencv_datasetslopencv_textlopencv_dnnlopencv_plotlopencv_xfeatures2dlopencv_shapelopencv_videolopencv_mllopencv_ximgproclopencv_calib3dlopencv_features2dlopencv_highguilopencv_videoiolopencv_flannlopencv_xobjdetectlopencv_imgcodecslopencv_objdetectlopencv_xphotolopencv_imgproclopencv_coreLibs.private:ldllmlpthreadlrtCflags:I{includedir}

更改环境变量,输入命令:

sudo gedit /etc/bash.bashrc

打开之后,在文件最后面添加以下内容:

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

保存退出,opencv基本上就安装完成了。通过 pkg-config 查看 opencv 版本:

pkg-config --modversion opencv

在bash.bashrc文件末尾加上

PKG_CONFIG=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig

export PKG_CONFIG_PATH

保存后退出,执行以下指令测试opencv配置成功:

ldconfig -p | grep opencv

5. python 链接opencv

pip install opencv-python

进行python测试,如下:

$ python
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import cv2
>>> print(cv2.__version__)
4.5.1

四、安装QT

4.1

1. 1 安装依赖库

sudo apt-get install g++

sudo apt-get install libx11-dev libxext-dev libxtst-dev

sudo apt-get install xlibmesa-gl-dev libglu1-mesa-dev

1.2 QT的安装

1.3 QT的配置

项目文件.pro中加入:

INCLUDEPATH +=  /usr/local/include\
                /usr/local/include/opencv4 \
                /usr/local/include/opencv4/opencv2

LIBS += /usr/local/lib/libopencv_highgui.so \
        /usr/local/lib/libopencv_core.so    \
        /usr/local/lib/libopencv_imgproc.so \
        /usr/local/lib/libopencv_imgcodecs.so

你可能感兴趣的:(c++,vscode,opencv)