资源简介
安全帽检测的检测,使用python实现,仅供参考。
代码片段和文件信息
# -*- coding: utf-8 -*-
import threadpool
import threading
import time
import random
import Queue
import numpy as np
import cv2
import sys
import osshutil
import time
import datetime
from imutils.object_detection import non_max_suppression
from imutils import paths
import imutils #安装库pip install imutils ;pip install --upgrade imutils更新版本大于v0.3.1
import threading
#import get_video_address
import copy
import hashlib
from imutils.video import FileVideoStream
from imutils.video import VideoStream
class bug_rect_info:
def __init__(selfxywh):
self.x = x
self.y = y
self.w = w
self.h = h
self.count = 1
class people_detect:
def __init__(self):
#已经训练好的分类器,检测佩戴安全头的人员
self.face_cascade = cv2.CascadeClassifier(os.path.join(sys.path[0] ‘cascade-v2.5.xml‘))
#检测行人
self.hog = cv2.HOGDescriptor() #初始化方向梯度直方图描述子
self.hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector()) #设置支持向量机(Support Vector Machine)使得它成为一个预先训练好了的行人检测器
self.font = cv2.FONT_HERSHEY_SIMPLEX
self.IsExit = False
self.dir_temp = os.path.join(sys.path[0] “temp“)
self.dir_people = os.path.join(sys.path[0] “people“)
self.dir_hat = os.path.join(sys.path[0] “hat“)
self.dir_empty = os.path.join(sys.path[0] “empty“)
self.dir_head = os.path.join(sys.path[0] “head“)
self.bug_list = []
#创建临时目录
if not os.path.exists(self.dir_temp): os.makedirs(self.dir_temp)
if not os.path.exists(self.dir_people): os.makedirs(self.dir_people)
if not os.path.exists(self.dir_hat): os.makedirs(self.dir_hat)
if not os.path.exists(self.dir_temp): os.makedirs(self.dir_temp)
if not os.path.exists(self.dir_empty): os.makedirs(self.dir_empty)
if not os.path.exists(self.dir_head): os.makedirs(self.dir_head)
#获取视频流的地址
def getframes(self):
#工地摄像头
#capture = cv2.VideoCapture(get_video_address.get_video_url())
#本地摄像头
#capture = cv2.VideoCapture(0)
#本地文件
capture = FileVideoStream(os.path.join(sys.path[0]‘test01.ts‘)).start()
#print(capture.isOpened())
return capture
#获取行人
def get_people(selfframesmall_frame):
#检测行人
(rects weights) = self.hog.detectMultiScale(small_frame winStride=(8 8) padding=(8 8) scale=1.15)
rects = np.array([[x y x + w y + h] for (x y w h) in rects])
index = 0
offset_x = float(frame.shape[0]) / float(small_frame.shape[0])
offset_y = float(frame.shape[1]) / float(small_frame.shape[1])
print offset_xoffset_y
head = datetime.datetime.now().strftime(‘%Y_%m_%d_%H_%M_%S‘)
for (xywh) in rects:
if weights[index] <= 0.68: continue
#检测安全帽
face = self.get_safe_hat(small_frame[y:hx
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论