-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_opencv_3.4.0
152 lines (124 loc) · 7.51 KB
/
install_opencv_3.4.0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
编译好的opencv和自己编译安装opencv的区别
Ubuntu安装了anaconda以后,
$ conda install opencv
直接安装网上编译好的opencv,但是Ubuntu,python以及opencv不同版本之间使用都有差异,容易出问题;但是如果没出问题的话,这确实是最简单的安装方式.
$ pip install opencv-python
或者$ apt-get install python-opencv
或者$ conda install –c https://conda.binstar.org/menpoopencv
具有同样问题,所以有的人选择自己编译安装opencv.
比如直接
$ conda install opencv
之后,调用cv2.destroyAllWindows()时有时会出现:
Thefunction is not implemented. Rebuild the library with Windows, GTK+ 2.x orCarbon support.
If you are on Ubuntu or Debian, install libgtk2.0‑dev and pkg‑config, then re‑runcmake or configure script
这就是网上编译好的opencv包在编译的过程中设置的选项可能和你当前需求不一样,解决方法就是自己编译安装opencv
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
安装之前,先确保没有opencv残余,
卸载opencv
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*
2. Ubuntu下anaconda卸载opencv
安装前首先把之前的opencv卸载掉,conda install装的就用conda uninstall卸,其他的安装方式也按照对应方式卸载就可以了.
然后
$ cd /usr/local/lib
$ sudo rm–r opencv相关的包
$ cd /usr/local/include
$ sudo rm–r opencv相关的包
看看/usr/local/下有没有其他opencv,有的话一并删除
删除一系列包可以用rm –r opencv*,以opencv开头的包就都会被删掉
##########################
install anaconda and run
##########################
# ignored insatall anaconda
# open anaconda navigator
anaconda-navigator
# build environment,next open the environment with terminal
##########################
update ubuntu
##########################
sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove
##########################
Installing all the recommended packages
##########################
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
sudo apt-get install libgtk-3-dev
sudo apt-get install libatlas-base-dev gfortran
sudo apt-get install python2.7-dev python3.5-dev
sudo apt-get install libatlas-base-dev gfortran pylint
##########################
Download OpenCV source
##########################
opencv official: https://github.com/opencv/opencv_contrib
opencv_contrib: https://github.com/opencv/opencv_contrib
opencv-3.4.0 download: https://downloads.sourceforge.net/opencvlibrary/opencv-3.4.0.zip
opencv_contrib-3.4.0 download: https://github.com/opencv/opencv_contrib/archive/3.4.0/opencv_contrib-3.4.0.tar.gz
##########################
Configuring and compiling
##########################
cd ~/opencv-3.4.0/
mkdir build
cd build
sudo cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D OPENCV_EXTRA_MODULES_PATH=/home/qian/Software/opencv/opencv_contrib-3.4.0/modules \
-D PYTHON_EXECUTABLE=/home/qian/Software/anaconda3/envs/tensorflow-gpu/bin/python3 \
-D BUILD_EXAMPLES=ON ..
## OPENCV_EXTRA_MODULES_PATH: opencv的额外模块地址,必须选择绝对地址,否则会出现错误:Compiling OpenCV 3.3 : C++11 is not supported
## PYTHON_EXECUTABLE: python的路径
make -j11
sudo make install
sudo ldconfig
## 参考:
https://medium.com/@debugvn/installing-opencv-3-3-0-on-ubuntu-16-04-lts-7db376f93961
https://www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/
发现安装的时候特别慢,主要是在下载第三方的文件,有一个技巧,即先翻墙下载好第三方的文件,
然后放在opencv-3.4.0文件目录的.cache文件夹中,结构格式如下面这个网站
http://download.csdn.net/download/u010342901/10173967
下载第三方的文件目录: https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=opencv-gstreamer
用shell脚本提取其中的地址。
这边我提供了自己的脚本,可以直接提取地址,将脚本保存成download.3rdpart.sh。然后添加执行权限,./download.3rdpart.sh即可。
shell脚本如下:
#!/bin/bash
echo "usage : chmod +x download_3rdpart.sh"
echo " ./download.3rdpart.sh"
touch 提取网站.txt
_srcname=opencv
_ippicv_ver='2017u3'
_ippicv_date='20170822'
_tinydnn_ver='1.0.0a3'
_dnn_face_detector_file='res10_300x300_ssd_iter_140000.caffemodel'
_ippicv_commit='dfe3162c237af211e98b8960018b564bc209261d'
_bootdesc_commit='34e4206aef44d50e6bbcd0ab06354b52e7466d26'
_vgg_commit='fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d'
_dnn_face_detector_commit='b2bfc75f6aea5b1f834ff0f0b865a7c18ff1459f'
_face_landmakr_model_commit='8afa57abc8229d611c4937165d20e2a2d9fc5a12'
pkgname=opencv-gstreamer
pkgver=3.4.0
pkgrel=1
pkgdesc='Open Source Computer Vision Library (no Xine/FFmpeg dependency, uses GStreamer)'
arch=('i686' 'x86_64')
echo "https://github.com/opencv/opencv/archive/${pkgver}.tar.gz" > pachong.txt
echo "https://github.com/opencv/opencv_contrib/archive/${pkgver}.tar.gz" >> pachong.txt
echo "https://github.com/tiny-dnn/tiny-dnn/archive/v${_tinydnn_ver}.tar.gz" >> pachong.txt
echo "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${_dnn_face_detector_commit}/${_dnn_face_detector_file}" >> pachong.txt
echo "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${_face_landmakr_model_commit}/face_landmark_model.dat" >> pachong.txt
echo "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${_bootdesc_commit}/boostdesc_bgm.i" >> pachong.txt
echo "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${_bootdesc_commit}/boostdesc_bgm_bi.i" >> pachong.txt
echo "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${_bootdesc_commit}/boostdesc_bgm_hd.i" >> pachong.txt
echo "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${_bootdesc_commit}/boostdesc_binboost_064.i" >> pachong.txt
echo "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${_bootdesc_commit}/boostdesc_binboost_128.i" >> pachong.txt
echo "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${_bootdesc_commit}/boostdesc_binboost_256.i" >> pachong.txt
echo "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${_bootdesc_commit}/boostdesc_lbgm.i" >> pachong.txt
echo "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${_vgg_commit}/vgg_generated_48.i" >> pachong.txt
echo "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${_vgg_commit}/vgg_generated_64.i" >> pachong.txt
echo "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${_vgg_commit}/vgg_generated_80.i" >> pachong.txt
echo "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${_vgg_commit}/vgg_generated_120.i" >> pachong.txt
echo source_x86_64="https://github.com/opencv/opencv_3rdparty/raw/${_ippicv_commit}/ippicv/ippicv_${_ippicv_ver}_lnx_intel64_general_${_ippicv_date}.tgz" >> pachong.txt