iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >从源码安装OpenCV,使用python
  • 161
分享到

从源码安装OpenCV,使用python

源码OpenCVpython 2023-01-31 02:01:56 161人浏览 安东尼

Python 官方文档:入门教程 => 点击学习

摘要

https://GitHub.com/OpenCV 需要的有两个部分:opencv 和opencv_contrib 这两个部分选择相同的版本,opencv_contrib是opencv的扩充. 安装cmake-gui (

https://GitHub.com/OpenCV
这里写图片描述
需要的有两个部分:opencv 和opencv_contrib 这两个部分选择相同的版本,opencv_contrib是opencv的扩充.
opencv3.4.1
opencv_contrib 3.4.1

安装cmake-gui (如何安装不多介绍)cmake-gui
opencv3.4.1中创建一个build文件夹,并将opencv_contrib-3.4.1(扩展库)添加到opencv3.4.1文件夹.

配置如下:
1
2
3
4
5
6
7
8
9
配置输出的信息:

General configuration for OpenCV 3.4.1 =====================================
  Version control:               unknown

  Extra modules:
    Location (extra):            /home/qy/opencv-3.4.1/opencv_contrib-3.4.1/modules
    Version control (extra):     unknown

  PlatfORM:
    Timestamp:                   2018-05-10T15:38:21Z
    Host:                        linux 4.4.0-122-generic x86_64
    CMake:                       3.5.1
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/make
    Configuration:               Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3
      requested:                 SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (3 files):          + SSSE3 SSE4_1
      SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (2 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (5 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (9 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
      AVX512_SKX (1 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_SKX

  C/C++:
    Built as dynamic libs?:      YES
    c++ Compiler:                /usr/bin/c++  (ver 5.4.0)
    C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
    C Compiler:                  /usr/bin/cc
    C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
    Linker flags (Release):      
    Linker flags (Debug):        
    ccache:                      NO
    Precompiled headers:         YES
    Extra dependencies:          dl m pthread rt
    3rdparty dependencies:       tbb

  OpenCV modules:
    To be built:                 aruco bgsegm bioinspired calib3D ccalib core cvv datasets dnn dnn_objdetect dpm face features2d flann freetype fuzzy hdf hfs highgui img_hash imGCodecs imgproc java_bindings_generator line_descriptor ml objdetect optflow phase_unwrapping photo plot python3 python_bindings_generator reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab viz xfeatures2d ximgproc xobjdetect xphoto
    Disabled:                    js Python2 world
    Disabled by dependency:      -
    Unavailable:                 cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev dnn_modern java matlab ovis sfm
    Applications:                tests perf_tests examples apps
    Documentation:               NO
    Non-free alGorithms:         NO

  GUI: 
    Qt:                          YES (ver 5.5.1)
      QT OpenGL support:         NO
    GTK+:                        NO
    VTK support:                 YES (ver 6.2.0)

  Media I/O: 
    ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.8)
    JPEG:                        libjpeg (ver 90)
    WEBP:                        /usr/lib/x86_64-linux-gnu/libwebp.so (ver encoder: 0x0202)
    PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.2.54)
    TIFF:                        /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 / 4.0.6)
    JPEG 2000:                   /usr/lib/x86_64-linux-gnu/libjasper.so (ver 1.900.1)
    OpenEXR:                     build (ver 1.7.1)

  Video I/O:
    DC1394:                      YES (ver 2.2.4)
    FFmpeg:                      YES
      avcodec:                   YES (ver 56.60.100)
      avformat:                  YES (ver 56.40.101)
      avutil:                    YES (ver 54.31.100)
      swscale:                   YES (ver 3.1.101)
      avresample:                NO
    GStreamer:                   NO
    libv4l/libv4l2:              NO
    v4l/v4l2:                    linux/videodev2.h
    gPhoto2:                     NO

  Parallel framework:            TBB (ver 2018.0 interface 10001)

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Intel IPP:                   2017.0.3 [2017.0.3]
           at:                   /home/qy/opencv-3.4.1/build/3rdparty/ippicv/ippicv_lnx
    Intel IPP IW:                sources (2017.0.3)
              at:                /home/qy/opencv-3.4.1/build/3rdparty/ippicv/ippiw_lnx
    Lapack:                      YES (/usr/lib/liblapack.so /usr/lib/libcblas.so /usr/lib/libatlas.so)
    Eigen:                       YES (ver 3.2.92)
    Custom HAL:                  NO
    Protobuf:                    build (3.5.1)

  NVIDIA CUDA:                   NO

  OpenCL:                        YES (no extra features)
    Include path:                /home/qy/opencv-3.4.1/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  Python 3:
    Interpreter:                 /home/qy/software/anaconda3/envs/MachineLearning/bin/python3.6m (ver 3.6.5)
    Libraries:                   /home/qy/software/anaconda3/envs/machineLearning/lib/libpython3.6m.so (ver 3.6.5)
    numpy:                       /home/qy/software/anaconda3/envs/machineLearning/lib/python3.6/site-packages/numpy/core/include (ver 1.14.2)
    packages path:               /home/qy/software/anaconda3/envs/machineLearning/lib/python3.6/site-packages

  Python (for build):            /home/qy/software/anaconda3/envs/machineLearning/bin/python3.6m

  Java:                          
    ant:                         NO
    JNI:                         NO
    Java wrappers:               NO
    Java tests:                  NO

  Matlab:                        NO

  Install to:                    /usr/opencv34

笔者使用的是ubuntu16.04,默认地opencv会链到系统的python2.7上去(看cache可知),所以需要指定到咱下的anaconda的python3上,在配置python3的时候,cmake-gui可能比较麻烦,笔者使用的命令行如下所示,记得把python所有相关路径改到自己的anaconda下。然后在cmake-gui中进行跟新配置. 笔者的python的环境的路径为/home/qy/software/anaconda3/envs/machineLearning,machineLearning是一个子环境,安装了python3,所以只要是python3的环境就可以.

$ cd build
cmake -D BUILD_opencv_python3=yes -D BUILD_opencv_python2=no -D PYTHON3_EXECUTABLE=/home/qy/software/anaconda3/envs/machineLearning/bin/python3.6m -D PYTHON3_INCLUDE_DIR=/home/qy/software/anaconda3/envs/machineLearning/include/python3.6m -D PYTHON3_LIBRARY=/home/qy/software/anaconda3/envs/machineLearning/lib/libpython3.6m.so -D PYTHON3_NUMPY_INCLUDE_DIRS=/home/qy/software/anaconda3/envs/machineLearning/lib/python3.6/site-packages/numpy/core/include -D PYTHON3_PACKAGES_PATH=/home/qy/software/anaconda3/envs/machineLearning/lib/python3.6/site-packages -D PYTHON_DEFAULT_EXECUTABLE=/home/qy/software/anaconda3/envs/machineLearning/bin/python3.6m ..

切换到cmake-gui,点击reload cache,把上面通过命令行配置的信息在cmake-gui中进行更新
这里写图片描述

在编译之前,需要安装OpenCV的依赖项:
依赖项参考:
Https://docs.opencv.org/2.4/doc/tutorials/introduction/linux_install/linux_install.html
https://www.linuxidc.com/Linux/2017-02/141157.htm
https://www.cnblogs.com/tlnshuju/p/6767337.html

# Build tools:
sudo apt-get install -y build-essential cmake

# GUI (if you want to use GTK instead of Qt, replace 'qt5-default' with 'libgtkglext1-dev' and remove '-DWITH_QT=ON' option in CMake):
sudo apt-get install -y qt5-default libvtk6-dev

# Media I/O:
sudo apt-get install -y zlib1g-dev libjpeg-dev libwebp-dev libpng-dev libtiff5-dev libjasper-dev libopenexr-dev libgdal-dev

# Video I/O:
sudo apt-get install -y libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev yasm libopencore-amrnb-dev libopencore-amrwb-dev libv4l-dev libxine2-dev

# Parallelism and linear algebra libraries:
sudo apt-get install -y libtbb-dev libeigen3-dev

# Python:
sudo apt-get install -y python-dev python-tk python-numpy python3-dev python3-tk python3-numpy

配置完成后,点击Generate,会在build文件夹中生成一系列文件.这里写图片描述
接下来使用四个线程进行编译:

make -j4 

然后进行安装:

cd opencv3.4.0/build/
sudo make install

在配置中opencv的安装目录可以用默认的也可以自己设定,笔者设定是:

/usr/opencv34

这里写图片描述
编译完成后,把编译出来的cv2.cpython-36m-x86_64-linux-gnu.so库(opencv-python)拷到anaconda的python库包下
这里写图片描述
这里写图片描述
然后可以使用相应的python3 import cv2

--结束END--

本文标题: 从源码安装OpenCV,使用python

本文链接: https://www.lsjlt.com/news/185804.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • 从源码安装OpenCV,使用python
    https://github.com/opencv 需要的有两个部分:opencv 和opencv_contrib 这两个部分选择相同的版本,opencv_contrib是opencv的扩充. 安装cmake-gui (...
    99+
    2023-01-31
    源码 OpenCV python
  • Linux下从源码安装python,将p
    以centos7为例:源码安装python,一般先安装一些devel的包:yum -y install xz wget gcc make gdbm-devel openssl-devel sqlite-devel zlib-devel bz...
    99+
    2023-01-31
    源码 Linux python
  • MYSQL5.7.22 源码安装 主从搭建
    操作系统版本 CENTOS7.6 MYSQL5.7.22 啥?为啥我的操作系统木有iso的安装镜像,哎算了,不能弄本地yum源,那就弄个网络的吧。只不过默认的用不了,那就自己动手丰衣足食 cd /...
    99+
    2022-10-18
  • 在 Linux 上从源代码安装 MySQL
    Linux 支持多种不同的方法来安装 MySQL。在众多可用安装中,只需使用 Oracle 的发行版之一。步骤类型 - Apt,设置method-启用 MySQL Apt 存储库类型 - Yum,设置 method-启用 MySQL Yum...
    99+
    2023-10-22
  • Linux 源码安装Python
    下载源码tar包下载地址:https://www.python.org/downloads/我这里下载的 Python-2.7.11.tgz# tar -zxvf Python-2.7.11.tgz进入解压缩后的文件夹# cd Python...
    99+
    2023-01-31
    源码 Linux Python
  • POSTGRESQL10.8怎么用源码安装主从搭建
    本篇内容介绍了“POSTGRESQL10.8怎么用源码安装主从搭建”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有...
    99+
    2022-10-18
  • POSTGRESQL10.3源码如何安装主从搭建
    这篇文章将为大家详细讲解有关POSTGRESQL10.3源码如何安装主从搭建,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。一、下载POSTGRESQL源码安装包及主机配置...
    99+
    2022-10-18
  • 如何从源码编译安装 PHP-FPM
    随着 PHP 的普及和使用,PHP-FPM 也被越来越多的使用者与开发者所熟知和使用。由于 PHP-FPM 带有更先进的进程管理和重载工具,它被广泛地用于高访问量和 HTTP 高并发场景下的 PHP 程序。本篇文章将讲解如何从源码编译安装 ...
    99+
    2023-05-14
  • MYSQL5.6.40源码安装 主从搭建 主主搭建
    前言: 前面那篇5.6.38主从搭建的文章属于测试系统里面弄着玩的,以下这篇文章写的是在公司生产库上搭建的MYSQL主从。 在上系统前,纠结了很久,到底使用哪种数据库(PG?HBASE?MONGODB...
    99+
    2022-10-18
  • 使用豆瓣源安装Python包
            Python pip安装的原理就是从Python的官方源https://pypi.python.org/pypi下载到本地安装,但是访问官方源网络不稳定,速度较慢,我经常会遇到一个问题,pip安装包由于速度较慢,过了一段时间...
    99+
    2023-01-31
    豆瓣 Python
  • postgresql的源码安装及配置使用
    装postgresql非常简单。直接三部曲搞定。./configure --prefix=/usr/local/postgresqlmakemake install创建postgresql的数据目录mkdi...
    99+
    2022-10-18
  • linux上如何使用源码安装swoole
    这篇“linux上如何使用源码安装swoole”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“linux上如何使用源码安装sw...
    99+
    2023-07-05
  • 怎么用源码安装mysql5.6.37
    这篇文章主要介绍“怎么用源码安装mysql5.6.37”,在日常操作中,相信很多人在怎么用源码安装mysql5.6.37问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”怎么用源...
    99+
    2022-10-18
  • 怎么用源码安装PostgreSQL
    本篇内容介绍了“怎么用源码安装PostgreSQL”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!数据库版本...
    99+
    2022-10-18
  • 怎么用源码安装mysql5.6.35
    这篇文章主要介绍“怎么用源码安装mysql5.6.35”,在日常操作中,相信很多人在怎么用源码安装mysql5.6.35问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”怎么用源...
    99+
    2022-10-18
  • 怎么用源码安装MYSQL
    这篇文章主要介绍“怎么用源码安装MYSQL”,在日常操作中,相信很多人在怎么用源码安装MYSQL问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”怎么用源码安装MYSQL”的疑惑...
    99+
    2022-10-18
  • 使用源码安装mysql5.7.11的详细步骤
    下文给大家带来关于使用源码安装mysql5.7.11的详细步骤,感兴趣的话就一起来看看这篇文章吧,相信看完使用源码安装mysql5.7.11的详细步骤对大家多少有点帮助吧。一、前期准备工作1、安装依赖包:y...
    99+
    2022-10-18
  • 企业级使用LAMP源码安装教程
    目录LAMP架构1.lamp介绍2.web服务工作流程web服务器的资源分为俩种:静态和动态资源web服务器如何处理客户端的请求2.1cgi和fastcgi2.2httpd与php结...
    99+
    2022-11-12
  • ”conda,pip,git clone和源码安装“四种方式安装 python 包
    一、安装位置 主要存在三个安装位置: 无论系统环境还是虚拟环境,conda install 均将 package 安装到 anaconda3/pkgs 目录下 系统环境下 pip install 将 package 安装到 ~/.lo...
    99+
    2023-09-18
    python git conda Powered by 金山文档
  • Centosz中如何使用源码方式安装python3
    本文小编为大家详细介绍“Centosz中如何使用源码方式安装python3”,内容详细,步骤清晰,细节处理妥当,希望这篇“Centosz中如何使用源码方式安装python3”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知...
    99+
    2023-06-27
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作