[Python Study Notes]行人检测
# --------------------------------------------------------------
# @文件: 行人识别.py
# @工程: blog
# @时间: 2018/3/16 21:12
# @作者: liu yang
# @博客: liuyang1.club
# @邮箱: liuyang0001@outlook.com
# -------------------------------------------------------------
# 编码格式
# -*- coding: utf-8 -*-
# Python版本
# #!/usr/bin/python3 import cv2 def draw_detection(img, rects):
for x, y, w, h in rects:
pad_w, pad_h = int(0.05 * w), int(0.05 * h)
cv2.rectangle(img, (x + pad_w, y + pad_h), (x + w - pad_w, y + h - pad_h), (0, 255, 0), 2) def draw_alart(img, rects):
area = [0, 2]
size = img.shape
area_img = size[0] * size[1]
for x, y, w, h in rects:
area.append(w * h)
thresh = 0.25
if max(area) / area_img > thresh:
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(img, "Incoming Peaple", (round(size[0] / 2) - 80, round(size[1] / 2) - 50),
font, 6, (0, 0, 255), 25) # 传入opencv里默认的参数
hog = cv2.HOGDescriptor()
# 得到行人的特征值
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
# 调用摄像头,也可以传入一个路径视频文件
cap = cv2.VideoCapture(0)
while True:
# ret是一个表
# 循环读取每一帧的数据
ret, frame = cap.read()
# 扫描图像,如果检测不到进行缩小检测
found, w = hog.detectMultiScale(frame, 0, winStride=(8, 8), padding=(8, 8), scale=1.05)
draw_detection(frame, found)
draw_alart(frame, found)
# 显示每一帧的画面
cv2.imshow("pd", frame)
# 按q退出
key = cv2.waitKey(1) & 0xff
if key == ord('q'):
break # 运行结束后释放摄像头
cap.release()
cv2.destroyAllWindows()
[Python Study Notes]行人检测的更多相关文章
- [Python Study Notes]异常处理
正则表达式 python提供了两个非常重要的功能来处理python程序在运行中出现的异常和错误.你可以使用该功能来调试python程序. 异常处理 断言(Assertions) python标准异常 ...
- [Python Study Notes] Python的安装
Windows: 1.下载安装包: 转到Python官网https://www.python.org/downloads/ ,下载最新版本的Python. 2.安装 安装到自定义的安装路径下. 3. ...
- [Python Study Notes]物体运动检测
基于opencv的cv2模块实现 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- [Python Study Notes]匿名函数
Python 使用 lambda 来创建匿名函数. lambda这个名称来自于LISP,而LISP则是从lambda calculus(一种符号逻辑形式)取这个名称的.在Python中,lambda作 ...
- [Python Study Notes]字符串处理技巧(持续更新)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- [Python Study Notes]with的使用
在 Python 2.5 中, with 关键字被加入.它将常用的 try ... except ... finally ... 模式很方便的被复用.看一个最经典的例子: with open('fil ...
- [Python Study Notes]实现对键盘控制与监控
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- [Python Study Notes]实现对鼠标控制
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- [Python Study Notes]批量将wold转换为pdf
本文代码,由原ppt2pdf.py进行改写 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
随机推荐
- NovaException: Unexpected vif_type=binding_failed
nova/virt/libvirt/vif.py: _("Unexpected vif_type=%s") % vif_type) NovaException: Unexpecte ...
- python中的单引号双引号和三引号
python的单引号和双引号没有本质的区别,而三引号有两种作用:注释和换行 一. 单引号中可以包含双引号,双引号中可以包含单引号 print("好好学习,'天天向上'") 结果: ...
- Linux中的固件加载例子
AP6335模块(BCM4339)在上电运行时,是需要刷入固件的,其在普通WIFI模式和AP模式之间切换时,也是需要加载不同的固件的,其位于/system/etc/firmware/下面:fw_bcm ...
- @angular/cli项目构建--路由2
app.module.ts update const routes: Routes = [ {path: '', redirectTo: '/home', pathMatch: 'full'}, {p ...
- 201621123014《Java程序设计》第十一周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线程 1. 源代码阅读:多线程程序BounceThread 1.1 BallR ...
- hdoj-1046-Gridland(规律题)
题目链接 #include <algorithm> #include <iostream> using namespace std; int main() { int t; c ...
- C++中关于strtok()函数的用法
strtok: #include <string.h> char *strtok(char *str, const char *delim); char *strtok_r(char *s ...
- NOI 模拟赛 #3
打开题一看,咦,两道数数,一道猫式树题 感觉树题不可做呀,暴力走人 数数题数哪个呢?感觉置换比矩阵好一些 于是数了数第一题 100 + 0 + 15 = 115 T1 bishop 给若干个环,这些环 ...
- php redis 操作手册
String 类型操作 string是redis最基本的类型,而且string类型是二进制安全的.意思是redis的string可以包含任何数据.比如jpg图片或者序列化的对象 1 $redis-&g ...
- 【redis】redis的 key的命名规则
key的命名规则 定义为 MS-TEN:SESSION_KEY_IN_LOGIN_NAME:fqh 使用:进行分割,这样存入redis的是有层次结构的,如下