3 step detailed face detection
step 1:
This will be your easist way for face detection codes any queery drop your comment
.........................................................CODE PYTHON.............................................................................
import numpy as np
import cv2
import matplotlib. pyplot as plt
annie = cv2.imread ("animesh.jpg",0)
plt.imshow(annie,cmap="gray")
Output:
...................................................................................................................................................................
step 2:
Hear we can call trained data set and detect faces in image
.....................................................................................................................................................
import numpy as np
import cv2
import matplotlib. pyplot as plt
annie = cv2.imread ("animesh.jpg",0)
plt.imshow(annie, cmap ="gray")
#trained data set you can try various data set from github
face_trainset = cv2.CascadeClassifier('face_detection_indian.xml')
#function for face detection
def detect_face(img):
face_img = img.copy()
face_rect= face_trainset.detectMultiScale(face_img)
for(x,y,w,h) in face_rect:
cv2.rectangle(face_img,(x,y),(x+w,y+h),(0,0,165),10)
return face_img
#lets try now
img1= detect_face(annie)
plt.imshow(img1,cmap="gray")
Output:
......................................................................................................................................................................
step 3:
Hear we will add webcam or our front camera an take a real time image and detect face.
...................................................................................................................................................................
capture = cv2.VideoCapture(0)
while True:
ret,frame= capture.read()
frame = detect_face(frame)
cv2.imshow("video",frame)
# Display the resulting frame
c = cv2.waitKey(1)
if c == 27:
#27 is askey code for esc button
break
capture.release()
cv2.destroyAllWindows()
OUTPUT:
...................................................................................................................................................................


 
 
Comments
Post a Comment