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()