er 不是二 我故意的!别讲我二。留言二的那个,你别跑!

人脸识别demo完成,搞一搞yolov5+deepsort

环境还是上个环境,装了就没问题

直接上百度盘链接

链接:https://pan.baidu.com/s/16q3wOgZ4zGqkEkAzVmk2Mw 
提取码:yolo 
代码,模型,数据都有,下载下来直接run  mian.py就行

import numpy as npimport tracker
from detector import Detector
import cv2if __name__ == '__main__':# 根据视频尺寸,填充一个polygon,供撞线计算使用mask_image_temp = np.zeros((1080, 1920), dtype=np.uint8)# 初始化2个撞线polygonlist_pts_blue = [[204, 305], [227, 431], [605, 522], [1101, 464], [1900, 601], [1902, 495], [1125, 379], [604, 437],[299, 375], [267, 289]]ndarray_pts_blue = np.array(list_pts_blue, np.int32)polygon_blue_value_1 = cv2.fillPoly(mask_image_temp, [ndarray_pts_blue], color=1)polygon_blue_value_1 = polygon_blue_value_1[:, :, np.newaxis]# 填充第二个polygonmask_image_temp = np.zeros((1080, 1920), dtype=np.uint8)list_pts_yellow = [[181, 305], [207, 442], [603, 544], [1107, 485], [1898, 625], [1893, 701], [1101, 568],[594, 637], [118, 483], [109, 303]]ndarray_pts_yellow = np.array(list_pts_yellow, np.int32)polygon_yellow_value_2 = cv2.fillPoly(mask_image_temp, [ndarray_pts_yellow], color=2)polygon_yellow_value_2 = polygon_yellow_value_2[:, :, np.newaxis]# 撞线检测用mask,包含2个polygon,(值范围 0、1、2),供撞线计算使用polygon_mask_blue_and_yellow = polygon_blue_value_1 + polygon_yellow_value_2# 缩小尺寸,1920x1080->960x540polygon_mask_blue_and_yellow = cv2.resize(polygon_mask_blue_and_yellow, (960, 540))# 蓝 色盘 b,g,rblue_color_plate = [255, 0, 0]# 蓝 polygon图片blue_image = np.array(polygon_blue_value_1 * blue_color_plate, np.uint8)# 黄 色盘yellow_color_plate = [0, 255, 255]# 黄 polygon图片yellow_image = np.array(polygon_yellow_value_2 * yellow_color_plate, np.uint8)# 彩色图片(值范围 0-255)color_polygons_image = blue_image + yellow_image# 缩小尺寸,1920x1080->960x540color_polygons_image = cv2.resize(color_polygons_image, (960, 540))# list 与蓝色polygon重叠list_overlapping_blue_polygon = []# list 与黄色polygon重叠list_overlapping_yellow_polygon = []# 进入数量down_count = 0# 离开数量up_count = 0font_draw_number = cv2.FONT_HERSHEY_SIMPLEXdraw_text_postion = (int(960 * 0.01), int(540 * 0.05))# 初始化 yolov5detector = Detector()# 打开视频capture = cv2.VideoCapture('./video/test.mp4')# capture = cv2.VideoCapture('/mnt/datasets/datasets/towncentre/TownCentreXVID.avi')while True:# 读取每帧图片_, im = capture.read()if im is None:break# 缩小尺寸,1920x1080->960x540im = cv2.resize(im, (960, 540))list_bboxs = []bboxes = detector.detect(im)# 如果画面中 有bboxif len(bboxes) > 0:list_bboxs = tracker.update(bboxes, im)# 画框# 撞线检测点,(x1,y1),y方向偏移比例 0.0~1.0output_image_frame = tracker.draw_bboxes(im, list_bboxs, line_thickness=None)passelse:# 如果画面中 没有bboxoutput_image_frame = impass# 输出图片output_image_frame = cv2.add(output_image_frame, color_polygons_image)if len(list_bboxs) > 0:# ----------------------判断撞线----------------------for item_bbox in list_bboxs:x1, y1, x2, y2, label, track_id = item_bbox# 撞线检测点,(x1,y1),y方向偏移比例 0.0~1.0y1_offset = int(y1 + ((y2 - y1) * 0.6))# 撞线的点y = y1_offsetx = x1if polygon_mask_blue_and_yellow[y, x] == 1:# 如果撞 蓝polygonif track_id not in list_overlapping_blue_polygon:list_overlapping_blue_polygon.append(track_id)pass# 判断 黄polygon list 里是否有此 track_id# 有此 track_id,则 认为是 外出方向if track_id in list_overlapping_yellow_polygon:# 外出+1up_count += 1print(f'类别: {label} | id: {track_id} | 上行撞线 | 上行撞线总数: {up_count} | 上行id列表: {list_overlapping_yellow_polygon}')# 删除 黄polygon list 中的此idlist_overlapping_yellow_polygon.remove(track_id)passelse:# 无此 track_id,不做其他操作passelif polygon_mask_blue_and_yellow[y, x] == 2:# 如果撞 黄polygonif track_id not in list_overlapping_yellow_polygon:list_overlapping_yellow_polygon.append(track_id)pass# 判断 蓝polygon list 里是否有此 track_id# 有此 track_id,则 认为是 进入方向if track_id in list_overlapping_blue_polygon:# 进入+1down_count += 1print(f'类别: {label} | id: {track_id} | 下行撞线 | 下行撞线总数: {down_count} | 下行id列表: {list_overlapping_blue_polygon}')# 删除 蓝polygon list 中的此idlist_overlapping_blue_polygon.remove(track_id)passelse:# 无此 track_id,不做其他操作passpasselse:passpasspass# ----------------------清除无用id----------------------list_overlapping_all = list_overlapping_yellow_polygon + list_overlapping_blue_polygonfor id1 in list_overlapping_all:is_found = Falsefor _, _, _, _, _, bbox_id in list_bboxs:if bbox_id == id1:is_found = Truebreakpasspassif not is_found:# 如果没找到,删除idif id1 in list_overlapping_yellow_polygon:list_overlapping_yellow_polygon.remove(id1)passif id1 in list_overlapping_blue_polygon:list_overlapping_blue_polygon.remove(id1)passpasslist_overlapping_all.clear()pass# 清空listlist_bboxs.clear()passelse:# 如果图像中没有任何的bbox,则清空listlist_overlapping_blue_polygon.clear()list_overlapping_yellow_polygon.clear()passpasstext_draw = 'DOWN: ' + str(down_count) + \' , UP: ' + str(up_count)output_image_frame = cv2.putText(img=output_image_frame, text=text_draw,org=draw_text_postion,fontFace=font_draw_number,fontScale=1, color=(255, 255, 255), thickness=2)cv2.imshow('demo', output_image_frame)cv2.waitKey(1)passpasscapture.release()cv2.destroyAllWindows()

