我正在开发一个检测面孔和距离的程序,我想同时播放距离的音频信息
我有一个对象检测代码,其中我计算了从脸到相机的距离?我可以使用什么功能以及如何播放每2-3秒钟的音频?谢谢 以下是代码
import cv2
import cvzone
from cvzone.FaceMeshModule import FaceMeshDetector
import os
class Face:
window_name = "Detected Objects in webcam"
video = cv2.VideoCapture(0)
while video.isOpened():
ret, frame = video.read()
detector = FaceMeshDetector(maxFaces=3)
img, faces = detector.findFaceMesh(frame, draw=False)
if not ret:
break
image = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cascade_classifier = cv2.CascadeClassifier(
f"{cv2.data.haarcascades}haarcascade_frontalface_default.xml")
detected_objects = cascade_classifier.detectMultiScale(
image, minSize=(20, 20))
if len(detected_objects) != 0:
for (x, y, height, width) in detected_objects:
cv2.rectangle(
frame, (x, y), ((x + height), (y + width)), (0, 255, 0), 5
)
for face in faces:
r_point = face[374]
l_point = face[145]
point_width, _ = detector.findDistance(l_point, r_point)
width = 6.3
distance = (width * 600) / point_width
# text_to_speech(math.floor(distance))
dis = str(distance)
cvzone.putTextRect(
frame, f"Depth:{distance:.2f} cm", (face[10][0]-95, face[10][1]-5), scale=1.8
)
cv2.imshow(window_name, frame)
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break
cv2.destroyAllWindows()
I have an object detection code, in which i calculate the distance from the face to the camera ? What functions can I use and how to play an audio that says every 2-3 seconds the distance? Thank you
below is the code
import cv2
import cvzone
from cvzone.FaceMeshModule import FaceMeshDetector
import os
class Face:
window_name = "Detected Objects in webcam"
video = cv2.VideoCapture(0)
while video.isOpened():
ret, frame = video.read()
detector = FaceMeshDetector(maxFaces=3)
img, faces = detector.findFaceMesh(frame, draw=False)
if not ret:
break
image = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cascade_classifier = cv2.CascadeClassifier(
f"{cv2.data.haarcascades}haarcascade_frontalface_default.xml")
detected_objects = cascade_classifier.detectMultiScale(
image, minSize=(20, 20))
if len(detected_objects) != 0:
for (x, y, height, width) in detected_objects:
cv2.rectangle(
frame, (x, y), ((x + height), (y + width)), (0, 255, 0), 5
)
for face in faces:
r_point = face[374]
l_point = face[145]
point_width, _ = detector.findDistance(l_point, r_point)
width = 6.3
distance = (width * 600) / point_width
# text_to_speech(math.floor(distance))
dis = str(distance)
cvzone.putTextRect(
frame, f"Depth:{distance:.2f} cm", (face[10][0]-95, face[10][1]-5), scale=1.8
)
cv2.imshow(window_name, frame)
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break
cv2.destroyAllWindows()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论