Object Recognition Web API Using OpenCV
OpenCV for Image Processing
Stands for Open Computer Vison is , started by Intel Russia research center for advanced Image Processing Stuff.
Open Source Scripting language for varied implementation
XML is scripting language to represent Meta-Data, used for cascade classifier.
Web Framework's for Web API handling. To serve as an endpoint for various Image Service Calls, it returns coordinates of Recognised Images.
Use of C++ as library in order to train Cascade Classifier
Sample Applications:
Face and eye detection using haar cascade eye and frontalface classifier
Code Implemented
import cv
imcolor = cv.LoadImage('detectionimg.jpg') # input image
# loading the classifiers
haarFace = cv.Load('haarcascade_frontalface_default.xml')
haarEyes = cv.Load('haarcascade_eye.xml')
# running the classifiers
storage = cv.CreateMemStorage()
detectedFace = cv.HaarDetectObjects(imcolor, haarFace, storage)
detectedEyes = cv.HaarDetectObjects(imcolor, haarEyes, storage)
# draw a green rectangle where the face is detected
if detectedFace:
for face in detectedFace:
cv.Rectangle(imcolor,(face[0][0],face[0][1]),
(face[0][0]+face[0][2],face[0][1]+face[0][3]),
cv.RGB(155, 255, 25),2)
# draw a purple rectangle where the eye is detected
if detectedEyes:
for face in detectedEyes:
cv.Rectangle(imcolor,(face[0][0],face[0][1]),
(face[0][0]+face[0][2],face[0][1]+face[0][3]),
cv.RGB(155, 55, 200),2)
print imcolor
cv.NamedWindow('Face Detection', cv.CV_WINDOW_AUTOSIZE)
cv.ShowImage('Face Detection', imcolor)
#cv.WaitKey()
cv.WaitKey(0)
Output
Hand detection using haar cascade hand classifier
Code Implemented
import cv2
import sys
# Get user supplied values
imagePath = sys.argv[1]
cascPath = sys.argv[2]
# Create the haar cascade
faceCascade = cv2.CascadeClassifier(cascPath)
# Read the image
image = cv2.imread(imagePath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Detect faces in the image
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=50,
minSize=(300, 300),
flags = cv2.cv.CV_HAAR_SCALE_IMAGE
)
print "Hands {0} faces!".format(len(faces))
# Draw a rectangle around the faces
for (x, y, w, h) in faces:
cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
cv2.imshow("Hands found", image)
cv2.waitKey(0)
OUTPUT
Car detection using haar cascade car classifier
Code Implemented
import numpy as np
import cv2
# Loads the data as a VideoCapture format, which is really just
# an image sequence.
image_sequence = 'Data/Camera3/image_%05d.jpg'
cap = cv2.VideoCapture(image_sequence)
# Load our cascade classifier from cars3.xml
car_cascade = cv2.CascadeClassifier(r'cars3.xml')
# Reduce frame number of tests.
number_of_frames_to_load = 30
for frame_id in xrange(number_of_frames_to_load):
ret, image = cap.read()
# Crop so that only the roads remain, eliminatives the distraction.
image = image[120:,:-20]
# Use Cascade Classifier to detect cars, may have to tune the
# parameters for less false positives.
cars = car_cascade.detectMultiScale(image, 1.008, 5)
for (x,y,w,h) in cars:
cv2.rectangle(image,(x,y),(x+w,y+h),(255,0,0),2)
print 'Processing %d : cars detected : [%s]' % (frame_id, len(cars))
cv2.imshow('frame', image)
cv2.waitKey(300)
cap.release()
cv2.destroyAllWindows()
OUTPUT
Cascade-Classifier:
Thank You