1
$\begingroup$
import cv2

videoCam = cv2.VideoCapture(0)

face = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye = cv2.CascadeClassifier('haarcascade_eye.xml')
nose = cv2.CascadeClassifier('haarcascade_mcs_nose.xml')
mouth = cv2.CascadeClassifier('haarcascade_mcs_mouth.xml')

while True:
    cond, frame = videoCam.read()
    frame = cv2.resize(frame, (154, 154))

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    muka = face.detectMultiScale(gray, 1.3, 5)
    for (x,y,w,h) in muka:
        cv2.rectangle(gray, (x,y), (x+w, y+h), (0, 255, 0), 5)

        roi_warna = frame[y:y+h, x:x+w]
        roi_gray = gray[y:y+h, x:x+w]
        mata = eye.detectMultiScale(roi_gray)
        nose = nose.detectMultiScale(roi_gray)
        mouth = mouth.detectMultiScale(roi_gray)
        for (mx,my,mw,mh)in mata:
            cv2.rectangle(roi_warna, (mx,my), (mx+mw, my+mh), (255,255,0), 2)
        for (nx, ny, nw, nh)in nose:
            cv2.rectangle(roi_warna, (nx, ny), (nx + nw, ny + nh), (0, 0, 255), 2)
        for (bx, by, bw, bh)in mouth:
            cv2.rectangle(roi_warna,(bx,by),(bx+bw,by+bh),(0,0,0),2)

    cv2.imshow('Face dan Eye detection', frame)


    k = cv2.waitKey(1) & 0xff
    if k == ord('q'):
        break

videoCam.release()
cv2.destroyAllWindows()
$\endgroup$
3
  • $\begingroup$ Please fix the format and expand more on what you intend to do with this code and if possible add an example of the file you are working with. $\endgroup$
    – wacax
    Dec 25, 2018 at 15:04
  • $\begingroup$ Which line causes the error? $\endgroup$ Apr 3, 2020 at 19:50
  • $\begingroup$ Thanks the error has solved been solved :) $\endgroup$ May 20, 2020 at 5:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.