git:https://github.com/linyi0604/Computer-Vision

 # coding:utf-8

 import cv2

 # 检测i方框 包含o方框
def is_inside(o, i):
ox, oy, ow, oh = o
ix, iy, iw, ih = i
return ox > ix and ox + ow < ix + iw and oy + oh < iy + ih # 将人外面的方框画出来
def draw_person(image, person):
x, y, w, h = person
cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 255), 2) # 读入图片
img = cv2.imread("../data/people2.jpg")
# 获取hog检测器对象
hog = cv2.HOGDescriptor()
# 设置检测人的默认检测器
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
# 在图片中检测人,
# 返回found列表 每个元素是一个(x, y, w, h)的矩形,w是每一个矩形的置信度
found, w = hog.detectMultiScale(img)
found_filtered = []
# 如果方框有包含,只留下内部的小方块
for ri, r in enumerate(found):
for qi, q in enumerate(found):
if ri != qi and is_inside(r, q):
break
else:
found_filtered.append(r) # 将每一个方块画出来
for person in found_filtered:
draw_person(img, person) cv2.imshow("person detection", img)
cv2.waitKey()
cv2.destroyAllWindows()

python opencv3 检测人的更多相关文章

  1. Python智能检测编码并转码

    #安装包工具 $pip3 install chardet #直接打开文件,中文显示乱码 >>> import chardet >>> f = open('test. ...

  2. Python IAQ中文版 - Python中少有人回答的问题

    Python中少有人回答的问题 The Python IAQ: Infrequently Answered Questions 1 Q: 什么是"少有人回答的问题(Infrequently ...

  3. python opencv3 cornerHarris 角点检测

    git:https://github.com/linyi0604/Computer-Vision 角点也是处在一个无论框框往哪边移动 框框内像素值都会变化很大的情况而定下来的点 如果框框水平方向上移动 ...

  4. python opencv3 摄像头人脸检测

    git:https://github.com/linyi0604/Computer-Vision # coding:utf8 import cv2 def detect(): # 创建人脸检测的对象 ...

  5. python opencv3 静态图片检测人脸

    git:https://github.com/linyi0604/Computer-Vision # coding:utf-8 import cv2 filename = "../data/ ...

  6. python opencv3 圆检测

    git:https://github.com/linyi0604/Computer-Vision # coding:utf8 import cv2 import numpy as np img_ori ...

  7. python opencv3 直线检测

    git:https://github.com/linyi0604/Computer-Vision # coding:utf8 import cv2 import numpy as np # 读入图像 ...

  8. python opencv3 grabcut前景检测

    git:https://github.com/linyi0604/Computer-Vision import numpy as np import cv2 import matplotlib.pyp ...

  9. python opencv3 轮廓检测

    git:https://github.com/linyi0604/Computer-Vision # coding:utf8 import cv2 import numpy as np # 创建一个2 ...

随机推荐

  1. kafka入门(1)- 基本概念

    Kafka is a distributed,partitioned,replicated commit logservice Kafka提供了类似于JMS的特性,但是在设计实现上完全不同,并不是JM ...

  2. opencv产生随机的颜色

    //将HSV颜色空间值转换成RGB值,参考这里cv::Scalar HSV2RGB(const float h, const float s, const float v) { ); - h_i; - ...

  3. python概念-常用模块之究竟你是什么鬼

    模块: 一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 说白了,就是一个python文件中定义好了类和方法,实现了一些功能,可以被别的python文件所调用 ...

  4. 洛谷 P4093: bzoj 4553: [HEOI2016/TJOI2016]序列

    题目传送门:洛谷P4093. 题意简述: 给定一个长度为 \(n\) 的序列 \(a\). 同时这个序列还可能发生变化,每一种变化 \((x_i,y_i)\) 对应着 \(a_{x_i}\) 可能变成 ...

  5. ubuntu复制文件或目录

    转自http://www.linuxidc.com/Linux/2008-11/17179.htm cp(copy)命令 该命令的功能是将给出的文件或目录拷贝到另一文件或目录中. 语法: cp [选项 ...

  6. linux中core dump开启使用教程【转】

    转自:http://www.111cn.net/sys/linux/67291.htm 一.什么是coredump 我们经常听到大家说到程序core掉了,需要定位解决,这里说的大部分是指对应程序由于各 ...

  7. java递归遍历获取目录下所有文件

    import java.io.File; import java.util.ArrayList; import java.util.List; public class GetFiles { Arra ...

  8. js 去除字符串所有空格

    function trim(str){ return str.replace(/\s|\xA0/g,""); }

  9. MyBatis3-实现MyBatis分页

    此文章中的例子是沿用上一篇文章http://www.cnblogs.com/EasonJim/p/7055499.html的Spring MVC集成的例子改装的. MyBatis分页有以下方式实现: ...

  10. TObjectList

    AOwnsObjects = true 就是  objectlist释放的时候,里面的对象一并释放. TObjectList对象的创建方法有一个参数:constructor TObjectList.C ...