资源简介
基于opencv的安全帽佩戴检测,开发语言采用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
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3998948 2018-07-17 18:16 test01.ts
文件 219097 2018-07-14 05:00 cascade-v2.5.xm
文件 10593 2018-07-24 10:45 safety_hat_detect2.py
----------- --------- ---------- ----- ----
4228638 3
相关资源
- Foundations of PyGTK Development_ GUI Creation
- Djangopython实现数据挖掘和分析.doc
- Python实现跟踪、光流、前景检测
- opencv_python-3.4.5 contrib-cp37-cp37m-win_amd
- opencv-contrib_python-3.4.2.16-cp37-amd64.zip
- OpenCV+3计算机视觉++Python语言实现 高清
- 基于python和pencv的车牌号码识别
- OpenCV3计算机视觉_Python语言实现 _刘波
- OpenCV3计算机视觉Python语言实现源代码
- opencv_python‑3.4.3‑cp37‑cp37m‑win_amd
- opencv_python-3.4.2-cp37-cp37m-win_amd64.whl
- OPENCV入门书籍:opencv3机器视觉Python语
- TensorflowOpenCV实现的CNN车牌识别代码
- opencv_python-3.4.3+contrib-cp35-cp35m-win_amd
- opencv_python-3.2.0-cp36-cp36m-win_amd64.whl25
- OpenCV3 计算机视觉 Python语言实现
- opencv_python-3.4.2.16-cp37-cp37m-win_amd64.wh
- 基于python的vgg网络学习,很基础但又
- Python-Ansible一个非常简单的IT自动化平
- opencv_python-2.4.13.2-cp27-cp27m-win_amd64.wh
- python2环境的opencv库
- opencv_python-3.3.0-cp35-cp35m-win_amd64.whl
- opencv_python-4.1.0.25-cp37-cp37m-win_amd64.wh
- simplecv实用机器视觉+OpenCV-Python-Totur
- opencv_python-4.1.2-cp37-cp37m-win_amd64.whl
- opencv-python 3.4.3.18
- opencv_python-3.4.2-cp36-cp36m-win_amd64.whl
- Computer Networking - A Top Down Approach 7th
- Django 2 Web Development Cookbook 3rd Edition.
- Python-Opencv自定义训练器识别任意物体
评论
共有 条评论