我想使用Raspberry与OpenCV + yolo做智能监控系统。
问题是:与其在屏幕上显示一个盒子,不如在检测到"person“时返回真假吗?
我了解到,它可以成功地在屏幕上显示一个盒子在屏幕上,当发现一些东西。我用的是一本中文书上的代码,我担心它可能会把整个代码贴在这里,这可能会破坏规则,所以我编写了描述它使用的代码。
原始代码使用以下3 yolo文件:
yolo4-tiny.cfg
coco.names
yolo4-tine.weight和
import cv2, numpy and time代码将图像调整为较小的帧,然后将图像放入yolo中。
def XXX(image, model):
classes, confs, boxes = model.detect(image, 0.6, 0.3)
return classes, confs, boxes下一步是在图像中显示框。
def YYY(image, classes, confs, boxes, names, colors):
new_image = image.copy()
for (classid, conf, box) in zip(classes, confs, boxes):
x, y, w , h = box
label = '{}: {:.2f}'.format(names[int(classid)], float(conf))
color = colors[int(classid)]
cv2.rectangle(new_image, (x, y), (x + w, y + h), color, 2)
cv2.putText(new_image, label, (x, y - 10),
cv2.FONT_HERSHEY_SIMPLEX, 0.7, color, 2
)
return new_image我的问题是如何在检测“人”时返回真。谢谢你回答这个问题。
发布于 2022-06-22 04:34:06
在您的例子中(我没有使用Yolo,但我使用了OpenCV人脸检测和MTCNN),您可以使用detect()函数返回的变量之一。应该安全地假设,如果模型在检测函数中创建了一个边界框,那么就存在一个人。
def XXX(image, model):
classes, confs, boxes = model.detect(image, 0.6, 0.3)
return classes, confs, boxes
x, y, z = XXX(image, model)
if z is not None: # if not an iterable
# if z.any(): # <-- this might be any(z) instead of z.any()
# do somethinghttps://stackoverflow.com/questions/72708329
复制相似问题