Object Recognition Web API Using OpenCV
Need for Object Recognition arrived from our experience with building Multilingual Captcha System.
Need to Create Haar-Cascade Library
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
DigitalOcean
DigitalOcean is used as server hosting services for Casscade Classifier training
Project Development was started as a Matlab Project
Sample Applications:
Face detection using haar cascade face classifier
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 "Found {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("Faces found", image)
cv2.waitKey(0)
Code Implemented
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:
Trained 6 Haar Cascade Classifier namely of: Cars, Frontal Face,Human Eye, Human Hand, Wall Clock, Human Body.
Thank You