行人检测:YOLO v4
行人跟踪:SORT
行人距离估计:IPM 逆透视映射
项目运行代码
from IPython.display import display, Javascript, Image
from base64 import b64decode, b64encode
import os
import cv2
import numpy as np
import PIL
import io
import html
import time
import matplotlib.pyplot as plt
%matplotlib inline
%cd darknet
!sed -i 's/OPENCV=0/OPENCV=1/' Makefile
!sed -i 's/GPU=0/GPU=1/' Makefile
!sed -i 's/CUDNN=0/CUDNN=1/' Makefile
!sed -i 's/CUDNN_HALF=0/CUDNN_HALF=1/' Makefile
!sed -i 's/LIBSO=0/LIBSO=1/' Makefile
# 导入 Darknet 函数来执行对象检测
from darknet2 import *
# 载入 YOLOv4 架构
network, class_names, class_colors = load_network("cfg/yolov4.cfg", "cfg/coco.data", "/openbayes/input/input0/DeepSocial.weights")
width = network_width(network)
height = network_height(network)
# 在图像上运行 Darknet helper 函数
def darknet_helper(img, width, height):
darknet_image = make_image(width, height, 3)
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img_resized = cv2.resize(img_rgb, (width, height),
interpolation=cv2.INTER_LINEAR)
# 获取图像比例,将边界框转换为适当的尺寸
img_height, img_width, _ = img.shape
width_ratio = img_width/width
height_ratio = img_height/height
# 运行 Darknet 模型
copy_image_from_bytes(darknet_image, img_resized.tobytes())
detections = detect_image(network, class_names, darknet_image)
free_image(darknet_image)
return detections, width_ratio, height_ratio
!pip install filterpy
from sort import *
mot_tracker = Sort(max_age=25, min_hits=4, iou_threshold=0.3)
Input = "/openbayes/input/input1/OxfordTownCentreDataset.avi"
ReductionFactor = 2
calibration = [[180,162],[618,0],[552,540],[682,464]]
分享
点收藏
点点赞
点在看
文章转发自AI科技大本营微信公众号,版权归其所有。文章内容不代表本站立场和任何投资暗示。
Copyright © 2021.Company 元宇宙YITB.COM All rights reserved.元宇宙YITB.COM