本文将介绍基于米尔电子MYD-LT527开发板(米尔基于全志T527开发板)的OpenCV行人检测方案测试。
摘自优秀创作者-小火苗
1.在全志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()
四、实际操作
文章评论(0条评论)
登录后参与讨论