[BangPypers] about code
narayan naik
narayannaik.05 at gmail.com
Mon Dec 15 07:21:39 CET 2014
Hi,
import cv2
def detect(path):
img = cv2.imread(path)
cascade = cv2.CascadeClassifier("haarcascade_frontalface_alt.xml")
rects = cascade.detectMultiScale(img, 1.3, 4,
cv2.cv.CV_HAAR_SCALE_IMAGE, (20,20))
if len(rects) == 0:
return [], img
rects[:, 2:] += rects[:, :2]
return rects, img
def box(rects, img):
for x1, y1, x2, y2 in rects:
cv2.rectangle(img, (x1, y1), (x2, y2), (127, 255, 0), 2)
rects, img = detect("hi.jpg")
cropped = img[70:17, 40:40]
cv2.imshow("cropped", cropped)
cv2.waitKey(0)
box(rects, img)
cv2.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
This is a face detection code.This will work properly.but I want to crop
the detected faces and it should display on the screen.
More information about the BangPypers
mailing list