【发布时间】:2023-01-28 02:56:30
【问题描述】:
我正在尝试使用此代码来获取x 和 y 坐标面部位置的实时。我从媒体管道解决方案在线的。 运行此代码时,实际上会检测到面部,并且其所有特征都在显示的框架上显示为红点。 我希望能够以整数形式获取面部坐标,以便稍后使用它们跟踪伺服电机的位置,有什么办法可以做到吗?
# face detection
import cv2
import mediapipe as mp
import time
mp_face_detection = mp.solutions.face_detection
mp_drawing = mp.solutions.drawing_utils
# capture video
cap = cv2.VideoCapture(2)
prevTime = 0
with mp_face_detection.FaceDetection( model_selection=1,
min_detection_confidence=0.65) as face_detection:
while True:
success, image = cap.read()
if not success:
print("Ignoring empty camera frame.")
break
#Convert the BGR image to RGB.
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image.flags.writeable = False
results = face_detection.process(image)
# Draw the face detection annotations on the image.
image.flags.writeable = True
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
if results.detections:
for detection in results.detections:
mp_drawing.draw_detection(image, detection)
print(detection) # I can get the score, x, y,..
cv2.imshow('BlazeFace Face Detection', image)
if cv2.waitKey(5) & 0xFF == 27:
break
cap.release()
我尝试在 for 循环中打印变量 persons,我可以清楚地看到其中有 x 和 y 坐标,但我未能提取这些特定信息。 关于如何更好地操纵这个变量的任何想法? 我将使用检测到的人脸数量、他们的位置坐标和置信度。
【问题讨论】:
标签: python opencv variables detection vision