YOLOV3 基于OpenCV DNN 的目标检测实现

原文: YOLOV3 基于OpenCV DNN 的目标检测实现 - AIUAI

这里主要是对 基于 YOLOV3 和 OpenCV的目标检测(PythonC++)[译] Python 完整实现的整理.

基于 YOLOV3 和 OpenCV的目标检测(PythonC++) - AIUAI

OpenCV DNN支持图像分类、对象检测、图像分割常见通用网络模型.

OpenCV4.X - DNN模块 Python APIs - AIUAI

1. YOLOV3 简述

OpenCV4.0如何跑YOLOv3对象检测模型 - OpenCV学堂

YOLOV3 网络结构如图:

image

YOLOV3 采用全卷积结构,有效减少了模型参数总数,取消了softmax层,模型输出结构如图:

image

2. YOLOV3 DNN 实现

模型下载:

# coco.names
wget https://github.com/pjreddie/darknet/blob/master/data/coco.names?raw=true -O ./coco.names

# YOLOV3
wget https://github.com/pjreddie/darknet/blob/master/cfg/yolov3.cfg?raw=true -O ./yolov3.cfg
wget https://pjreddie.com/media/files/yolov3.weights

# YOLOV3-tiny
wget https://github.com/pjreddie/darknet/blob/master/cfg/yolov3-tiny.cfg
wget https://pjreddie.com/media/files/yolov3-tiny.weights

完整实现:

#!/usr/bin/python3
# -*- coding: utf-8 -*-
import cv2
import sys
import numpy as np
import os
import matplotlib.pyplot as plt
import time


class general_yolov3(object):
    def __init__(self, modelpath, is_tiny=False):
        self.conf_threshold = 0.5  # Confidence threshold
        self.nms_threshold  = 0.4  # NMS threshold
        self.net_width  = 416      # 网络输入图像宽度
        self.net_height = 416      # 网络输入图像高度

        self.classes = self.get_coco_names()
        self.yolov3_model = self.get_yolov3_model(modelpath, is_tiny)
        self.outputs_names = self.get_outputs_names()


    def get_coco_names(self):
        # COCO 物体类别名
        classesFile = "/path/to/coco.names"
        classes = None
        with open(classesFile, 'rt') as f:
            classes = f.read().rstrip('\n').split('\n')

        return classes


    def get_yolov3_model(self, modelpath, is_tiny):
        if is_tiny:
            cfg_file = os.path.join(modelpath, "yolov3-tiny.cfg
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值