alpr-unconstrained icon indicating copy to clipboard operation
alpr-unconstrained copied to clipboard

ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type

Open edgarscr opened this issue 5 years ago • 8 comments

I need help with a bug some one can help me?

image

layer     filters    size              input                output
    0 conv     32  3 x 3 / 1   240 x  80 x   3   ->   240 x  80 x  32  0.033 BFLOPs
    1 max          2 x 2 / 2   240 x  80 x  32   ->   120 x  40 x  32
    2 conv     64  3 x 3 / 1   120 x  40 x  32   ->   120 x  40 x  64  0.177 BFLOPs
    3 max          2 x 2 / 2   120 x  40 x  64   ->    60 x  20 x  64
    4 conv    128  3 x 3 / 1    60 x  20 x  64   ->    60 x  20 x 128  0.177 BFLOPs
    5 conv     64  1 x 1 / 1    60 x  20 x 128   ->    60 x  20 x  64  0.020 BFLOPs
    6 conv    128  3 x 3 / 1    60 x  20 x  64   ->    60 x  20 x 128  0.177 BFLOPs
    7 max          2 x 2 / 2    60 x  20 x 128   ->    30 x  10 x 128
    8 conv    256  3 x 3 / 1    30 x  10 x 128   ->    30 x  10 x 256  0.177 BFLOPs
    9 conv    128  1 x 1 / 1    30 x  10 x 256   ->    30 x  10 x 128  0.020 BFLOPs
   10 conv    256  3 x 3 / 1    30 x  10 x 128   ->    30 x  10 x 256  0.177 BFLOPs
   11 conv    512  3 x 3 / 1    30 x  10 x 256   ->    30 x  10 x 512  0.708 BFLOPs
   12 conv    256  3 x 3 / 1    30 x  10 x 512   ->    30 x  10 x 256  0.708 BFLOPs
   13 conv    512  3 x 3 / 1    30 x  10 x 256   ->    30 x  10 x 512  0.708 BFLOPs
   14 conv     80  1 x 1 / 1    30 x  10 x 512   ->    30 x  10 x  80  0.025 BFLOPs
   15 detection
mask_scale: Using default '1.000000'
Loading weights from data/ocr/ocr-net.weights...Done!
Performing OCR...
Traceback (most recent call last):
  File "license-plate-ocr.py", line 38, in <module>
    R,(width,height) = detect(ocr_net, ocr_meta, img_path ,thresh=ocr_threshold, nms=None)
  File "/home/pi/alpr-unconstrained/darknet/python/darknet.py", line 126, in detect
    im = load_image(image, 0, 0)
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type

edgarscr avatar Dec 06 '19 04:12 edgarscr

@edgarscr https://github.com/sergiomsilva/alpr-unconstrained/issues/22

im = load_image(image.encode('ascii'), 0, 0)

Sundrops avatar Dec 16 '19 06:12 Sundrops

Are you trying to use Python 3.x? Darknet demands that every string is encoded and in Python 3 you must encode using b before "text" or str.encode(text) for variables.

For instance, if you have: weights = "ex.weights" cfg = "ex.cfg" You must add b like this: weights = b"ex.weights" cfg = b"ex.cfg"

And if you have a variable live img_path, you must pass str.encode(img_path) to Darknet's detect function.

lucassfer avatar Dec 16 '19 13:12 lucassfer

After i setup i dont get any bug, but my result always the same:

image

edgarscr avatar Dec 16 '19 22:12 edgarscr

Did it detect a vehicle? Did you test it on another image?

lucassfer avatar Dec 16 '19 22:12 lucassfer

i test alot of images i use directly "license-plate-ocr" file

import sys
import cv2
import numpy as np
import traceback

import darknet.python.darknet as dn

from os.path 				import splitext, basename
from glob					import glob
from darknet.python.darknet import detect
from src.label				import dknet_label_conversion
from src.utils 				import nms

if __name__ == '__main__':
	try:
		ocr_threshold = .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)
		
		img_path = b'samples/test/03025.jpg'

		print ('Performing OCR...')

		bname = basename(splitext(img_path)[0])

		R,(width,height) = detect(ocr_net, ocr_meta, img_path ,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])
			
			with open('bmw.txt', 'w') as f:
				f.write(lp_str + '\n')

			print ('\t\tLP: %s' % lp_str)
		else:

			print ('No characters found')
	except:
		traceback.print_exc()
		sys.exit(1)

	sys.exit(0)

edgarscr avatar Dec 16 '19 22:12 edgarscr

You must run the run.sh script file, not license-plate-ocr.py directly. The OCR-net expects a image of the LP, not a image of the scenario. So it must first detect the vehicle, then the LP and finally it does character recognition. If you run the .sh file like the README indicates, it probably won't have any problems with that image.

Em seg., 16 de dez. de 2019 às 19:25, Edgar Carrera < [email protected]> escreveu:

i test alot of images i use directly "license-plate-ocr" file

import sys import cv2 import numpy as np import traceback

import darknet.python.darknet as dn

from os.path import splitext, basename from glob import glob from darknet.python.darknet import detect from src.label import dknet_label_conversion from src.utils import nms

if name == 'main': try: ocr_threshold = .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)
  
  img_path = b'samples/test/03025.jpg'

  print ('Performing OCR...')

  bname = basename(splitext(img_path)[0])

  R,(width,height) = detect(ocr_net, ocr_meta, img_path ,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])
  	
  	with open('bmw.txt', 'w') as f:
  		f.write(lp_str + '\n')

  	print ('\t\tLP: %s' % lp_str)
  else:

  	print ('No characters found')

except: traceback.print_exc() sys.exit(1)

sys.exit(0)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/sergiomsilva/alpr-unconstrained/issues/106?email_source=notifications&email_token=AGCEQCACAWKVXZNQTHZUJMLQY7553A5CNFSM4JWLABG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHAKPNY#issuecomment-566273975, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGCEQCDQSI2AEJYR2X5AV4DQY7553ANCNFSM4JWLABGQ .

-- Lucas de Sousa Fernandes *Desenvolvedor de Software * GREat (UFC)

lucassfer avatar Dec 16 '19 22:12 lucassfer

@lucasfernandes42 I tried what you suggested, ran the ru.sh script file. But it is still not detecting vehicle and so no LP and Number. There were no error raised. Screenshot from 2020-02-04 17-04-09

mayurmahurkar avatar Feb 04 '20 11:02 mayurmahurkar

我也遇到了这个问题,请问你解决了吗 I also encountered this problem, have you solved it

linnnff avatar Jul 17 '20 09:07 linnnff