【发布时间】:2019-11-29 11:54:45
【问题描述】:
我第一次尝试使用 YOLO 对象检测,在此期间我在证明要编程的图像后出现类型错误。我正在使用 cv2.imread() 函数从 opencv 读取图像,并在经过一些图像处理后将其提供给 yolo,但出现“类型错误”。
我正在提供出现错误的代码图像:
def ocr_function(image):
start = time()
try:
ocr_threshold = 0.4
ocr_weights = b'data/ocr/ocr-net.weights'
ocr_netcfg = b'data/ocr/ocr-net.cfg'
ocr_dataset = b'data/ocr/ocr-net.data'
ocr_net = dn.load_net(ocr_netcfg, ocr_weights, 0)
ocr_meta = dn.load_meta(ocr_dataset)
print("performing OCR at: ", os.getcwd())
print("\tScanning %s" %image)
image = cv2.imread(image_path)
image = preprocess(image)
show(image, "provided image")
R,(width,height) = detect(ocr_net, ocr_meta, image, thresh=ocr_threshold, nms=None)
if len(R):
L = dknet_label_conversion(R,width,height)
L = nms(L,.45)
L.sort(key=lambda x: x.tl()[0])
lp_str = ''.join([chr(l.cl()) for l in L])
print ('\t\tLP: %s' % lp_str)
我收到了这个错误:
Traceback (most recent call last):
File "<ipython-input-1-c25d751af85c>", line 86, in ocr_function
R,(width,height) = detect(ocr_net, ocr_meta, imageROT, thresh=ocr_threshold, nms=None)
File "/home/infinity/Desktop/NEW ALPR/LPD/darknet/python/darknet.py", line 126, in detect
im = load_image(image, 0, 0)
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type
【问题讨论】:
-
发布代码而不是截图
-
我编辑了问题并在给出代码后重新发布。
-
当您将图像作为
detect的参数传递时,图像的类型是什么。我的意思是print(type(image))的输出是什么 -
使用 cv2 读取图像后,类型为 ndarray,即
。 -
预处理步骤之后?
标签: python opencv object-detection yolo