边缘设备上的实时AI人员检测:在Raspberry Pi上启动SSD(译文)
By S.F.
本文链接 https://www.kyfws.com/news/real-time-ai-person-detection-on-edge-devices-laun/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 4 分钟阅读 - 1916 个词 阅读量 0边缘设备上的实时AI人员检测:在Raspberry Pi上启动SSD(译文)
原文地址:https://www.codeproject.com/Articles/5281995/Real-time-AI-Person-Detection-on-Edge-Devices-Laun
原文作者:Sergey L. Gladkiy
译文由本站翻译
前言
In this article, we’ll see how you can install Python-OpenCV on the device and run the code. 在本文中,我们将介绍如何在设备上安装Python-OpenCV并运行代码. Here we’ll launch our person detection software on a Raspberry Pi device. 在这里,我们将在Raspberry Pi设备上启动人体检测软件.
(In the last article of this series, we’ve written the Python code for detecting persons in images using SSD models. In this article, we’ll go over the Python-OpenCV installation on a Raspberry Pi device, and then see how to launch our Python code on that device.) 在本系列的最后一篇文章中,我们编写了Python代码,用于使用SSD模型检测图像中的人物.在本文中,我们将介绍Raspberry Pi设备上的Python-OpenCV安装,然后了解如何在该设备上启动Python代码.
(First,) 第一, (download) 下载 (and install the Raspberry Pi OS – the official operating system for the Pi device series. We used) 并安装Raspberry Pi OS – Pi设备系列的官方操作系统.我们用了**(*Raspberry Pi OS (32-bit) with desktop and recommended software*) 具有桌面和推荐软件的Raspberry Pi OS(32位)**(*. The OS can be installed on the device’s SD card using a disk imager. For our Windows desktop, we used*) .可以使用磁盘映像程序将操作系统安装在设备的SD卡上.对于我们的Windows桌面,我们使用了 (Win32DiskImager) Win32DiskImager (*. With the first boot, the system asks for updating all pre-installed system packages – we recommend that you do this. The update can take several minutes.*) .首次启动时,系统会要求更新所有预安装的系统软件包-我们建议您这样做.更新可能需要几分钟.
(*Now it’s time to install Python-OpenCV on the device. There are two main options for this: compile the OpenCV source on the device or install an existing package on the system. We’ve used the latter option for simplicity. Fortunately, there is good support for*) 现在是时候在设备上安装Python-OpenCV.为此,有两个主要选项:在设备上编译OpenCV源或在系统上安装现有软件包.为了简单起见,我们使用了后一种选项.幸运的是,有很好的支持 (Python packages on Raspberry Pi) Raspberry Pi上的Python软件包 (*. Before installing the OpenCV library, we need to install some prerequisites, such as HD5 and Qt packages. After this, you need to set up a virtual environment for further use of the OpenCV package. We’ve installed the*) .在安装OpenCV库之前,我们需要安装一些先决条件,例如HD5和Qt软件包.此后,您需要设置虚拟环境以进一步使用OpenCV软件包.我们已经安装了 virtualenv
(*and*) 和 virtualenvwrapper
(*tools, and then activated a virtual environment named ‘*) 工具,然后激活一个名为" cv
(*’. Then, we’ve installed the*) ’.然后,我们安装了 opencv-contrib-python
(*package in that environment. This package is highly recommended as it includes all the required OpenCV modules.*) 在那种环境下打包.强烈推荐该软件包,因为它包含所有必需的OpenCV模块.
(*Now we can use the virtual environment to launch on the Pi device the Python code for person detection that we’d developed in the previous article. The classes are the same as for the desktop application. We’ll only need to change the paths for the DNN models and the image locations. Here is the code modified for the Pi 3 device:*) 现在,我们可以使用虚拟环境在Pi设备上启动我们在上一篇文章中开发的用于人员检测的Python代码.这些类与桌面应用程序相同.我们只需要更改DNN模型的路径和图像位置即可.这是为Pi 3设备修改的代码:
# testing SSD
proto_file = r"/home/pi/Desktop/PI_RPD/mobilenet.prototxt"
model_file = r"/home/pi/Desktop/PI_RPD/mobilenet.caffemodel"
ssd_net = CaffeModelLoader.load(proto_file, model_file)
print("Caffe model loaded from: "+model_file)
proc_frame_size = 300
# frame processor for MobileNet
ssd_proc = FrameProcessor(proc_frame_size, 1.0/127.5, 127.5)
person_class = 15
ssd = SSD(ssd_proc, ssd_net)
im_dir = r"/home/pi/Desktop/PI_RPD/test_images"
im_name = "woman_640x480_01.png"
im_path = os.path.join(im_dir, im_name)
image = cv2.imread(im_path)
print("Image read from: "+im_path)
obj_data = ssd.detect(image)
persons = ssd.get_objects(image, obj_data, person_class, 0.5)
person_count = len(persons)
print("Person count on the image: "+str(person_count))
Utils.draw_objects(persons, "PERSON", (0, 0, 255), image)
res_dir = r"/home/pi/Desktop/PI_RPD/results"
res_path = os.path.join(res_dir, im_name)
cv2.imwrite(res_path, image)
print("Result written to: "+res_path)
(If our code resides in a single Python file, say) 如果我们的代码位于单个Python文件中,请说**(*pi_rpd_run_img.pi3.py*) pi_rpd_run_img.pi3.py**(*, we can launch it from the terminal with two subsequent commands:*) ,我们可以使用以下两个命令从终端启动它:
workon cv
python /home/pi/Desktop/PI_RPD/pi_rpd_run_img.pi3.py
(Here is the screenshot of the terminal response:) 这是终端响应的屏幕截图:
(As you can see from the picture above, the code works on the Pi device the same as it did on a desktop computer. And, as expected, it produces the same person detections in the test images:) 从上图可以看到,该代码在Pi设备上的工作方式与在台式计算机上相同.并且,正如预期的那样,它会在测试图像中产生相同的人检测:
(So we’ve shown that we can detect persons in images using the SSD model on the Raspberry Pi device with the same precision we did on a desktop or a laptop. The difference is speed. Yes, performance on an edge device can be an issue.) 因此,我们证明了可以在Raspberry Pi设备上使用SSD模型检测图像中的人物,其精度与台式机或笔记本电脑相同.区别在于速度.是的,边缘设备的性能可能是一个问题.
(Next Steps) 下一步
(In the next article, we’ll test the accuracy and the performance of the MibileNet and SqueezeNet models on the Raspberry Pi device. We’ll select the better option and use it for further testing on a video clip, and then in the real-time mode.) 在下一篇文章中,我们将测试Raspberry Pi设备上MibileNet和SqueezeNet模型的准确性和性能.我们将选择更好的选项,并将其用于在视频片段上进行进一步测试,然后在实时模式下进行测试.
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
Python AI Raspberry neural 新闻 翻译