我正在尝试遵循以下代码中的相同步骤,以学习如何使用Yolo https://www.arunponnusamy.com/yolo-object-detection-openCV-python.html进行对象检测。我正在使用Python 2.7
。运行这部分代码后,我收到此错误:
AttributeError: 'module' object has no attribute 'readNet'
我真的需要您的帮助来解决此错误
import cv2
import argparse
import numpy as np
ap = argparse.ArgumentParser()
ap.add_argument('-i', '--image', required=False,default='D:/darknet/data/dog.jpg',help = 'path to input image')
ap.add_argument('-c', '--config',required=False,default='D:/darknet/cfg/yolov3.cfg',help = 'path to yolo config file')
ap.add_argument('-w', '--weights', required=False,default='D:/darknet/yolov3.weights',
help = 'path to yolo pre-trained weights')
ap.add_argument('-cl', '--classes', required=False,default='D:/darknet/yolov3.txt',
help = 'path to text file containing class names')
args = ap.parse_args()
image = cv2.imread(args.image)
Width = image.shape[1]
Height = image.shape[0]
scale = 0.00392
classes = None
with open(args.classes, 'r') as f:
classes = [line.strip() for line in f.readlines()]
COLORS = np.random.uniform(0, 255, size=(len(classes), 3))
net = cv2.dnn.readNet(args.weights, args.config)
blob = cv2.dnn.blobFromImage(image, scale, (416,416), (0,0,0), True,crop=False)
net.setInput(blob)