Install OpenCV-Python in Ubuntu
- 之前安装python版opencv,需要下载whl文件,进行安装,这是在window环境下的:
- 安装opencv_python,下载whl包
安装系统python下的opencv
-
今天发现一个简单的方法。
Install package python-opencv with following command in terminal (as root user).
$ sudo apt-get install python-opencv
Open Python IDLE (or IPython) and type following codes in Python terminal.
import cv2 as cv
print(cv.__version__)
If the results are printed out without any errors, congratulations !!! You have installed OpenCV-Python successfully.
针对conda环境下env安装python-opencv
- 发现有些坑
- 首先,我们直接编译opencv应该就有python的接口:/usr/local/lib/python3.5/dist-packages;发现有
cv2.cpython-35m-x86_64-linux-gnu.so
文件,说的直接拷贝到env下的site-packages,结果报错
; - 然后我们本身直接
sudo apt-get install python-opencv
安装的是直接可以使用的; - sudo直接安装按系统默认的python2.7上:
/usr/lib/python2.7/dist-packages
下面有cv2.x86_64-linux-gnu.so;
rjw@rjw:~$ /usr/bin/python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'2.4.9.1'
-
中间还有错: Python 3.5 ImportError: dynamic module does not define module export function (PyInit_cv2)
-
参考的方法: Linux下安装python-opencv
-
最终解决方法:
conda install -c menpo opencv3
:Mac+anaconda+python3.6安装opencv3
(tensorflow) rjw@rjw:~$ python
Python 3.5.6 |Anaconda, Inc.| (default, Aug 26 2018, 21:41:56)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.2.0'
-
直接
conda install python-opencv
在conda环境下找不到包 -
update2018.11.11;今天遇到个问题:
UnsatisfiableError: The following specifications were found to be in conflict: - opencv3 -> python
- 重新使用:
pip install opencv-python
(maskrcnn_benchmark) rjw@rjw:~/desktop$ pip install opencv-python
Collecting opencv-python
Downloading https://files.pythonhosted.org/packages/d2/cf/1e5774811aa1b656fba8476e98edab2f99a7683c3aaeede057cdc9959c24/opencv_python-3.4.3.18-cp37-cp37m-manylinux1_x86_64.whl (25.0MB)
100% |████████████████████████████████| 25.0MB 72kB/s
Requirement already satisfied: numpy>=1.14.5 in /home/rjw/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages (from opencv-python) (1.15.4)
Installing collected packages: opencv-python
Successfully installed opencv-python-3.4.3.18
- 可以想想,在anaconda下怎么使用自己编译的opencv,这样就可以万能使用!!!
其他错误
- 遇到下面问题,使用
conda install -c asmeurer pango
,参考github:Qt fails in GNOME/Fedora 22
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0: undefined symbol: hb_font_funcs_set_variation_glyph_func
C/C++基本语法学习
STL
C++ primer