Esempio n. 1
0
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i",
                "--images",
                required=True,
                help="path to the images to be classified")
args = vars(ap.parse_args())

# loop over the images
for imagePath in sorted(list(paths.list_images(args["images"]))):
    # load the image
    image = cv2.imread(imagePath)
    print(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 charactors
    lpd = LicensePlateDetector(image)
    plates = lpd.detect()

    # loop over the license plate regions and draw the bounding box surrounding the
    # license plate
    for lpBox in plates:
        lpBox = np.array(lpBox).reshape((-1, 1, 2)).astype(np.int32)
        cv2.drawContours(image, [lpBox], -1, (0, 255, 0), 2)

    # display the output image
    cv2.imshow("image", image)
    cv2.waitKey(0)
Esempio n. 2
0
# 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()

    # loop over the detected plages
    for (lpBox, chars) in plates:
        # initialize the text containing the recognized characters
        text = ""

        # loop over each character
        for (i, char) in enumerate(chars):
            # preprocess the character and describe it
            char = LicensePlateDetector.preprocessChar(char)
            features = desc.describe(char).reshape(1, -1)

            # if this is the first 3 characters, then use the character classifier
            if i < 3:
alphabetLabels = []
digitsLabels = []

# loop over the sample character paths
for samplePath in sorted(glob.glob(args["samples"] + "/*")):
	# extract the sample name, grab all images in the sample path, and sample them
	sampleName = samplePath[samplePath.rfind("/") + 1:]
	imagePaths = list(paths.list_images(samplePath))
	imagePaths = random.sample(imagePaths, min(len(imagePaths), args["min_samples"]))

	# loop over all images in the sample path
	for imagePath in imagePaths:
		# load the character, convert it to grayscale, preprocess it, and describe it
		char = cv2.imread(imagePath)
		char = cv2.cvtColor(char, cv2.COLOR_BGR2GRAY)
		char = LicensePlateDetector.preprocessChar(char)
		features = desc.describe(char)

		# check to see if we are examining a digit
		if sampleName.isdigit():
			digitsData.append(features)
			digitsLabels.append(sampleName)

		# otherwise, we are examining an alphabetical character
		else:
			alphabetData.append(features)
			alphabetLabels.append(sampleName)

# train the character classifier
print("[INFO] fitting character model...")
charModel = LinearSVC(C=1.0, random_state=42)
# loop over the images
for imagePath in imagePaths:
    # show the image path
    print("[EXAMINING] {}".format(imagePath))

    try:
        # load the image
        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 characters on the license plate
        lpd = LicensePlateDetector(image, numChars=7)
        plates = lpd.detect()

        # loop over the license plates
        for (lpBox, chars) in plates:
            # draw the bounding box surrounding the license plate and display it for
            # reference purposes
            plate = image.copy()
            cv2.drawContours(plate, [lpBox], -1, (0, 255, 0), 2)
            cv2.imshow("License Plate", plate)

            # loop over the characters
            for char in chars:
                # display the character and wait for a keypress
                cv2.imshow("Char", char)
                key = cv2.waitKey(0)
Esempio n. 5
0
    #	mask = np.zeros(image.shape[:2], dtype="uint8")
    #x1,y1  x2,y2
    #	cv2.rectangle(mask, rect[0], rect[1], 255, -1)
    #	image = cv2.bitwise_and(image, image, mask=mask)

    # crop it instead
    image = image[rect[0][1]:rect[1][1], rect[0][0]:rect[1][0]]

    print(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 charactors
    lpd = LicensePlateDetector(image)
    data = lpd.detect()
    plates = data['regions']

    if plates:
        images = data['images']

        #	image = cv2.cvtColor(images[-1], cv2.COLOR_GRAY2BGR)

        #	montage.addResult(images[0])

        print('found', len(plates))
        # loop over the license plate regions and draw the bounding box surrounding the
        # license plate
        for lpBox in plates:
            #			cv2.drawContours(image, [lpBox], -1, (0, 255, 0), 2)