2

I'm trying to get a message when my face's center goes into a ROI, is it possible to detect? or it doesnt work that way? (I just started with openCV)

This is my code:

import cv2
import sys
import numpy as np

cascPath = 'haarcascade_frontalface_default.xml'
faceCascade = cv2.CascadeClassifier(cascPath)
video_capture = cv2.VideoCapture(0)

while True:
    ret, frame = video_capture.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    roiLeft = frame[0:0, 200:480]
    roiRight = frame[640:0, 440:480]
    faces = faceCascade.detectMultiScale(
        gray,
        scaleFactor=1.2,
        minNeighbors=1,
        minSize=(120, 120),
        flags=cv2.cv.CV_HAAR_SCALE_IMAGE
    )

    for (x, y, w, h) in faces:
        centerFrame = x+w/2,y+h/2
        cv2.circle(frame,(x+w/2,y+h/2),10,(0,0,255),-1)
        cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
        if centerFrame in frame[640:0, 440:480]:
            print("OOOOOOOOHHHHHHHH")

    cv2.imshow('Video', frame)

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

video_capture.release()
cv2.destroyAllWindows()
lelp89
  • 21
  • 1
  • 3

1 Answers1

3

One possible solution(approach) is :

1 : Determine average min & max HSV values of your face color. 2 : Threshold ROI part with cv2.inRange(hsv, COLOR_MIN, COLOR_MAX) value.

3 : If image contains values of HSV in between defined HSV values , that part of image will be white otherwise black

Like this : red ball area = white

4 : Find contour area , as you said you want your face to be recoginise so i think area should be atleast 8000 or more , if contour area is equal or maximum then it is your face else not .

Read this blog , Global Threholding part , extracting pink color.

udit043
  • 1,610
  • 3
  • 22
  • 40