【智控万物】晃头控灯
本帖最后由 云天 于 2021-6-22 18:19 编辑【MediaPipe 人脸检测】
MediaPipe 人脸检测是一种超快的人脸检测解决方案,具有 6 个地标和多人脸支持。它基于BlazeFace,这是一种轻量级且性能良好的人脸检测器,专为移动 GPU 推理量身定制。检测器的超实时性能使其能够应用于任何需要准确的面部感兴趣区域作为其他任务特定模型输入的实时取景器体验,例如 3D 面部关键点或几何估计(例如MediaPipe Face Mesh),面部特征或表情分类,以及面部区域分割。BlazeFace 使用了一个轻量级的特征提取网络,其灵感来自于MobileNetV1/V2,但与MobileNetV1/V2不同,后者是一种 GPU 友好的锚点方案,修改自Single Shot MultiBox Detector (SSD),以及替代非极大值抑制的改进平局分辨率策略。
检测到的人脸的集合,其中每个人脸都表示为一个检测原始消息,其中包含一个边界框和 6 个关键点(右眼、左眼、鼻尖、嘴巴中心、右耳和左耳)。边界框由xmin和width(均由图像宽度归一化)和ymin和height(均由图像高度归一化)组成。每个关键点由x和组成y,分别由图像宽度和高度归一化。
【程序代码】通过左右眼纵坐标的差来判断头向左歪还是向右歪
import cv2
import mediapipe as mp
from pinpong.board import Board,Pin,NeoPixel
NEOPIXEL_PIN = Pin.D7
PIXELS_NUM = 7 #灯数
Board("uno").begin()#初始化,选择板型和端口号,不输入端口号则进行自动识别
np = NeoPixel(Pin(NEOPIXEL_PIN), PIXELS_NUM)
mp_face_detection = mp.solutions.face_detection
mp_drawing = mp.solutions.drawing_utils
# For webcam input:
cap = cv2.VideoCapture(0)
Width=cap.get(3)
Height=cap.get(4)
with mp_face_detection.FaceDetection(
min_detection_confidence=0.5) as face_detection:
while cap.isOpened():
success, image = cap.read()
if not success:
print("Ignoring empty camera frame.")
# If loading a video, use 'break' instead of 'continue'.
continue
# Flip the image horizontally for a later selfie-view display, and convert
# the BGR image to RGB.
image = cv2.cvtColor(cv2.flip(image, 1), cv2.COLOR_BGR2RGB)
# To improve performance, optionally mark the image as not writeable to
# pass by reference.
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)
#计算左右眼坐标位置
RIGHT_EYE=mp_face_detection.get_key_point(detection, mp_face_detection.FaceKeyPoint.RIGHT_EYE)
LEFT_EYE=mp_face_detection.get_key_point(detection, mp_face_detection.FaceKeyPoint.LEFT_EYE)
Rx=int(RIGHT_EYE.x*Width)
Ry=int(RIGHT_EYE.y*Height)
Lx=int(LEFT_EYE.x*Width)
Ly=int(LEFT_EYE.y*Height)
cv2.circle(image, (Lx,Ly), 8, (0, 255, 255), cv2.FILLED)
cv2.circle(image, (Rx,Ry), 8, (0, 255, 255), cv2.FILLED)【视频演示】https://v.youku.com/v_show/id_XNTE3MjUwMDk3Ng==.html
运行程序,窗口没有弹出,有以下提示,怎么原因?拜托
Opening COM26...
Waiting 4 seconds(arduino_wait) for Arduino devices to reset...
Arduino compatible device found and connected to COM26
Retrieving Arduino Firmware ID...
Arduino Firmware ID: 2.6 DFRobot firmata
Retrieving analog map...
Auto-discovery complete. Found 20 Digital Pins and 6 Analog Pins
------------------------------
All right. PinPong go...
------------------------------
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
>>> 上面都是正常运行显示的内容。没有出错显示!
页:
[1]