物体检测实战:使用OpenCV内置方法实现行人检测,Python开发应该了解的Binder原理

compute the area of the bounding boxes and grab the indexes to sort

(in the case that no probabilities are provided, simply sort on the

bottom-left y-coordinate)

area = (x2 - x1 + 1) * (y2 - y1 + 1)

idxs = y2

if probabilities are provided, sort on them instead

if probs is not None:

idxs = probs

sort the indexes

idxs = np.argsort(idxs)

keep looping while some indexes still remain in the indexes list

while len(idxs) > 0:

grab the last index in the indexes list and add the index value

to the list of picked indexes

last = len(idxs) - 1

i = idxs[last]

pick.append(i)

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())

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

一、Python所有方向的学习路线

Python所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照下面的知识点去找对应的学习资源,保证自己学得较为全面。

img
img

二、Python必备开发工具

工具都帮大家整理好了,安装就可直接上手!img

三、最新Python学习笔记

当我学到一定基础,有自己的理解能力的时候,会去阅读一些前辈整理的书籍或者手写的笔记资料,这些笔记详细记载了他们对一些技术点的理解,这些理解是比较独到,可以学到不一样的思路。

img

四、Python视频合集

观看全面零基础学习视频,看视频学习是最快捷也是最有效果的方式,跟着视频中老师的思路,从基础到深入,还是很容易入门的。

img

五、实战案例

纸上得来终觉浅,要学会跟着视频一起敲,要动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。img

六、面试宝典

在这里插入图片描述

在这里插入图片描述

简历模板在这里插入图片描述

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

深知大多数初中级Python工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

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

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

如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注:python)
img

,而且极易碰到天花板技术停滞不前!**

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

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

如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注:python)
[外链图片转存中…(img-I1FIqoKw-1711021230139)]

  • 18
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很好,下面我来为你介绍一下 OpenCV-Python 实现目标检测的过程。 OpenCV-Python 是一款基于 Python 的计算机视觉库,它可以帮助我们完成各种图像处理任务,包括图像的读取、处理、显示等。在使用它进行目标检测时,我们可以使用传统方法 HOG+SVM 实现。 HOG(Histogram of Oriented Gradient)特征是一种常用的图像特征,它可以描述图像中的边缘、角点等信息,其中梯度方向直方图是 HOG 特征的核心部分。在目标检测中,我们需要先提取出图像中的 HOG 特征,然后再使用 SVM(Support Vector Machine)进行分类,从而实现目标检测。 下面是一个简单的 OpenCV-Python 实现目标检测的示例代码: ```python import cv2 # 加载 SVM 分类器 svm = cv2.ml.SVM_load('svm.xml') # 加载测试图片 img = cv2.imread('test.jpg') # 创建 HOG 描述符 hog = cv2.HOGDescriptor() # 设置 SVM 分类器 hog.setSVMDetector(svm) # 检测目标并绘制矩形框 rects, weights = hog.detectMultiScale(img, winStride=(8, 8), padding=(32, 32), scale=1.05) for (x, y, w, h) in rects: cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2) # 显示结果 cv2.imshow('result', img) cv2.waitKey(0) cv2.destroyAllWindows() ``` 在代码中,我们首先加载了训练好的 SVM 分类器,并加载了测试图片。然后创建了 HOG 描述符,并设置 SVM 分类器。最后使用 detectMultiScale 函数检测目标,并绘制矩形框,最终在窗口中显示检测结果。 当然,这仅仅是一个简单的示例,实际的目标检测过程还需要根据具体的应用场景进行调整和优化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值