openCV with Python David Hsu
Installations - windows • Python 2.7 or 3.5 https://www.python.org/downloads/ • Frequently used Libraries : Numpy, Matplotlib, Scipy http://www.scipy.org/ • Or try Anaconda (Python + popular libraries) https://www.continuum.io/downloads • openCV 3.0.0 http://opencv.org/downloads.html • Copy “cv2.pyd” from pathopencvbuildpython2.7x86(x64) Paste “cv2.pyd” to pathAnacondaLibsite-packages In python shell : import cv2 cv2.__version__ (two underscores) ‘3.0.0’
Installations - mac • Python 2.7 or 3.5 or Anaconda https://www.python.org/downloads/ https://www.continuum.io/downloads • Frequently used Libraries : Numpy, Matplotlib, Scipy in Terminals : pip install –U numpy scipy matplotlib (for Python 2.X) pip3 install –U numpy scipy matplotlib (for Python 3.X) • Download openCV http://opencv.org/downloads.html • Install Xcode https://developer.apple.com/xcode/ • Install Cmake https://cmake.org/download/ • Build openCV for Python http://luigolas.com/blog/2014/09/15/install-opencv3-with- python-3-mac-osx/
Ex1: read/show images • Put the image (lena.bmp) and cv_ex1.py in the same folder •
Ex1: read/show images •
Ex2: open videos • Put the video (test.mp4) and cv_ex2.py in the same folder •
Ex2: open videos •
Ex3: using webCam • Very similar to video open, just change the argument to be 0 •
Ex4: edges detection • Adopt “canny” method to achieve edges detection •
Ex4: edges detection •
Ex5: lines detection • Lines detection using Hough Transform  line equation using (r, thita) •
Ex5: lines detection •
Ex6: object tracking using color filtering • using color as features : quick and dirty • Detecting something in blue
• Ex6: object tracking using color filtering
Ex7: contours classification • blue objects detextion  shapes recognition • Rectangle  shown in green • multiple-sides-polygon (like circles)  shown in red
Ex7: contours classification •
Lightening condition invariant? • Color looks different with lightening issue.
Finding corners’ features • Color invariant, Scale invariant
Finding corners’ features • Color invariant, Scale invariant
Features matching • features matching with two images
• Features method : ORB (Oriented FAST and Rotated BRIEF) • Matching method : BruteForceMatcher • Ex8: object tracking using corners’ features
• Ex8: object tracking using corners’ features
Ex9: Face recognition/tracking • Download the training model (haarcascade_frontalface_default.xml') and put it in the same folder with the code cv_ex9.py. •
Ex9: Face recognition/tracking •
References • You can access the example from https://github.com/ntudavid/CV_lab • Reference : OpenCV – Python Tutorials https://opencv-python-tutroals.readthedocs.org/en/latest/

openCV with python