本文将介绍基于米尔电子MYD-LT527开发板(米尔基于全志T527开发板)的OpenCV行人检测方案测试。
摘自优秀创作者-小火苗
sudo apt-get install libopencv-dev python3-opencv
sudo apt-get install python3-pip
使用HOG和SVM基于全志T527开发板构建行人检测器的关键步骤包括:
import cv2
import time
def detect(image,scale):
imagex=image.copy() #函数内部做个副本,让每个函数运行在不同的图像上
hog = cv2.HOGDescriptor() #初始化方向梯度直方图描述子
#设置SVM为一个预先训练好的行人检测器
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
#调用函数detectMultiScale,检测行人对应的边框
time_start = time.time() #记录开始时间
#获取(行人对应的矩形框、对应的权重)
(rects, weights) = hog.detectMultiScale(imagex,scale=scale)
time_end = time.time() #记录结束时间
# 绘制每一个矩形框
for (x, y, w, h) in rects:
cv2.rectangle(imagex, (x, y), (x + w, y + h), (0, 0, 255), 2)
print("sacle size:",scale,",time:",time_end-time_start)
name=str(scale)
cv2.imshow(name, imagex) #显示原始效果
image = cv2.imread("back.jpg")
detect(image,1.01)
detect(image,1.05)
detect(image,1.3)
cv2.waitKey(0)
cv2.destroyAllWindows()
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有