Computer Vision
Computer Vision
OpenCV + Python
OpenCV
Set of Libraries for commonly used computer
vision algorithms(computer vision module)
Like using header files in C++
Eg.
Convert to grayscale
Split image into R, G, B
Edge Detection
Finding contours
Face Detection
Note:
Lines are not parallel
Sides are not equal
Edges change based
on viewing angle
Video
Image
Simple
functions
More
Processing
Low
Resolution
High
resolution
Fast
Slow
Specialized
General
Real Time
Trade Offs
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
Import OpenCV
loop
while(True):
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame', gray)
if cv2.waitKey(1)==27:
break
loop
Implementation
Do the processing
loop
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
gray_old = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
while(True):
ret, frame = cap.read()
gray_new = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
img_diff = cv2.absdiff(gray_new,gray_old)
cv2.imshow('Result',img_diff)
gray_new = gray_old
if cv2.waitKey(1)==27:
break
cap.release()
cv2.destroyAllWindows()
In the above program, we have just shown the difference, and it is easier for a human to find the motion.
However, the computer still is not judging(understanding) if motion has occurred.
Therefore, we have used image processing, but not computer vision.
To do so, we must impose a judgment on the resultant image, i.e. img_diff
loop
import numpy as np
import cv2
cap = cv2.VideoCapture(1)
ret, frame = cap.read()
g_old = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
h,w = g_old.shape
imgt1 = cv2.resize(g_old,(w/5,h/5), interpolation = cv2.INTER_AREA)
while(True):
ret, frame = cap.read()
g_new = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
imgt2 = cv2.resize(g_new,(w/5,h/5), interpolation = v2.INTER_AREA)
img_diff = cv2.absdiff(imgt2,imgt1)
cv2.imshow('Result',img_diff)
if cv2.countNonZero(imgt_diff) > 2000:
print yo whats up
gray_new = gray_old
if cv2.waitKey(1)==27:
break
cap.release()
cv2.destroyAllWindows()
Extra Links
OpenCV + Python Tutorials
http://docs.opencv.org/trunk/doc/py_tutorials/py_tutorials.html
https://opencv-pythontutroals.readthedocs.org/en/latest/py_tutorials/py_tutorials.html
OpenCV Documentation
http://docs.opencv.org/trunk/modules/refman.html
Gestalt Principles
http://www.smashingmagazine.com/2014/03/28/design-principles-visual-perceptionand-the-principles-of-gestalt/