Compare commits
2 Commits
478b5bb6e6
...
afe0de3109
Author | SHA1 | Date |
---|---|---|
Alexander Popov | afe0de3109 | |
Alexander Popov | aafe177204 |
|
@ -0,0 +1,2 @@
|
|||
*.png
|
||||
haarcascade_*.xml
|
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import cv2
|
||||
|
||||
cam_port = 2
|
||||
cam = cv2.VideoCapture(cam_port)
|
||||
|
||||
while True:
|
||||
result, image = cam.read()
|
||||
|
||||
cv2.imshow('Camera', image)
|
||||
|
||||
if cv2.waitKey(1) & 0xFF == ord('s'):
|
||||
cv2.imwrite('capture.png', image)
|
||||
|
||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||
break
|
||||
|
||||
cam.release()
|
||||
cv2.destroyWindow('Camera')
|
||||
cv2.destroyAllWindows()
|
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import cv2
|
||||
|
||||
|
||||
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)
|
||||
)
|
||||
|
||||
for x, y, w, h in faces:
|
||||
cv2.rectangle(capture, (x, y), (x + w, y + h), (0, 255, 0), 2)
|
||||
|
||||
return faces
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
camera = cv2.VideoCapture(2)
|
||||
face_classifier = cv2.CascadeClassifier(
|
||||
cv2.data.haarcascades + 'haarcascade_frontalface_default.xml'
|
||||
)
|
||||
|
||||
while True:
|
||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||
break
|
||||
|
||||
result, image = camera.read()
|
||||
|
||||
faces = face_detect(image)
|
||||
cv2.imshow('Face Realtime Detector', image)
|
||||
|
||||
camera.release()
|
||||
cv2.destroyAllWindows()
|
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import cv2
|
||||
|
||||
img = cv2.imread('face.png')
|
||||
|
||||
gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
||||
|
||||
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)
|
||||
)
|
||||
|
||||
for x, y, w, h in face:
|
||||
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
|
||||
|
||||
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
||||
|
||||
cv2.imshow('Face Detector', img_rgb)
|
||||
cv2.waitKey(0)
|
||||
cv2.destroyAllWindows()
|
|
@ -0,0 +1,7 @@
|
|||
import cv2
|
||||
|
||||
img = cv2.imread('image.png')
|
||||
|
||||
cv2.imshow('Images from Files', img)
|
||||
cv2.waitKey(0)
|
||||
cv2.destroyAllWindows()
|
|
@ -0,0 +1,4 @@
|
|||
[tool.black]
|
||||
skip-string-normalization = true
|
||||
pycodestyle = true
|
||||
line-length = 100
|
|
@ -0,0 +1,2 @@
|
|||
numpy==1.25.2
|
||||
opencv-python==4.8.0.76
|
Loading…
Reference in New Issue