Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- import os
- face_dascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
- eye_dascade = cv2.CascadeClassifier('haarcascade_eye.xml')
- smile_dascade = cv2.CascadeClassifier('haarcascade_smile.xml')
- cap = cv2.VideoCapture(0)
- # temp = cv2.imread('dat.jpg',0)
- # temp_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
- a = 0
- while a != 1:
- ret, img = cap.read()
- hinh = np.copy(img)
- gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
- faces = face_dascade.detectMultiScale(gray, 1.3, 5)
- for (x,y,w,h) in faces:
- cv2.rectangle(img, (x,y), (x+w, y+h), (255,0,0), 2)
- face_gray = gray[y:y+h, x:x+h]
- face_color = img[y:y+h, x:x+h]
- smile = smile_dascade.detectMultiScale(face_gray, 1.3, 5)
- for (x2,y2,w2,h2) in smile:
- if((((h*1.0*w)/(w2*h2))<11) and len(smile)==len(faces)):
- cv2.rectangle(face_color, (x2,y2), (x2+w2, y2+h2), (150,0,0), 2)
- cv2.imwrite('hinh1.jpg',hinh)
- a = 1
- eyes = eye_dascade.detectMultiScale(face_gray)
- for (xe,ye,we,he) in eyes:
- cv2.rectangle(face_color, (xe,ye), (xe+we, ye+he), (0,0,255), 2)
- cv2.imshow('img',img)
- if cv2.waitKey(1) == 27:
- break
- cap.release()
- cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement