使用YOLOv2和MobileNet_SSD检测算法与KCF对象跟踪器进行视频流的实时对象跟踪和检测

微信公众号:小白图像与视觉

关于技术、关注yysilence00。有问题或建议,请公众号留言。


主题:使用YOLOv2和MobileNet_SSD检测算法与KCF对象跟踪器进行视频流的实时对象跟踪和检测

1、版本:opencv3.4.1 numpy imutils

2、载权重并将其放置在model_data /中

3、项目结构:

  • media:存放视频文件
  • misc:存放结构文件动图
  • model_data:存放模型文件,这里使用coco和mobilenet数据集进行训练和测试,利用caffe框架进行网络参数训练获取模型
  • out:存放结果
  • src:存放源码

使用方法:先cd到项目文件中路径中,然后执行

python src/main.py -h
usage: main.py [-h] [--input INPUT] [--output OUTPUT] --model MODEL
               [--config CONFIG] [--classes CLASSES] [--thr THR]

Object Detection and Tracking on Video Streams

optional arguments:
  -h, --help         show this help message and exit
  --input INPUT      Path to input image or video file. Skip this argument to
                     capture frames from a camera.
  --output OUTPUT    Path to save output as video file. Skip this argument if
                       you don't want the output to be saved. 
  --model MODEL      Path to a binary file of model that contains trained weights.
                     It could be a file with extensions .caffemodel (Caffe) or
                     .weights (Darknet)
  --config CONFIG    Path to a text file of model that contains network
                     configuration. It could be a file with extensions
                     .prototxt (Caffe) or .cfg (Darknet)
  --classes CLASSES  Optional path to a text file with names of classes to
                     label detected objects.
  --thr THR          Confidence threshold for detection. Default: 0.35

然后在终端执行:

- yolov2
usge0:python src/main.py --model model_data/yolov2.weights --config model_data/yolov2.cfg --classes model_data/coco_classes.txt --input media/sample_video.mp4 --output out/sample_output.avi

-mobilenet_ssd
usge1:python src/main.py --model model_data/MobileNetSSD_deploy.caffemodel --config model_data/MobileNetSSD_deploy.prototxt --classes model_data/MobileNet_classes.txt --input media/sample_video.mp4 --output out/sample_output.avi

4、带有KCF跟踪器的YOLOv2

5、带有KCF跟踪器的MobileNet_SSD

6、完整项目代码

main.py
#usge0:python src/main.py --model model_data/yolov2.weights --config model_data/yolov2.cfg --classes model_data/coco_classes.txt --input media/sample_video.mp4 --output out/sample_output.avi
#usge1:python src/main.py --model model_data/MobileNetSSD_deploy.caffemodel --config model_data/MobileNetSSD_deploy.prototxt --classes model_data/MobileNet_classes.txt --input media/sample_video.mp4 --output out/sample_output.avi

"""
Author: Apoorva Vinod Gorur
Email: apoorva.v94@gmail.com

update Vesion:
Author: YanYong
Email: yanyong.email@gmail.com

"""


import cv2 as cv
import argparse
import sys
import numpy as np
import time
from copy import deepcopy
import imutils
from object_detection import object_detector

#绘制预测框图
def drawPred(frame, objects_detected):

    objects_list = list(objects_detected.keys())

    for object_, info in objects_detected.items():
        box = info[0]
        confidence = info[1]
        label = '%s: %.2f' % (object_, confidence)
        p1 = (int(box[0]), int(box[1]))
        p2 = (int(box[0] + box[2]), int(box[1] + box[3]))
        #p1=(x=box[0],y=box[1])是矩阵左上点的坐标,w=box[2],h=box[3]是矩阵的宽和高  p2 =(box[0] + box[2]), int(box[1] + box[3])为右下角坐标
        cv.rectangle(frame, p1, p2, (<
  • 2
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值