"--char-classifier", required=True, help="path to the output character classifier") ap.add_argument("-d", "--digit-classifier", required=True, help="path to the output digit classifier") args = vars(ap.parse_args()) # load the character and digit classifiers charModel = cPickle.loads(open(args["char_classifier"]).read()) digitModel = cPickle.loads(open(args["digit_classifier"]).read()) # initialize the descriptor blockSizes = ((5, 5), (5, 10), (10, 5), (10, 10)) desc = BlockBinaryPixelSum(targetSize=(30, 15), blockSizes=blockSizes) # loop over the images for imagePath in sorted(list(paths.list_images(args["images"]))): # load the image print(imagePath[imagePath.rfind("/") + 1:]) image = cv2.imread(imagePath) # if the width is greater than 640 pixels, then resize the image if image.shape[1] > 640: image = imutils.resize(image, width=640) # initialize the license plate detector and detect the license plates and characters lpd = LicensePlateDetector(image, numChars=7) plates = lpd.detect()
help="path to the output digit classifier") args = vars(ap.parse_args()) # initialize characters string alphabet = "abcdefghijklmnopqrstuvwxyz0123456789" # initialize the data and labels for the alphabet and digits alphabetData = [] digitsData = [] alphabetLabels = [] digitsLabels = [] # initialize the descriptor print("[INFO] describing font examples...") blockSizes = ((5, 5), (5, 10), (10, 5), (10, 10)) desc = BlockBinaryPixelSum(targetSize=(30, 15), blockSizes=blockSizes) # loop over the font paths for fontPath in paths.list_images(args["fonts"]): # load the font image, convert it to grayscale and threshold it font = cv2.imread(fontPath) font = cv2.cvtColor(font, cv2.COLOR_BGR2GRAY) thresh = cv2.threshold(font, 128, 255, cv2.THRESH_BINARY_INV)[1] # detect contours in the thresholded image and sort them from left to right cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) cnts = cnts[0] if imutils.is_cv2() else cnts[1] cnts = sorted(cnts, key=lambda c: (cv2.boundingRect(c)[0] + cv2.boundingRect(c)[1]))