Opencv with python linux

Opencv with python linux

The following steps have been tested for Ubuntu 10.04 but should work with other distros as well.

Required Packages

  • GCC 4.4.x or later
  • CMake 2.8.7 or higher
  • Git
  • GTK+2.x or higher, including headers (libgtk2.0-dev)
  • pkg-config
  • Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy)
  • ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev
  • [optional] libtbb2 libtbb-dev
  • [optional] libdc1394 2.x
  • [optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev
  • [optional] CUDA Toolkit 6.5 or higher

The packages can be installed using a terminal and the following commands or by using Synaptic Manager:

[required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev [optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

Getting OpenCV Source Code

You can use the latest stable OpenCV version or you can grab the latest snapshot from our Git repository.

Getting the Latest Stable OpenCV Version

Getting the Cutting-edge OpenCV from the Git Repository

Launch Git client and clone OpenCV repository. If you need modules from OpenCV contrib repository then clone it as well.

Читайте также:  Css перенос строки после элемента

Building OpenCV from Source Using CMake

  1. Create a temporary directory, which we denote as , where you want to put the generated Makefiles, project files as well the object files and output binaries and enter there. For example
  • set full path to OpenCV source code, e.g. /home/user/opencv
  • set full path to , e.g. /home/user/opencv/build
  • set optional parameters
  • run: “Configure”
  • run: “Generate”
  • build type: CMAKE_BUILD_TYPE=Release\Debug
  • to build with modules from opencv_contrib set OPENCV_EXTRA_MODULES_PATH to
  • set BUILD_DOCS for building documents
  • set BUILD_EXAMPLES to build all examples
  • PYTHON2(3)_EXECUTABLE =
  • PYTHON_INCLUDE_DIR = /usr/include/python
  • PYTHON_INCLUDE_DIR2 = /usr/include/x86_64-linux-gnu/python
  • PYTHON_LIBRARY = /usr/lib/x86_64-linux-gnu/libpython.so
  • PYTHON2(3)_NUMPY_INCLUDE_DIRS = /usr/lib/python/dist-packages/numpy/core/include/
  • Unset parameter: BUILD_SHARED_LIBS
  • It is useful also to unset BUILD_EXAMPLES, BUILD_TESTS, BUILD_PERF_TESTS — as they all will be statically linked with OpenCV and can take a lot of memory.

Источник

Opencv with python linux

In this tutorial We will learn to setup OpenCV-Python in Ubuntu System. Below steps are tested for Ubuntu 16.04 and 18.04 (both 64-bit).

OpenCV-Python can be installed in Ubuntu in two ways:

  • Install from pre-built binaries available in Ubuntu repositories
  • Compile from the source. In this section, we will see both.

Another important thing is the additional libraries required. OpenCV-Python requires only Numpy (in addition to other dependencies, which we will see later). But in this tutorials, we also use Matplotlib for some easy and nice plotting purposes (which I feel much better compared to OpenCV). Matplotlib is optional, but highly recommended. Similarly we will also see IPython, an Interactive Python Terminal, which is also highly recommended.

Installing OpenCV-Python from Pre-built Binaries

This method serves best when using just for programming and developing OpenCV applications.

Install package python3-opencv with following command in terminal (as root user).

Open Python IDLE (or IPython) and type following codes in Python terminal.

If the results are printed out without any errors, congratulations . You have installed OpenCV-Python successfully.

It is quite easy. But there is a problem with this. Apt repositories may not contain the latest version of OpenCV always. For example, at the time of writing this tutorial, apt repository contains 2.4.8 while latest OpenCV version is 3.x. With respect to Python API, latest version will always contain much better support and latest bug fixes.

So for getting latest source codes preference is next method, i.e. compiling from source. Also at some point in time, if you want to contribute to OpenCV, you will need this.

Building OpenCV from source

Compiling from source may seem a little complicated at first, but once you succeeded in it, there is nothing complicated.

First we will install some dependencies. Some are required, some are optional. You can skip optional dependencies if you don’t want.

Required build dependencies

We need CMake to configure the installation, GCC for compilation, Python-devel and Numpy for building Python bindings etc.

Источник

Opencv with python linux

In this tutorial We will learn to setup OpenCV-Python in Ubuntu System. Below steps are tested for Ubuntu 16.04 and 18.04 (both 64-bit).

OpenCV-Python can be installed in Ubuntu in two ways:

  • Install from pre-built binaries available in Ubuntu repositories
  • Compile from the source. In this section, we will see both.

Another important thing is the additional libraries required. OpenCV-Python requires only Numpy (in addition to other dependencies, which we will see later). But in this tutorials, we also use Matplotlib for some easy and nice plotting purposes (which I feel much better compared to OpenCV). Matplotlib is optional, but highly recommended. Similarly we will also see IPython, an Interactive Python Terminal, which is also highly recommended.

Installing OpenCV-Python from Pre-built Binaries

This method serves best when using just for programming and developing OpenCV applications.

Install package python3-opencv with following command in terminal (as root user).

Open Python IDLE (or IPython) and type following codes in Python terminal.

If the results are printed out without any errors, congratulations . You have installed OpenCV-Python successfully.

It is quite easy. But there is a problem with this. Apt repositories may not contain the latest version of OpenCV always. For example, at the time of writing this tutorial, apt repository contains 2.4.8 while latest OpenCV version is 3.x. With respect to Python API, latest version will always contain much better support and latest bug fixes.

So for getting latest source codes preference is next method, i.e. compiling from source. Also at some point in time, if you want to contribute to OpenCV, you will need this.

Building OpenCV from source

Compiling from source may seem a little complicated at first, but once you succeeded in it, there is nothing complicated.

First we will install some dependencies. Some are required, some are optional. You can skip optional dependencies if you don’t want.

Required build dependencies

We need CMake to configure the installation, GCC for compilation, Python-devel and Numpy for building Python bindings etc.

Источник

How to Install OpenCV for Python in Linux?

Prerequisite: Python Language Introduction OpenCV is the huge open-source library for computer vision, machine learning, and image processing and now it plays a major role in real-time operation which is very important in today’s systems. By using it, one can process images and videos to identify objects, faces, or even the handwriting of a human. When it integrated with various libraries, such as Numpy, python is capable of processing the OpenCV array structure for analysis. To Identify image patterns and its various features we use vector space and perform mathematical operations on these features. To install OpenCV, one must have Python and PIP, preinstalled on their system. To check if your system already contains Python, go through the following instructions: Open the terminal using Ctrl+Alt+T Now run the following command: For Python2

For Python3.x

If Python is already installed, it will generate a message with the Python version available. If Python is not present, go through How to install Python on Linux? and follow the instructions provided. PIP is a package management system used to install and manage software packages/libraries written in Python. These files are stored in a large “on-line repository” termed as Python Package Index (PyPI). To check if PIP is already installed on your system, just go to the terminal and execute the following command:

If PIP is not present, go through How to install PIP on Linux? and follow the instructions provided.

Downloading and Installing OpenCV:

OpenCV can be directly downloaded and installed with the use of pip (package manager). To install OpenCV, just go to the terminal and type the following command:

pip3 install opencv-python

Beginning with the installation:

  • Type the command in the Terminal and proceed:
  • Collecting Information and downloading data:
  • Installing Packages:
  • Finished Installation:

To check if OpenCV is correctly installed, just run the following commands to perform a version check:

python3 >>>import cv2 >>>print(cv2.__version__)

Источник

Оцените статью