搭建 darkflow与 sort/deep_sort 环境


修改 darkflow/net/yolov2/predict.py

import numpy as np
import math
import cv2
import os
import json
import csv
#from scipy.special import expit
#from utils.box import BoundBox, box_iou, prob_compare
#from utils.box import prob_compare2, box_intersection
from ...utils.box import BoundBox
from ...cython_utils.cy_yolo2_findboxes import box_constructor#########################################
id_list = []
blist = []
clist = []loc_dic={}
in_count = 0 #in 计数器
out_count = 0 #out 计数器
######################################### ds = True
try :from deep_sort.application_util import preprocessing as prepfrom deep_sort.application_util import visualizationfrom deep_sort.deep_sort.detection import Detection
except :ds = Falsedef expit(x):return 1. / (1. + np.exp(-x))def _softmax(x):e_x = np.exp(x - np.max(x))out = e_x / e_x.sum()return outdef findboxes(self, net_out):# metameta = self.metaboxes = list()boxes=box_constructor(meta,net_out)return boxesdef extract_boxes(self,new_im):cont = []new_im=new_im.astype(np.uint8)ret, thresh=cv2.threshold(new_im, 127, 255, 0)p, contours, hierarchy=cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)for i in range(0, len(contours)):cnt=contours[i]x, y, w, h=cv2.boundingRect(cnt)if w*h > 30**2 and ((w < new_im.shape[0] and h <= new_im.shape[1]) or (w <= new_im.shape[0] and h < new_im.shape[1])):if self.FLAGS.tracker == "sort":cont.append([x, y, x+w, y+h])else : cont.append([x, y, w, h])return contdef postprocess(self,net_out, im,frame_id = 0,csv_file=None,csv=None,mask = None,encoder=None,tracker=None):"""Takes net output, draw net_out, save to disk"""boxes = self.findboxes(net_out)# metameta = self.metanms_max_overlap = 0.1threshold = meta['thresh']colors = meta['colors']labels = meta['labels']if type(im) is not np.ndarray:imgcv = cv2.imread(im)else: imgcv = imh, w, _ = imgcv.shapethick = int((h + w) // 300)resultsForJSON = []
######################################### global id_listglobal blistglobal clisetglobal in_countglobal out_countcv2.line(imgcv, (int(w/2), int(0)),(int(w/2) ,int(h)), (255,255,255))cv2.putText(imgcv, "in number:" + str(int(in_count)),(10, 40), 0, 1e-3 * h, (255,0,0),2)cv2.putText(imgcv, "out number:" + str(int(out_count)),(10, 60),0, 1e-3 * h, (255,0,0),2)
######################################### if not self.FLAGS.track :for b in boxes:boxResults = self.process_box(b, h, w, threshold)if boxResults is None:continueleft, right, top, bot, mess, max_indx, confidence = boxResultsif self.FLAGS.json:resultsForJSON.append({"label": mess, "confidence": float('%.2f' % confidence), "topleft": {"x": left, "y": top}, "bottomright": {"x": right, "y": bot}})continueif self.FLAGS.display or self.FLAGS.saveVideo:cv2.rectangle(imgcv,(left, top), (right, bot),colors[max_indx], thick)cv2.putText(imgcv, mess, (left, top - 12),0, 1e-3 * h, colors[max_indx],thick//3)else :if not ds :print("ERROR : deep sort or sort submodules not found for tracking please run :")print("\tgit submodule update --init --recursive")print("ENDING")exit(1)detections = []scores = []for b in boxes:boxResults = self.process_box(b, h, w, threshold)if boxResults is None:continueleft, right, top, bot, mess, max_indx, confidence = boxResultsif mess not in self.FLAGS.trackObj :continueif self.FLAGS.tracker == "deep_sort":detections.append(np.array([left,top,right-left,bot-top]).astype(np.float64))scores.append(confidence)elif self.FLAGS.tracker == "sort":detections.append(np.array([left,top,right,bot]).astype(np.float64))if len(detections) < 3  and self.FLAGS.BK_MOG:detections = detections + extract_boxes(self,mask)detections = np.array(detections)if detections.shape[0] == 0 :return imgcvif self.FLAGS.tracker == "deep_sort":scores = np.array(scores)features = encoder(imgcv, detections.copy())detections = [Detection(bbox, score, feature) for bbox,score, feature inzip(detections,scores, features)]# Run non-maxima suppression.boxes = np.array([d.tlwh for d in detections])scores = np.array([d.confidence for d in detections])indices = prep.non_max_suppression(boxes, nms_max_overlap, scores)detections = [detections[i] for i in indices]tracker.predict()tracker.update(detections)trackers = tracker.trackselif self.FLAGS.tracker == "sort":trackers = tracker.update(detections)for track in trackers:if self.FLAGS.tracker == "deep_sort":if not track.is_confirmed() or track.time_since_update > 1:continuebbox = track.to_tlbr()id_num = str(track.track_id)
#########################################        id_list.append(id_num)blist = list(set(id_list))clist = sorted([int(i) for i in blist])
#########################################                                              elif self.FLAGS.tracker == "sort":bbox = [int(track[0]),int(track[1]),int(track[2]),int(track[3])]id_num = str(int(track[4]))if self.FLAGS.csv:csv.writerow([frame_id,id_num,int(bbox[0]),int(bbox[1]),int(bbox[2])-int(bbox[0]),int(bbox[3])-int(bbox[1])])                    csv_file.flush()
#########################################if id_num in loc_dic:#判断上一帧运动轨迹#向右运动,且经过分界线#print("###########")if bbox[0] > loc_dic[id_num] and (bbox[0] > float(w/2) and loc_dic[id_num] < float(w/2)):print("##################in one##################")loc_dic[id_num] = bbox[0]in_count = in_count + 1#向左移动,且经过分解线    elif bbox[0] < loc_dic[id_num] and (bbox[0] < float(w/2) and loc_dic[id_num] > float(w/2)):print("##################out_one#################")loc_dic[id_num] = bbox[0]out_count = out_count + 1if in_count > 0 :    in_count = in_count - 1else:loc_dic[id_num] = bbox[0]
#########################################                                           if self.FLAGS.display or self.FLAGS.saveVideo:cv2.rectangle(imgcv, (int(bbox[0]), int(bbox[1])), (int(bbox[2]), int(bbox[3])),(255,255,255), thick//3)cv2.putText(imgcv, id_num,(int(bbox[0]), int(bbox[1]) - 12),0, 1e-3 * h, (255,255,255),thick//6)cv2.putText(imgcv, 'current  number: '+ str(int(len(clist) - out_count)),(10, 20),0, 1e-3 * h, (255,0,0),2)return imgcv

