Skip to content

rajadavidh/learning-opencv-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Learning OpenCV in Python

This repo contains my personal notes and resources about learning OpenCV in Python programming language

Contents

Code Examples

These examples using OpenCV 3 from Python 2.7

Credit

Thanks to Harrison Kinsley for his tutorials, OpenCV with Python Intro and loading Images.

If you are looking for the complete explanation, you can find it here.

Reading resources

Open CV Tutorial and Documentation

Further reading

Websites related to OpenCV for Python

Run command

  • Open terminal
  • Go to each file and run this:
    python2 filename.py

System setup and Troubleshooting

Setup for Mac OSX

Install Xcode

Open terminal and type:

xcode-select --install

Install HomeBrew

Type on terminal:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

To confirm Homebrew installed correctly, run this command:

$ brew doctor
Your system is ready to brew.

Install Python 2 and Python 3

brew update
brew install python   # for installing python3
brew install python2  # for installing python2
brew link python      # creates symlinks to python3 installation in Cellar
brew link python@2    # creates symlinks to python2 installation in Cellar

Check whether Python using homebrew install correctly:

which python2  # it should output /usr/local/bin/python2
which python3  # it should output /usr/local/bin/python3

Check Python versions:

python2 --version  # it should output Python 2.7.15
python3 --version  # it should output Python 3.7.0

Install OpenCV 3

Tap to repo:

brew tap brewsci/bio  # previous repo: homebrew/science

Below command produced error on my machine:

brew install opencv3 --with-contrib --with-python3 --HEAD  # "Error: No head is defined for opencv"

This command worked on my machine:

brew install opencv3 --with-contrib --with-python3

Verifying that OpenCV 3 has been installed:

python
>>> import cv2
>>> cv2.__version__
'3.4.2'

python3
>>> import cv2
>>> cv2.__version__
'3.4.2'

Running code sample after installation:

python test_webcam.py

Troubleshooting OpenCV 3 installation

If found error after import cv2 like:

RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: numpy.core.multiarray failed to import

We can solve it by updating numpy installation:

pip install -U numpy   # for python2
pip3 install -U numpy  # for python3

References:

Install OpenCV 4 (Update: January 2019)

OpenCV 4 was released on November 20th, 2018

Install supporting libraries

brew install cmake pkg-config
brew install jpeg libpng libtiff openexr
brew install eigen tbb

(TODO)

References:

Setup for Ubuntu

Install Python

(TODO)

Install OpenCV

(TODO)

About

Code examples for learning OpenCV in python

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages