lezinterracial |
05-24-2024 11:46 PM |
Quote:
Originally Posted by 2MuchMark
(Post 23267156)
Try using Dlib’s face detector, MTCNN, or deep learning-based models such as OpenCV’s DNN module with pre-trained models (e.g., ResNet-based face detectors). Check scaleFactor and minNeighbors settings.
|
Yea, I have read about Dlib. I want to use on my laptop. You think it will run with real time video.
Thanks for all responses so far.
I used the example facedetect.py . Add a target box, when a face enters the box
moves a servo. Polulu Maestro servo controller.
Code:
import cv2
import os
import time
cmdpull = "/home/walter/maestro-linux/UscCmd --servo 5,7000"
cmdreturn = "/home/walter/maestro-linux/UscCmd --servo 5,6000"
# Load the cascade
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
# To capture video from webcam.
cap = cv2.VideoCapture(2)
# To use a video file as input
# cap = cv2.VideoCapture('filename.mp4')
while True:
# Read the frame
_, img = cap.read()
# Convert to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Detect the faces
faces = face_cascade.detectMultiScale(gray, 1.1, 4)
#create region of interest box and dot
cv2.rectangle(img, (100, 100), (180, 180), (0, 0, 255), 2)
cv2.line(img, (140, 140), (140, 140), (0, 255, 0), 5)
# Draw the rectangle around each face
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)
#if face is in middle of the screen - region of interest
if x > 100 and x < 180 and y > 100 and y < 180:
print ("x: ",x)
print ("y: ",y)
time.sleep(.1)
os.system(cmdpull)
time.sleep(.1)
os.system(cmdreturn)
# Display
cv2.imshow('img', img)
# Stop if escape key is pressed
k = cv2.waitKey(30) & 0xff
if k==27:
break
# Release the VideoCapture object
cap.release()
|