资源简介
基于python语言的opencv行人检测,通过OpenCV自带的HOG+SVM行人检测器图片中的行人,并根据界面提示按钮,选择相应的操作。

代码片段和文件信息
# import the necessary packages
from __future__ import print_function #确保代码同时在Python2.7和Python3上兼容
from imutils.object_detection import non_max_suppression
from imutils import paths
import numpy as np
import argparse
import imutils #安装库pip install imutils ;pip install --upgrade imutils更新版本大于v0.3.1
import cv2
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument(“-i“ “--images“required=True help=“path to images directory“)
# args = vars(ap.parse_args())
# 初始化我们的行人检测器
hog = cv2.HOGDescriptor() #初始化方向梯度直方图描述子
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector()) #设置支持向量机(Support Vector Machine)使得它成为一个预先训练好了的行人检测器
#到这里,我们的OpenCV行人检测器已经完全载入了,我们只需要把它应用到一些图像上
#---------------------------------------------------------------------------------------------------------
image_Path=“./images“;
# loop over the image paths
for imagePath in paths.list_images(image_Path): #args[“images“]
# load the image and resize it to (1) reduce detection time
# and (2) improve detection accuracy
image = cv2.imread(imagePath)
image = imutils.resize(image width=min(400 image.shape[1]))
orig = image.copy()
‘‘‘
构造了一个尺度scale=1.05的图像金字塔,以及一个分别在x方向和y方向步长为(44)像素大小的滑窗
scale的尺度设置得越大,在图像金字塔中层的数目就越少,相应的检测速度就越快,但是尺度太大会导致行人出现漏检;
同样的,如果scale设置得太小,将会急剧的增加图像金字塔的层数,这样不仅耗费计算资源,而且还会急剧地增加检测过程
中出现的假阳数目(也就是不是行人的被检测成行人)。这表明,scale是在行人检测过程中它是一个重要的参数,
需要对scale进行调参。我会在后面的文章中对detectMultiScale中的每个参数做些调研。
‘‘‘
# detect people in the image:
(rects weights) = hog.detectMultiScale(image winStride=(4 4)
padding=(8 8) scale=1.05)
# draw the original bounding boxes
for (x y w h) in rects:
cv2.rectangle(orig (x y) (x + w y + h) (0 0 255) 2)
# apply non-maxima suppression to the bounding boxes using a
# fairly large overlap threshold to try to maintain overlapping
# boxes that are still people
#应用非极大抑制方法,通过设置一个阈值来抑制那些重叠的边框
rects = np.array([[x y x + w y + h] for (x y w h) in rects])
pick = non_max_suppression(rects probs=None overlapThresh=0.65)
# draw the final bounding boxes
for (xA yA xB yB) in pick:
cv2.rectangle(image (xA yA) (xB yB) (0 255 0) 2)
# show some information on the number of bounding boxes
filename = imagePath[imagePath.rfind(“/“) + 1:]
print(“[INFO] {}: {} original boxes {} after suppression“.format(
filename len(rects) len(pick)))
# show the output images
cv2.imshow(“Before NMS“ orig)
cv2.imshow(“After NMS“ image)
cv2.waitKey(0)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-03-01 17:56 PedestrianDetection\
目录 0 2019-03-01 17:56 PedestrianDetection\.idea\
文件 183 2018-01-21 14:41 PedestrianDetection\.idea\misc.xm
文件 290 2018-01-21 14:40 PedestrianDetection\.idea\modules.xm
文件 455 2018-01-21 14:41 PedestrianDetection\.idea\PedestrianDetection.iml
文件 10650 2018-01-22 09:32 PedestrianDetection\.idea\workspace.xm
文件 39 2018-12-18 18:04 PedestrianDetection\1.txt
文件 3361 2018-12-10 19:27 PedestrianDetection\detect.py
目录 0 2018-12-18 18:07 PedestrianDetection\image\
目录 0 2019-03-01 17:56 PedestrianDetection\images\
文件 98918 2018-12-18 17:41 PedestrianDetection\images\person_1.jpg
文件 23582 2018-12-18 17:40 PedestrianDetection\images\person_10.jpg
文件 150943 2018-12-18 17:56 PedestrianDetection\images\person_11.jpg
文件 921654 2003-05-20 13:43 PedestrianDetection\images\person_12.bmp
文件 921654 2003-05-20 13:43 PedestrianDetection\images\person_13.bmp
文件 204593 2018-12-18 17:58 PedestrianDetection\images\person_14.jpeg
文件 103383 2018-12-18 18:00 PedestrianDetection\images\person_15.jpeg
文件 921654 2003-05-20 13:43 PedestrianDetection\images\person_16.bmp
文件 921654 2003-05-20 13:43 PedestrianDetection\images\person_2.bmp
文件 22728 2018-12-18 17:53 PedestrianDetection\images\person_220.jpg
文件 921654 2003-05-20 13:37 PedestrianDetection\images\person_221.bmp
文件 921654 2003-05-20 13:43 PedestrianDetection\images\person_3.bmp
文件 921654 2003-05-20 13:43 PedestrianDetection\images\person_302.bmp
文件 921654 2003-05-20 13:44 PedestrianDetection\images\person_390.bmp
文件 945906 2018-12-18 17:47 PedestrianDetection\images\person_4.JPG
文件 37042 2018-12-18 17:46 PedestrianDetection\images\person_5.jpg
文件 71234 2018-12-18 17:47 PedestrianDetection\images\person_6.jpg
文件 83034 2018-12-18 17:36 PedestrianDetection\images\person_7.jpg
文件 30150 2018-12-18 17:50 PedestrianDetection\images\person_8.jpg
文件 921654 2003-05-20 13:43 PedestrianDetection\images\person_9.bmp
文件 3511 2018-12-18 18:06 PedestrianDetection\unti
............此处省略0个文件信息
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论