• 大小: 49.37MB
    文件类型: .7z
    金币: 1
    下载: 0 次
    发布日期: 2023-08-07
  • 语言: Python
  • 标签: yolo  检测  识别  跟踪  

资源简介

yolo3,目标检测、识别、跟踪, 人和车 都已经实现 程序入口是app.py 已在python 3.7 tensorflow 1.12.0上测试通过 详细说明请参照代码 里面有详细注释

资源截图

代码片段和文件信息

import os
from timeit import time
import sys
import cv2
import numpy as np
from PIL import Image
from yolo import YOLO

from application_util import preprocessing
from deep_sort import nn_matching
from deep_sort.detection import Detection
from deep_sort.tracker import Tracker
from tools import generate_detections as gdet
from deep_sort.detection import Detection as ddet

‘‘‘
This project does both detection and tracking of objects.
It utilizes the following project.
Tracker is based on: https://github.com/nwojke/deep_sort
Detector is based on: https://github.com/qqwweee/keras-yolo3
Just call detect_video to start the program.
Or just run py py app.py to see a demo.
Also you can refer to the usage example below.
@Params
yolo: Yolo detector object.
filename: filename of video to be detected
path: path of video to be detected
resize_flag: whether the video to be processed should be rescaled by half.
‘‘‘


def detect_video(yolo filename=‘‘ path=‘‘ resize_flag=False):
    # define video path
    fullpath = path + filename

    model_path = yolo.model_path
    model_name = model_path.split(‘/‘)[1][:-3]
    output_path = ‘‘
    if resize_flag == True:
        output_path = f‘output/resized-{model_name}‘
    else:
        output_path = f‘output/original-{model_name}‘
    # create output dir if not exist
    if not os.path.exists(output_path):
        os.makedirs(output_path)
    # Gating threshold for cosine distance
    max_cosine_distance = 0.2
    # Maximum size of the appearance descriptors
    nn_budget = None
    # Non-maxima suppression threshold
    nms_max_overlap = 1.0

    # deep_sort
    model_filename = ‘model_data/mars-small128.pb‘
    encoder = gdet.create_box_encoder(model_filename batch_size=1)

    metric = nn_matching.NearestNeighborDistanceMetric(
        “cosine“ max_cosine_distance nn_budget)
    tracker = Tracker(metric)

    writeVideo_flag = True

    video_capture = cv2.VideoCapture(fullpath)
    if writeVideo_flag:
        # Define the codec and create VideoWriter object
        w = int(video_capture.get(3))
        h = int(video_capture.get(4))
        if resize_flag == True:
            # default to resize by half
            w = int(w/2)
            h = int(h/2)
        fourcc = cv2.VideoWriter_fourcc(* ‘MJPG‘)
        # trim the filename to get rid of file extension
        filename = filename[:-4]
        # result output
        out = cv2.VideoWriter(
            f‘{output_path}/output-{filename}.avi‘ fourcc 15 (w h))
        # location of detected objects
        list_file = open(f‘{output_path}/detection-{filename}.txt‘ ‘w‘)
        # framerate of detection.
        fps_file = open(f‘{output_path}/framerate-{filename}.txt‘ ‘w‘)
        frame_index = -1

    fps = 0.0

    while True:
        ret frame = video_capture.read()  # frame shape 640*480*3
        if ret != True:
            break
        h w _ = frame.shape
        if resize_flag == True:
            frame = cv2.resize(frame (int(w/2) int(h/2))

评论

共有 条评论