Install OpenCV-Python in Ubuntu


安裝系統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'
(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,這樣就可以萬能使用!!!

其他錯誤

>>> 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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM