This repo contains my personal notes and resources about learning OpenCV in Python programming language
- Code Examples
- Reading resources
- Websites related to OpenCV for Python
- Run command
- System setup and Troubleshooting
- GUI Lesson: PyQt5
These examples using OpenCV 3 from Python 2.7
- Loading Image
- Loading Video Source
- Drawing and Writing on image
- Image Operations
- Image Arithmetics
- Thresholding
- Color filtering
- Blurring and Smoothing
- Morphological Transformations
- Canny Edge Detection and Gradients
- Template Matching
- GrabCut Foreground Extraction
- Corner Detection
- Feature Matching (Homography) Brute force
- MOG background reduction
- Haar Cascade Object Detection Face & Eye
- Creating your own Haar Cascade
- Intro Custom Haar Cascade
- Gathering image for Haar Cascade
- Cleaning images and creating description files
- Training Haar Cascade object detection
- Haar Cascade for image and video object classification
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.
- Official master docs: https://docs.opencv.org/master/d6/d00/tutorial_py_root.html
- Unofficial docs: https://opencv-python-tutroals.readthedocs.io/en/latest/index.html
- All documentation: https://docs.opencv.org/
- Loading Image
- Loading Video Source
- Drawing and Writing on image
- Image Operations
- Image Arithmetics
- Thresholding
- Color filtering
- Blurring and Smoothing
- Morphological Transformations
- Canny Edge Detection and Gradients
- Template Matching
- GrabCut Foreground Extraction
- Corner Detection
- Feature Matching (Homography) Brute force
- MOG background reduction
- Haar Cascade Object Detection Face & Eye
- Creating your own Haar Cascade
- Open terminal
- Go to each file and run this:
python2 filename.py
Open terminal and type:
xcode-select --install
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.
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
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
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
- http://docs.python-guide.org/en/latest/starting/install/osx/
- https://www.codingforentrepreneurs.com/blog/install-opencv-3-for-python-on-mac/
- https://github.com/Homebrew/homebrew-science/issues/6617
- https://www.pyimagesearch.com/2016/12/19/install-opencv-3-on-macos-with-homebrew-the-easy-way/
- https://www.learnopencv.com/install-opencv3-on-macos/
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)
- https://www.learnopencv.com/install-opencv-4-on-macos/
- https://www.pyimagesearch.com/2018/08/17/install-opencv-4-on-macos/
(TODO)
(TODO)