我第一次尝试使用YOLO对象检测,在此期间,在向程序证明图像后,我得到了类型错误。我正在使用cv2.imread()函数从opencv读取图像,并在经过一些图像处理后将其提供给yolo,但我收到了"Type Error“。
我提供了代码的图像,其中我得到了错误:
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发布于 2019-11-30 11:02:34
看起来load_image函数需要一个pointer to data array。
来自darknet库的detect函数的代码:
load_image = lib.load_image_color
load_image.argtypes = [c_char_p, c_int, c_int]
load_image.restype = IMAGE所以我建议你使用__arrayinterface__来传递数据数组。https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.interface.html
image_data = image.__array_interface__['data'][0]
R,(width,height) = detect(ocr_net, ocr_meta, image_data, thresh=ocr_threshold, nms=None)https://stackoverflow.com/questions/59104298
复制相似问题