# -*- coding: utf-8 -*-# @time : 18-10-26 下午4:47# @author : xugaoxiang# @email : djstava@gmail.com# @website : https://xugaoxiang.com# @file : opencv_yolov3.py# @software: PyCharm# Usage example: python3 opencv_yolov3.py --image=test.pngimport sysimport cv2import argparseimport numpy as npimport os.path# 参数初始化# 相似度阈值confThreshold = 0.5 # Confidence threshold# NMS算法阈值nmsThreshold = 0.4# 输入图片的宽和高inpWidth = 416 inpHeight = 416parser = argparse.ArgumentParser(description = 'Object detection using YOLOv3 in opencv')
parser.add_argument('--image', help = 'Path to image file.')
args = parser.parse_args()# 导入物体类别class文件,默认支持80种classesFile = "coco.names"classes = Nonewith open(classesFile, 'rt') as f :
classes = f.read().rstrip('\n').split('\n')# yolo v3的配置及weights文件modelConfiguration &