原理就是使用Opencv3画线,然后根据追踪物体 boundingbox 中心点坐标判断前后帧位置变化与这条线的关联,如果前后帧的中心点坐标在线的两边,说明有人员进出,效果图如下:

基于深度学习的视频检测(六) 行人计数,监控视频人员管理相关推荐

  1. 基于深度学习的目标检测和改进的监控视频异常检测

    在这个快速处理的世界里,我们需要具有最大精度的快速处理程序.这可以通过将计算机视觉与优化的深度学习模型和神经网络连接起来来实现. 这个项目的目标是建立一个人工智能系统,该系统将闭路电视实时摄像头馈送作 ...

  2. CV:基于深度学习实现目标检测之GUI界面产品设计并实现图片识别、视频识别、摄像头识别(准确度非常高)

    CV:基于深度学习实现目标检测之GUI界面产品设计并实现图片识别.视频识别.摄像头识别(准确度非常高) 目录 GUI编程设计界面 产品演示 GUI编程设计界面 产品演示 视频演示:https://bl ...

  3. 一种基于深度学习的目标检测提取视频图像关键帧的方法

    摘要:针对传统的关键帧提取方法误差率高.实时性差等问题,提出了一种基于深度学习的目标检测提取视频图像关键帧的方法,分类提取列车头部.尾部及车身所在关键帧.在关键帧提取过程中,重点研究了基于SIFT特征 ...

  4. 病虫害模型算法_基于深度学习的目标检测算法综述

    sigai 基于深度学习的目标检测算法综述 导言 目标检测的任务是找出图像中所有感兴趣的目标(物体),确定它们的位置和大小,是机器视觉领域的核心问题之一.由于各类物体有不同的外观,形状,姿态,加上成像 ...

  5. 基于深度学习的目标检测算法综述(一)

    基于深度学习的目标检测算法综述(一) 基于深度学习的目标检测算法综述(二) 基于深度学习的目标检测算法综述(三) 本文内容原创,作者:美图云视觉技术部 检测团队,转载请注明出处 目标检测(Object ...

  6. 基于深度学习的花卉检测与识别系统(YOLOv5清新界面版,Python代码)

    摘要:基于深度学习的花卉检测与识别系统用于常见花卉识别计数,智能检测花卉种类并记录和保存结果,对各种花卉检测结果可视化,更加方便准确辨认花卉.本文详细介绍花卉检测与识别系统,在介绍算法原理的同时,给出 ...

  7. 学习笔记之——基于深度学习的目标检测算法

    国庆假期闲来无事~又正好打算入门基于深度学习的视觉检测领域,就利用这个时间来写一份学习的博文~本博文主要是本人的学习笔记与调研报告(不涉及商业用途),博文的部分来自我团队的几位成员的调研报告(由于隐私 ...

  8. 基于深度学习的目标检测论文综述Paper Reading:A Survey of Deep Learning-based Object Detection(中文)

    摘要 介绍了文章的大致思路和结构: 1.介绍,经典的目标检测算法,数据集 2.分析比对,各种目标检测算法,包括一阶段和两阶段的 3.介绍,传统和新的应用,以及一些目标检测的其他分支 4.讨论,用目前这 ...

  9. 基于深度学习的口罩检测系统(Python+清新界面+数据集)

    摘要:口罩检测系统用于日常生活中检测行人是否规范佩戴口罩,利用深度学习算法可实现图片.视频.连接摄像头等方式的口罩检测,另外支持和结果可视化.在介绍算法原理的同时,给出Python的实现代码以及PyQ ...

  10. 基于深度学习的瓶子检测软件(UI界面+YOLOv5+训练数据集)

    摘要:基于深度学习的瓶子检测软件用于自动化瓶子检测与识别,对于各种场景下的塑料瓶.玻璃瓶等进行检测并计数,辅助计算机瓶子生产回收等工序.本文详细介绍深度学习的瓶子检测软件,在介绍算法原理的同时,给出P ...

最新文章

  1. Chrome DevTools 之 Network,网络加载分析利器
  2. azure kinect三维点云_万众期待的 【三维点云处理】 课程来啦!
  3. 双机热备份和负载均衡的区别
  4. iOS LLDB console debug总结
  5. mvvm模式和mvc的区别_MVC,MVVM,MVP是指什么,它们之间有啥区别
  6. 实现自己的控制层do-c (仿Struts2和SpringMVC)(六)
  7. 你想面试运维看一下你合格了吗?
  8. BZOJ3450 Easy
  9. 工大瑞普Dynamips使用教程图解(傻瓜版)
  10. Vue开发实例(03)之Vue项目引入element_ui
  11. Connection: keep-alive——[HTTP权威指南]摘录
  12. 在Python中安装了graphvize还出现报错:ExecutableNotFound: failed to execute ‘dot‘, make sure the Graphviz execut
  13. 大数据导论习题_《大数据导论(通识课版)》.PDF
  14. TCP/IP五层模型
  15. Error:间接寻址级别不同——C++真的魔鬼
  16. python数据中元素可以改变的是_下列Python数据中其元素可以改变的是( )。 (2.0分)_学小易找答案...
  17. 10.23训练赛补题
  18. 懒人数据库 MongoDB 5.x
  19. 转一篇Decorator模式的讲解文章
  20. 【Tanzu 社区版=TCE】 Mac 笔记本快速部署安装体验-(二)

热门文章

  1. 博物馆RFID资产管理解决方案-RFID资产防盗管理-新导智能
  2. TrOCR:基于Transformer的新一代光学字符识别
  3. 政务大数据共享面临的难题,我们应该如何破解?
  4. powerbi与mysql_PowerBI中的数据连接和导入
  5. java设计模式 23种设计模式和思想
  6. 重头开始学“程序员的数学”
  7. VUE 项目落地页使用 LinkedME 深度链接服务跳回App
  8. 通过运营技能地图使用Python整理用户指标及订单跟踪
  9. Ubuntu中常用的解/压缩命令
  10. 腾讯云2020,产业级数字化生态协同势能更强大