Exemplo n.º 1
0
def extract_char(img):

    image = DetectPlates.extract(img)

    img_gray, thresh = Preprocess.preprocess(image)
    listOfPossibleChars = []
    imgContours, contours, npaHierarchy = cv2.findContours(
        thresh, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)

    def sort_contours(cnts, method="left-to-right"):
        # initialize the reverse flag and sort index
        reverse = False
        i = 0

        # handle if we need to sort in reverse
        if method == "right-to-left" or method == "bottom-to-top":
            reverse = True

        # handle if we are sorting against the y-coordinate rather than
        # the x-coordinate of the bounding box
        if method == "top-to-bottom" or method == "bottom-to-top":
            i = 1

        # construct the list of bounding boxes and sort them from top to
        # bottom
        boundingBoxes = [cv2.boundingRect(c) for c in cnts]
        (cnts, boundingBoxes) = zip(*sorted(
            zip(cnts, boundingBoxes), key=lambda b: b[1][i], reverse=reverse))

        # return the list of sorted contours and bounding boxes
        return (cnts, boundingBoxes)

    (contours, boundingBoxes) = sort_contours(contours)

    for i in range(len(contours)):
        #check xem contours tim duoc co kha nang la char hay khong
        if checkIfPossibleChar_(contours[i]):
            listOfPossibleChars.append(contours[i])

    idx = 0
    for i in range(len(contours)):
        # tra ve vi tri chieu rong, cao cho moi duowng vien
        x, y, w, h = cv2.boundingRect(contours[i])

        #crop and save
        idx += 1
        new_img = image[y - 2:y + h + 2, x - 1:x + w + 1]
        img_gray = cv2.cvtColor(new_img, cv2.COLOR_BGR2GRAY)
        #new_img = 1- new_img

        _, img_threshold = cv2.threshold(img_gray, 150, 255, cv2.THRESH_BINARY)

        new_img = img_threshold
Exemplo n.º 2
0
import Preprocess
import cv2
import DetectPlates
import DetectChars
import argparse
import predict

ap = argparse.ArgumentParser()
ap.add_argument('-i', '--image', help="fill the path of image")

args = vars(ap.parse_args())
img = cv2.imread(args['image'])

DetectPlates.extract(img)
DetectChars.extract_char(img)

# Main.py

import cv2
import numpy as np
import os

import DetectChars
import DetectPlates
import PossiblePlate

# module level variables ##########################################################################
SCALAR_BLACK = (0.0, 0.0, 0.0)
SCALAR_WHITE = (255.0, 255.0, 255.0)
SCALAR_YELLOW = (0.0, 255.0, 255.0)
SCALAR_GREEN = (0.0, 255.0, 0.0)