Raspberry pi opencv+ YOLO:在检测“人”时返回对还是错。

发布于 2025-02-09 12:25:37 字数 1075 浏览 3 评论 0原文

我想将Raspberry Pi与OpenCV + Yolo一起进行智能监测系统。

问题是:当检测“人”时,它不是在屏幕上显示盒子,而是返回ture还是错误?

我了解到,在检测某些内容时,它可以成功在屏幕上显示一个盒子。我使用一本中文书中的代码,恐怕它可能会使规则粘贴在此处粘贴整个代码,因此我BREIF描述了它使用的代码。

原始代码使用以下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

我的问题是在检测“人”时如何返回真实。谢谢您的呼吸。

I would like to use Raspberry Pi with OpenCV + yolo to do smart monitering system.

The question is: Instead of showing a box on the screen, could it return Ture or False when detecting "person"?

I learned that it could successful show on screen a box on screen when detecting something. I use a code from a chinese book, I am afraid that it might viloate the rule to paste the whole code here, so I breif describe the code it use.

the original code use the following 3 yolo file:

 yolo4-tiny.cfg
 coco.names
 yolo4-tine.weight

And

import cv2, numpy and time

the code resize the image to a smaller frame and then put the image into yolo

def XXX(image, model):
    classes, confs, boxes = model.detect(image, 0.6, 0.3)
    return classes, confs, boxes

the next step is show the box in the image.

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

My question is how to return true when detecting "person". Thank you for respone this question.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜还是长夜 2025-02-16 12:25:37

在您的情况下,(我尚未使用Yolo,但是我使用了OpenCV面部检测和MTCNN),您可以使用detchect()函数的返回变量之一。可以肯定地假设,如果模型在检测功能中创建一个边界框,则存在一个人。

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 something

In your case, (I haven't used Yolo, but I've used OpenCV face detection and MTCNN), you can use one of the returned variables from the detect() function. It should be safe to assume that if the model creates a bounding box in the detection function, then a person exists.

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 something
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文