python opencv3 检测人
Python 检测 OPENCV3
2023-09-27 14:28:47 时间
git:https://github.com/linyi0604/Computer-Vision
1 # coding:utf-8
2
3 import cv2
4
5
6 # 检测i方框 包含o方框
7 def is_inside(o, i):
8 ox, oy, ow, oh = o
9 ix, iy, iw, ih = i
10 return ox > ix and ox + ow < ix + iw and oy + oh < iy + ih
11
12
13 # 将人外面的方框画出来
14 def draw_person(image, person):
15 x, y, w, h = person
16 cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 255), 2)
17
18
19 # 读入图片
20 img = cv2.imread("../data/people2.jpg")
21 # 获取hog检测器对象
22 hog = cv2.HOGDescriptor()
23 # 设置检测人的默认检测器
24 hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
25 # 在图片中检测人,
26 # 返回found列表 每个元素是一个(x, y, w, h)的矩形,w是每一个矩形的置信度
27 found, w = hog.detectMultiScale(img)
28 found_filtered = []
29 # 如果方框有包含,只留下内部的小方块
30 for ri, r in enumerate(found):
31 for qi, q in enumerate(found):
32 if ri != qi and is_inside(r, q):
33 break
34 else:
35 found_filtered.append(r)
36
37 # 将每一个方块画出来
38 for person in found_filtered:
39 draw_person(img, person)
40
41
42 cv2.imshow("person detection", img)
43 cv2.waitKey()
44 cv2.destroyAllWindows()
相关文章
- 【Python从入门到精通】(二十三)Python threading Local()函数用法:返回线程局部变量
- python读取文件夹图像名称并保存为txt文件
- 用递归方法判断字符串是否是回文(Recursion Palindrome Python)
- Python读取mdb文件以及shell检测
- Python接口测试实战之unittest测试框架【7000字超细教程】
- Python爬虫:Scrapy的Crawler对象及扩展Extensions和信号Signals
- Python 之父 Guido van Rossum 宣布退休
- 2022.06青少年软件编程(Python)等级考试试卷(五级)
- python 标定相机 检测圆点 对称或非对称02
- Python迭代器的生成与学习笔记
- 使用Python,OpenCV执行视觉显著性检测(Visual Saliency Detection)
- 使用Python,OpenCV和深度学习进行全面嵌套边缘检测
- 使用Python,OpenCV和Scikit-Image检测低对比度图像
- 使用Python和OpenCV检测图像中的多个亮点
- 使用Python,OpenCV和Hough圆检测图像中的圆
- 使用Python,OpenCV,dlib进行睡意检测(疲劳驾驶检测)
- Python基础 -- 变量进阶
- 第9.8节 Python使用writelines函数写入文件内容
- Python中的文档字符串作用
- 第4章 基础知识进阶 第4.1节 Python基础概念之迭代、可迭代对象、迭代器
- Python 日期和时间
- python opencv3 运动检测
- python opencv3 grabcut前景检测
- python opencv3 直线检测