Programming/openCV2019. 5. 10. 19:17

 

 

import cv2

 

dirname = '/home/user/.local/lib/python3.6/site-packages/cv2/data/'

 

face_cascade = cv2.CascadeClassifier(dirname + 'haarcascade_frontalface_default.xml')

eye_cascade = cv2.CascadeClassifier(dirname + 'haarcascade_eye.xml')

 

cam = cv2.VideoCapture(0)

cam.set(3, 160) # CV_CAP_PROP_FRAME_WIDTH

cam.set(4, 120) # CV_CAP_PROP_FRAME_HEIGHT

cam.set(5, 60) # CV_CAP_PROP_FPS

print(cam.get(3))

print(cam.get(4))

print(cam.get(5))

 

while True:

ret_val, img = cam.read()

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

 

faces = face_cascade.detectMultiScale(gray, 1.3, 5)

print(faces)

for (x, y, w, h) in faces:

img = cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)

roi_gray = gray[y:y+h, x:x+w]

roi_color = img[y:y+h, x:x+w]

eyes = eye_cascade.detectMultiScale(roi_gray)

for (ex, ey, ew, eh) in eyes:

cv2.rectangle(roi_color, (ex, ey), (ex+ew, ey+eh), (0, 255, 0), 2)

 

cv2.imshow("Cam Viewer", img)

cv2.imshow("Cam Viewer gray", gray)

if cv2.waitKey(1) == 27:

break

 

[링크 : https://opencv-python-tutroals.readthedocs.io/.../py_face_detection/py_face_detection.html]

[링크 : https://stackoverflow.com/questions/30508922/error-215-empty-in-function-detectmultiscale]

'Programming > openCV' 카테고리의 다른 글

virtual mouse  (0) 2022.01.25
opencv-3.4.0 어플리케이션 빌드  (0) 2021.01.14
vscode python3 opencv lint  (0) 2019.05.10
opencv cannyedge  (0) 2019.01.16
opencv 원 추정  (0) 2019.01.16
Posted by 구차니