撞线对我目前来说没什么大用,但是考虑到后面可以做个电子围栏还是可以留下的。

detect.py

import torch
import numpy as npfrom models.experimental import attempt_load
from utils.datasets import letterbox
from utils.general import non_max_suppression, scale_coords
from utils.torch_utils import select_deviceclass Detector:def __init__(self):self.img_size = 640self.threshold = 0.3self.stride = 1self.weights = './weights/yolov5m.pt'self.device = '0' if torch.cuda.is_available() else 'cpu'self.device = select_device(self.device)model = attempt_load(self.weights, map_location=self.device)model.to(self.device).eval()model.half()self.m = modelself.names = model.module.names if hasattr(model, 'module') else model.namesdef preprocess(self, img):img0 = img.copy()img = letterbox(img, new_shape=self.img_size)[0]img = img[:, :, ::-1].transpose(2, 0, 1)img = np.ascontiguousarray(img)img = torch.from_numpy(img).to(self.device)img = img.half()img /= 255.0if img.ndimension() == 3:img = img.unsqueeze(0)return img0, imgdef detect(self, im):im0, img = self.preprocess(im)pred = self.m(img, augment=False)[0]pred = pred.float()pred = non_max_suppression(pred, self.threshold, 0.4)boxes = []for det in pred:if det is not None and len(det):det[:, :4] = scale_coords(img.shape[2:], det[:, :4], im0.shape).round()for *x, conf, cls_id in det:lbl = self.names[int(cls_id)]if lbl not in ['person', 'bicycle', 'car', 'motorcycle', 'bus', 'truck']:continuepassx1, y1 = int(x[0]), int(x[1])x2, y2 = int(x[2]), int(x[3])boxes.append((x1, y1, x2, y2, lbl, conf))return boxes

if lbl not in ['person', 'bicycle', 'car', 'motorcycle', 'bus', 'truck'] 我只需要检测人就行 留个person其余全删。

准备工作到此结束。后面就开始结合人脸识别

