python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.2.0'
python3-opencv can be installed from the Universe repository in Ubuntu 17.10 and later. Open the terminal and type:
sudo apt install python3-opencv
Upgrade your OS to 18.04 if you are using Ubuntu 14.04 or Ubuntu 16.04. If Ubuntu 16.04 is installed in WSL sudo do-release-upgrade will upgrade it to 18.04.
Install the developer packages for Python3.5: sudo apt-get install python3.5-dev
Copy the dev files:python3.5-config --includes The output should be similar to: -I/usr/include/python3.5m -I/usr/include/x86_64-linux-gnu/python3.5m. The first part of the output is the expected location & the second part shows the current location of the config file. To solve this problem, we’ll copy the file from the current location to the expected location: sudo cp /usr/include/x86_64-linux-gnu/python3.5m/pyconfig.h /usr/include/python3.5m/
Create a temporary directory, move into it and run: git clone https://github.com/Itseez/opencv.git. This will download OpenCV 3. Then rename the folder opencv to opencv-3
The most simple and elegant way I found online is to install the library by running an installation script. Download the installation script install-opencv.sh, open your terminal and execute:
bash install-opencv.sh
Type your sudo password and you will have installed OpenCV. This operation may take a long time due to the packages to be installed and the compilation process.
I am currently working with Google VM (ubuntu 14.04). Installing opencv on python3.4 version has been quite a task. I wanted opencv to be installed for python 3.4 but every time it was getting installed on 2.7 version.
I will share the steps I followed so as to help others on it.
Step 1 Follow all the steps as mentioned on openCv installation part till cmake. Link is given below:
Note: Install all the 3 packages mentioned at start. That optional one too..!! And don't forget to change the python version for which you are installing.
Step 2 For installing opencv in specific version of python (ubuntu), you have to set the default (PYTHON_DEFAULT_EXECUTABLE) with the path to where your python is installed. You can find that out by using command whereis python3.4 (or, your version). Mine was in /usr/bin/python3.4
The following, tested on Ubuntu 18.04, installs OpenCV 4.1.0-dev and does not use python virtual environment. I haven't figured out how they work yet. I put the answer here so it has wider visibility.
OpenCV can be installed using pip/pip3 and homebrew. I've tried installing it before using pip3 (Python 3.6.0), but i had problems with VideoCapture, which requires the ffmpeg package. cv2.VideoCapture('videofilename'). This is why I used homebrew for installing OpenCV. Open a Terminal with Ctrl + Alt + T and type the following commands:
I found this.
OpenCV on wheels.
Installation was painless for Ubuntu 16.04:
Check the installation:
python3-opencv can be installed from the Universe repository in Ubuntu 17.10 and later. Open the terminal and type:
Upgrade your OS to 18.04 if you are using Ubuntu 14.04 or Ubuntu 16.04. If Ubuntu 16.04 is installed in WSL
sudo do-release-upgrade
will upgrade it to 18.04.I have OpenCV version 3.1 on Ubuntu 16.04 LTS to work with Python 3.5.1. At the latest version it's fixed, try:
http://cyaninfinite.com/tutorials/installing-opencv-in-ubuntu-for-python-3/
But I didn't download dev python and OpenCV, I took directly from github:
EDIT:
Here are the instructions I tested successfully and mentioned in the link above:
sudo apt-get update
Download the required packages to compile OpenCV:
sudo apt-get install python3.5-dev
python3.5-config --includes
The output should be similar to:-I/usr/include/python3.5m -I/usr/include/x86_64-linux-gnu/python3.5m
. The first part of the output is the expected location & the second part shows the current location of the config file. To solve this problem, we’ll copy the file from the current location to the expected location:sudo cp /usr/include/x86_64-linux-gnu/python3.5m/pyconfig.h /usr/include/python3.5m/
git clone https://github.com/Itseez/opencv.git
. This will download OpenCV 3. Then rename the folderopencv
toopencv-3
Create a
build
directory, move to it and run:make
and thensudo make install
.The most simple and elegant way I found online is to install the library by running an installation script. Download the installation script
install-opencv.sh
, open your terminal and execute:Type your sudo password and you will have installed OpenCV. This operation may take a long time due to the packages to be installed and the compilation process.
The reference: https://milq.github.io/install-opencv-ubuntu-debian/
I am currently working with Google VM (ubuntu 14.04). Installing opencv on python3.4 version has been quite a task. I wanted opencv to be installed for python 3.4 but every time it was getting installed on 2.7 version.
I will share the steps I followed so as to help others on it.
Step 1 Follow all the steps as mentioned on openCv installation part till cmake. Link is given below:
https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html
Note: Install all the 3 packages mentioned at start. That optional one too..!! And don't forget to change the python version for which you are installing.
I did
Follow step 2 for
cmake
.Step 2 For installing opencv in specific version of python (ubuntu), you have to set the default (PYTHON_DEFAULT_EXECUTABLE) with the path to where your python is installed. You can find that out by using command whereis python3.4 (or, your version). Mine was in
/usr/bin/python3.4
Instead of cmake mentioned on the page, use this,
Note: Don't forget to change your python version and path in PYTHON_DEFAULT_EXECUTABLE.
Step 3 Follow the remaining steps as mentioned in the link till sudo make install
Hope it helps.
Base guide: https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html
The following, tested on Ubuntu 18.04, installs OpenCV 4.1.0-dev and does not use python virtual environment. I haven't figured out how they work yet. I put the answer here so it has wider visibility.
Requirements
How to install jasper: https://github.com/opencv/opencv/issues/8622#issuecomment-353761271
1. Clone repos
The installation will include contrib modules.
(Git branch to 3.4 to install that version.)
1.1 Make build folder
If you mess up, just delete build folder and start over from here.
2. Configuring
I use the following cmake flags:
Optional flags: (there are a lot of flags, see this blog post for some useful ones)
Ensure cmake finds your python version by checking its output for the following:
How to specify which python versions to use
3. Make and install
Use make with the desired number of threads (ex. number of processors) then install.
Things should now install to
/usr/local
4. Test
If all went well then you should be able to import cv2 in python.
OpenCV can be installed using pip/pip3 and homebrew. I've tried installing it before using pip3 (Python 3.6.0), but i had problems with VideoCapture, which requires the ffmpeg package. cv2.VideoCapture('videofilename'). This is why I used homebrew for installing OpenCV. Open a Terminal with Ctrl + Alt + T and type the following commands: