2

Hi can someone help me with writing an openCV function and return co-ordinates of face rectangle.

My current code looks like this but program hangs.

def WatchMe():
    while(video.isOpened()):
        ret, frame = video.read()
        if frame is not None:
            gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
            faces = face_cascade.detectMultiScale(gray, 1.3, 5)
            for (x,y,w,h) in faces:
                cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
                t =(x+w)/2
                v =(y+h)/2
                #cv2.circle(frame, (t,v), 1, (0,0,255), thickness=1, lineType=8, shift=0)
                #watchme(t,v)
                roi_gray = gray[y:y+h, x:x+w]
                roi_color = frame[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('Video', frame)
            time.sleep(3) # delays for 5 seconds
        #return t,v

     # part of original face code      
        #if cv2.waitKey(1) & 0xFF == ord('q'):
            #break

1 Answer 1

1

Function Definition-

def WatchMe2(frame):
                gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
                faces = face_cascade.detectMultiScale(gray, 1.3, 5)
                for (x,y,w,h) in faces:
                    cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
                    t =(x+w)/2
                    v =(y+h)/2                                      
                    roi_gray = gray[y:y+h, x:x+w]
                    roi_color = frame[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)

Function call-

while(video.isOpened()):
        ret, frame = video.read()
        if frame is not None:
           WatchMe2(frame)
           cv2.imshow('Video', frame)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.