realtime face detect
This commit is contained in:
parent
aafe177204
commit
afe0de3109
2
snipplets/code/Python/opencv/.gitignore
vendored
2
snipplets/code/Python/opencv/.gitignore
vendored
@ -1,2 +1,2 @@
|
||||
*.png
|
||||
haarcascade_frontalface_default.xml
|
||||
haarcascade_*.xml
|
||||
|
@ -2,28 +2,33 @@
|
||||
|
||||
import cv2
|
||||
|
||||
camera = cv2.VideoCapture(2)
|
||||
|
||||
while True:
|
||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||
break
|
||||
def face_detect(capture):
|
||||
gray_image = cv2.cvtColor(capture, cv2.COLOR_BGR2GRAY)
|
||||
faces = face_classifier.detectMultiScale(
|
||||
gray_image, scaleFactor=1.1, minNeighbors=5, minSize=(40, 40)
|
||||
)
|
||||
|
||||
result, image = camera.read()
|
||||
for x, y, w, h in faces:
|
||||
cv2.rectangle(capture, (x, y), (x + w, y + h), (0, 255, 0), 2)
|
||||
|
||||
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
||||
return faces
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
camera = cv2.VideoCapture(2)
|
||||
face_classifier = cv2.CascadeClassifier(
|
||||
cv2.data.haarcascades + 'haarcascade_frontalface_default.xml'
|
||||
)
|
||||
|
||||
face = face_classifier.detectMultiScale(
|
||||
gray_image, scaleFactor=1.1, minNeighbors=5, minSize=(40, 40)
|
||||
)
|
||||
while True:
|
||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||
break
|
||||
|
||||
for x, y, w, h in face:
|
||||
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)
|
||||
result, image = camera.read()
|
||||
|
||||
cv2.imshow('Face Realtime Detector', image)
|
||||
faces = face_detect(image)
|
||||
cv2.imshow('Face Realtime Detector', image)
|
||||
|
||||
camera.release()
|
||||
cv2.destroyAllWindows()
|
||||
camera.release()
|
||||
cv2.destroyAllWindows()
|
||||
|
Loading…
Reference in New Issue
Block a user