行人跟踪之身份识别(er)相关推荐

  1. 行人跟踪之身份识别(三)

    前两篇写了人脸识别和yolo+deepsort 这篇就写下两个方法的结合,在保持一定帧率的前提下进行身份识别和跟踪: 代码直接在yolo+deepsort下的main.py 修改,先备份一个main. ...

  2. 基于深度学习实现行人跟踪相关论文总结

    基于深度学习实现行人跟踪相关论文总结 [1] Recurrent YOLO and LSTM-based IR single pedestrian tracking 本文提出了一种基于空间监督的递归卷 ...

  3. 密集场景下的行人跟踪替代算法,头部跟踪算法 | CVPR 2021

    点击下方"AI算法与图像处理",一起进步!重磅干货,第一时间送达 报告链接:https://www.bilibili.com/video/BV1Ug411M7Kt/ https:/ ...

  4. 行人检测与重识别!SOTA算法

    行人检测与重识别!SOTA算法 A Simple Baseline for Multi-Object Tracking, Yifu Zhang, Chunyu Wang, Xinggang Wang, ...

  5. OWASP A7 Identification and Authentication Failures(身份识别和身份验证错误)

    Identification and Authentication Failures(身份识别和身份验证错误) 从 2017 的第二名下降到了 2021的第7名 我在 TOP1 中提出过水平越权和垂直 ...

  6. 2020电赛F题回顾——简易无接触温度测量与身份识别装置

    2020电赛F题回顾--简易无接触温度测量与身份识别装置 第一次参加电赛,已经大三了,这也有可能是我的最后一次,不禁感慨时间过得真快.在实验室一起奋斗的夜晚既辛苦又幸福,感谢陪伴在我身边一起做电赛的同 ...

  7. 硕士论文阅读——基于机器视觉和深度学习的工人安全帽检测与身份识别方法

    文章目录 零.摘要 一.绪论 1.背景与研究意义 2.国内外研究现状 (1)安全帽佩戴检测研究现状与不足 (2)身份识别研究现状与不足 (3)基于深度学习的目标检测 二.深度学习目标检测理论 1.卷积 ...

  8. 2020年TI杯电子设计大赛F题及2022年山西省电子设计大赛E题简易无接触温度测量与身份识别装置整体思路及代码

    在2022年山西省电子设计大赛选题刚刚公布的时候,我们组本来是想做电源题的,奈何学艺不精,最后转做了这道仪器仪表题,经过几天紧张的制作,写报告,最终也是获得了省一,想要代码和报告文档的可以私聊我或者从 ...

  9. 身份识别协议枚举工具ident-user-enum

    身份识别协议枚举工具ident-user-enum 身份识别协议(Ident protocol,IDENT)是一种Internet协议,用于识别使用特定TCP端口的用户身份.服务器开启该服务后,会默认 ...

最新文章

  1. [BZOJ4994] [Usaco2017 Feb]Why Did the Cow Cross the Road III(树状数组)
  2. Linux系统下MySQL数据库的备份和恢复
  3. 将数据转化为API,OpenDataSoft获540万美元A轮融资
  4. 三线调速风扇原理_学修电风扇~风机转速慢、调速失灵故障维修。
  5. 前端传递json,后端应该怎样接收呢?
  6. from mysql partition select_爬虫(九十九)mysql详解二
  7. Railgun工具箱HWID验证
  8. eclipse提交代码到github其他分支
  9. [NOI2016]优秀的拆分
  10. ssm项目从零到精通的超全解析(含项目源码)
  11. [CTF] 攻防世界MISC高手区部分题目WriteUp
  12. vbscript mysql_vbscript 数据库操作
  13. DNSPod十问顺丰科技唐恺:为什么顺丰快递那么快?
  14. 微信端视频播放时防止被浏览器劫持的问题
  15. Tableau参数:自定义周起始时间
  16. DB2数据库常见问题汇总
  17. 数据库的概念设计与逻辑设计
  18. 于晓津外头游荡了半天
  19. Sers微服务2.1.1
  20. UOS上扫描仪驱动笔记

热门文章

  1. 燃气管网在线监测系统方案
  2. 手游幻想神域服务器显示,幻想神域手游有黑边是怎么回事 屏幕旁边有黑边解决方法...
  3. js判断ipad还是安卓_JavaScript判断ios还是android系统
  4. 益智玩具不益智?这些才是真正能让孩子更聪明的益智玩具!
  5. 教你使用CDR绘制纸杯的扇形
  6. winform中英文切换(实测简单可用)
  7. 盲人的福音 FingerReader智能指环让盲人读电子书
  8. 【13】淘宝sdk——入门实战之header.php制作(一)
  9. android adb broadcast,adb shell am broadcast -a  -d
  10. RFC2616-HTTP1.1-Header Field Definitions(头字段规定部分—单词注释版)