当前位置:   article > 正文

物体检测实战:使用OpenCV内置方法实现行人检测

物体检测实战:使用OpenCV内置方法实现行人检测

find the largest (x, y) coordinates for the start of the bounding

box and the smallest (x, y) coordinates for the end of the bounding

box

xx1 = np.maximum(x1[i], x1[idxs[:last]])

yy1 = np.maximum(y1[i], y1[idxs[:last]])

xx2 = np.minimum(x2[i], x2[idxs[:last]])

yy2 = np.minimum(y2[i], y2[idxs[:last]])

compute the width and height of the bounding box

w = np.maximum(0, xx2 - xx1 + 1)

h = np.maximum(0, yy2 - yy1 + 1)

compute the ratio of overlap

overlap = (w * h) / area[idxs[:last]]

delete all indexes from the index list that have overlap greater

than the provided overlap threshold

idxs = np.delete(idxs, np.concatenate(([last],

np.where(overlap > overlapThresh)[0])))

return only the bounding boxes that were picked

return boxes[pick].astype(“int”)

image_types = (“.jpg”, “.jpeg”, “.png”, “.bmp”, “.tif”, “.tiff”)

def list_images(basePath, contains=None):

return the set of files that are valid

return list_files(basePath, validExts=image_types, contains=contains)

def list_files(basePath, validExts=None, contains=None):

loop over the directory structure

for (rootDir, dirNames, filenames) in os.walk(basePath):

loop over the filenames in the current directory

for filename in filenames:

if the contains string is not none and the filename does not contain

the supplied string, then ignore the file

if contains is not None and filename.find(contains) == -1:

continue

determine the file extension of the current file

ext = filename[filename.rfind(“.”):].lower()

check to see if the file is an image and should be processed

if validExts is None or ext.endswith(validExts):

construct the path to the image and yield it

imagePath = os.path.join(rootDir, filename)

yield imagePath

def resize(image, width=None, height=None, inter=cv2.INTER_AREA):

dim = None

(h, w) = image.shape[:2]

如果高和宽为None则直接返回

if width is None and height is None:

return image

检查宽是否是None

if width is None:

计算高度的比例并并按照比例计算宽度

r = height / float(h)

dim = (int(w * r), height)

高为None

else:

计算宽度比例,并计算高度

r = width / float(w)

dim = (width, int(h * r))

resized = cv2.resize(image, dim, interpolation=inter)

return the resized image

return resized

nms函数:非极大值抑制。

list_images:读取图片。

resize:等比例改变大小。

construct the argument parse and parse the arguments

ap = argparse.ArgumentParser()

ap.add_argument(“-i”, “–images”, default=‘test1’, help=“path to images directory”)

args = vars(ap.parse_args())

初始化 HOG 描述符/人物检测器

hog = cv2.HOGDescriptor()

hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())

定义输入图片的文件夹路径。

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数Python工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Python开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img



既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Python开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新

如果你觉得这些内容对你有帮助,可以添加V获取:vip1024c (备注Python)
img

最后

Python崛起并且风靡,因为优点多、应用领域广、被大牛们认可。学习 Python 门槛很低,但它的晋级路线很多,通过它你能进入机器学习、数据挖掘、大数据,CS等更加高级的领域。Python可以做网络应用,可以做科学计算,数据分析,可以做网络爬虫,可以做机器学习、自然语言处理、可以写游戏、可以做桌面应用…Python可以做的很多,你需要学好基础,再选择明确的方向。这里给大家分享一份全套的 Python 学习资料,给那些想学习 Python 的小伙伴们一点帮助!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/409018
推荐阅读
相关标签