コード例 #1
0
def findPossibleCharsInScene(imgThresh, char_aspect_ratio_interval):

    imgThreshCopy = imgThresh.copy()
    _, contours, _ = cv2.findContours(imgThreshCopy, cv2.RETR_TREE,
                                      cv2.CHAIN_APPROX_SIMPLE)
    return [
        PossibleChar.PossibleChar(contour)
        for contour in contours if DetectChars.checkIfPossibleChar(
            PossibleChar.PossibleChar(contour), char_aspect_ratio_interval)
    ]
コード例 #2
0
def findPossibleCharsInScene(imgThresh):
    listOfPossibleChars = []  # this will be the return value

    intCountOfPossibleChars = 0

    imgThreshCopy = imgThresh.copy()
    #print('Now we start to find the contours in the thresholded image that may be characters:')
    #if error with expected values: add imgContours to the next line
    contours, npaHierarchy = cv2.findContours(
        imgThreshCopy, cv2.RETR_CCOMP,
        cv2.CHAIN_APPROX_SIMPLE)  # find all contours

    height, width = imgThresh.shape
    imgContours = np.zeros((height, width, 3), np.uint8)

    for i in range(0, len(contours)):  # for each contour

        possibleChar = PossibleChar.PossibleChar(
            contours[i]
        )  # Here we calculate the x,y,w,h,flatdiagonalsize,aspedctratio,area and (x,y) of the center of the rectangle that is bounding the contour.

        if DetectChars.checkIfPossibleChar(
                possibleChar
        ):  # if contour is a possible char, note this does not compare to other chars (yet) . . .
            intCountOfPossibleChars = intCountOfPossibleChars + 1  # increment count of possible chars
            listOfPossibleChars.append(
                possibleChar)  # and add to list of possible chars

    return listOfPossibleChars
コード例 #3
0
def findPossibleCharsInScene(imgThresh):
    listOfPossibleChars = []  # this will be the return value

    intCountOfPossibleChars = 0

    imgThreshCopy = imgThresh.copy()

    imgContours, contours, npaHierarchy = cv2.findContours(
        imgThreshCopy, cv2.RETR_LIST,
        cv2.CHAIN_APPROX_SIMPLE)  # find all contours

    height, width = imgThresh.shape
    imgContours = np.zeros((height, width, 3), np.uint8)

    for i in range(0, len(contours)):  # for each contour

        if Main.showSteps == True:  # show steps ###################################################
            cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE)
        # end if # show steps #####################################################################

        possibleChar = PossibleChar.PossibleChar(contours[i])

        if DetectChars.checkIfPossibleChar(
                possibleChar
        ):  # if contour is a possible char, note this does not compare to other chars (yet) . . .
            intCountOfPossibleChars = intCountOfPossibleChars + 1  # increment count of possible chars
            listOfPossibleChars.append(
                possibleChar)  # and add to list of possible chars
        # end if
    # end for

    return listOfPossibleChars
コード例 #4
0
def findPossibleCharsInScene(imgThresh):
    listOfPossibleChars = []  # this will be the return value

    intCountOfPossibleChars = 0

    imgThreshCopy = imgThresh.copy()

    imgContours, contours, npaHierarchy = cv2.findContours(
        imgThreshCopy, cv2.RETR_LIST,
        cv2.CHAIN_APPROX_SIMPLE)  # find all contours

    height, width = imgThresh.shape
    imgContours = np.zeros((height, width, 3), np.uint8)

    for i in range(0, len(contours)):  # for each contour

        possibleChar = PossibleChar.PossibleChar(contours[i])

        if DetectChars.checkIfPossibleChar(
                possibleChar
        ):  # if contour is a possible char, note this does not compare to other chars (yet) . . .
            # kontur olası bir char ise, bu diğer karakterlerle (henüz) karşılaştırılamaz.
            intCountOfPossibleChars = intCountOfPossibleChars + 1  # increment count of possible chars (olası karakterlerin artış sayısı)
            listOfPossibleChars.append(
                possibleChar
            )  # and add to list of possible chars (ve olası karakterlerin listesine ekle)
        # end if
    # end for

    return listOfPossibleChars
コード例 #5
0
def find_char(imgThresh):
    listOfPossibleChars = []
    intCountOfPossibleChars = 0

    #Creating a copy of the thresholded image
    imgThreshCopy = imgThresh.copy()

    #The following finds all the contours.
    #To remember contours: https://docs.opencv.org/3.1.0/d4/d73/tutorial_py_contours_begin.html
    imgContours, contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)

    #get height and width of  the thresholded image
    height, width = imgThresh.shape
    #intializing
    imgContours = np.zeros((height, width, 3), np.uint8)

    #loop i from 0 to the number of contours(contours is a list containing the contour's information in each entry, so we get it's length)
    for i in range(0, len(contours)):

        #refer to the file PossibleChar.py
        #it's constructor takes the contour
        possibleChar = PossibleChar.PossibleChar(contours[i])

        #check if the a contour is a possible character.
        if DetectChars.checkIfPossibleChar(possibleChar):
            #increment count
            intCountOfPossibleChars = intCountOfPossibleChars + 1

            #add to list of possible chars
            listOfPossibleChars.append(possibleChar)

    #When the loop finishes we have a list with all contours having a possibility of being a character.
    return listOfPossibleChars
コード例 #6
0
def findPossibleCharsInScene(imgThresh):
    listOfPossibleChars = []                # this will be the return value

    intCountOfPossibleChars = 0

    imgThreshCopy = imgThresh.copy()
    contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE)   # find all contours

    height, width = imgThresh.shape
    imgContours = np.zeros((height, width, 3), np.uint8)

    for i in range(0, len(contours)):                       # for each contour

        # if Main.showSteps == True:
        #     cv2.drawContours(imgContours, contours, i, Main.SCALAR_YELLOW)
        #     cv2.imshow('Thresholded',imgContours)
        #     cv2.waitKey(0)

        possibleChar = PossibleChar.PossibleChar(contours[i])

        if CharacterDetection.checkIfPossibleChar(possibleChar):
            intCountOfPossibleChars = intCountOfPossibleChars + 1
            listOfPossibleChars.append(possibleChar)

    # if Main.showSteps == True:
    #     # print("\nstep 2 - Total number of contours found in the image are = " + str(len(contours)))
    #     # print("step 2 - number of contours those may be characters = " + str(intCountOfPossibleChars))
    #     # # #print("These are the contours those may be characters :")
    #     # cv2.imshow("2a", imgContours)
    #     # cv2.waitKey(0)
    return listOfPossibleChars
コード例 #7
0
def findPossibleCharsInScene(img_thresh):
    possible_chars = []

    possible_chars_count = 0

    img_thresh_copy = img_thresh.copy()

    img_contours, contours, npa_hierarchy = cv2.findContours(img_thresh_copy, cv2.RETR_LIST,
                                                             cv2.CHAIN_APPROX_SIMPLE)

    height, width = img_thresh.shape
    img_contours = np.zeros((height, width, 3), np.uint8)

    for i in range(0, len(contours)):

        if Recognitor.showSteps:
            cv2.drawContours(img_contours, contours, i, Recognitor.SCALAR_WHITE)

        possibleChar = PossibleChar.PossibleChar(contours[i])

        if DetectChars.checkIfPossibleChar(possibleChar):
            possible_chars_count = possible_chars_count + 1  # increment count of possible chars
            possible_chars.append(possibleChar)  # and add to list of possible chars

    if Recognitor.showSteps:
        print("\nstep 2 - len(contours) = " + str(len(contours)))
        print("step 2 - intCountOfPossibleChars = " + str(possible_chars_count))
        cv2.imshow("2a", img_contours)

    return possible_chars
コード例 #8
0
def find_possible_chars_in_scene(img_thresh) -> [PossibleChar]:
    list_of_possible_chars: [PossibleChar] = []
    int_count_of_possible_chars: int = 0
    img_thresh_copy = img_thresh.copy()

    contours, npa_hierarchy = cv2.findContours(img_thresh_copy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)

    height, width = img_thresh.shape
    img_contours = np.zeros((height, width, 3), np.uint8)

    for i in range(0, len(contours)):
        if not SUPER_SPEED_MODE:
            cv2.drawContours(img_contours, contours, i, SCALAR_WHITE, 3)

        possible_char = PossibleChar.PossibleChar(contours[i])

        if DetectChars.check_if_possible_char(possible_char):
            int_count_of_possible_chars = int_count_of_possible_chars + 1
            list_of_possible_chars.append(possible_char)

    if NO_ERROR_PRINT_ENABLED:
        print("\n[F:Find Possible Chars in Scene] - len(contours) = " + str(len(contours)))
        print("\n[F:Find Possible Chars in Scene] - int_count_of_possible_chars = " + str(int_count_of_possible_chars))

    if SHOW_IMAGE:
        cv2.imshow("[F:Find Possible Chars in Scene] - Contours", img_contours)

    if SAVE_IMAGE:
        cv2.imwrite("./output/showImage/4-Find Possible Chars-Contours.jpg", img_contours)

    return list_of_possible_chars
コード例 #9
0
def findPossibleCharsInScene(imgThresh):
    listOfPossibleChars = []                # this will be the return value

    intCountOfPossibleChars = 0

    imgThreshCopy = imgThresh.copy()

#   imgContours, contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)   # find all contours
    contours,npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)[-2:]
    # find all contours
#    print("imgContours",imgContours)
#    print("contours",contours)
    
    height, width = imgThresh.shape
    imgContours = np.zeros((height, width, 3), np.uint8)

    
    for contour in contours:
#        type(contour)
#        print(type(contour))
#        x,y,w,h=cv2.boundingRect(contour)
#        print('x,y,w,h',x,y,w,h)
        #if Main.showSteps == True:
        
            
            #cv2.drawContours(imgThreshCopy, contour, -1, (0, 255, 0), 3)
        possibleChar = PossibleChar.PossibleChar(contour)
        x,y,w,h=cv2.boundingRect(contour)
#        print('x,y,w,h',x,y,w,h)

        if DetectChars.checkIfPossibleChar(possibleChar):   
            
                # if contour is a possible char, note this does not compare to other chars (yet) . . .
            intCountOfPossibleChars = intCountOfPossibleChars + 1           # increment count of possible chars
            listOfPossibleChars.append(possibleChar)                        # and add to list of possible chars

#        print("listOfPossibleChars in findPossibleChars",listOfPossibleChars)
    
#    for i in range(0, len(contours)):                       # for each contour
#
#        if Main.showSteps == True: # show steps ###################################################
#     #       cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE)
#            cv2.drawContours(imgThresh, contours, i, Main.SCALAR_WHITE)
#        # end if # show steps #####################################################################
#
#        possibleChar = PossibleChar.PossibleChar(contours[i])
#
#        if DetectChars.checkIfPossibleChar(possibleChar):                   # if contour is a possible char, note this does not compare to other chars (yet) . . .
#            intCountOfPossibleChars = intCountOfPossibleChars + 1           # increment count of possible chars
#            listOfPossibleChars.append(possibleChar)                        # and add to list of possible chars
#        # end if
#    # end for

    if Main.showSteps == True: # show steps #######################################################
        print("\nstep 2 - len(contours) = " + str(len(contours)))  # 2362 with MCLRNF1 image
        print("step 2 - intCountOfPossibleChars = " + str(intCountOfPossibleChars))  # 131 with MCLRNF1 image
        cv2.imshow("2a", imgContours)
    # end if # show steps #########################################################################

    return listOfPossibleChars
コード例 #10
0
def findPossibleCharsInScene(imgThresh):
    listOfPossibleChars = []  # this will be the return value

    intCountOfPossibleChars = 0

    imgThreshCopy = imgThresh.copy()

    imgContours, contours, npaHierarchy = cv2.findContours(
        imgThreshCopy, cv2.RETR_LIST,
        cv2.CHAIN_APPROX_SIMPLE)  # find all contours

    height, width = imgThresh.shape
    imgContours = np.zeros((height, width, 3), np.uint8)

    for i in range(0, len(contours)):  # for each contour

        possibleChar = PossibleChar.PossibleChar(contours[i])

        if DetectChars.checkIfPossibleChar(
                possibleChar
        ):  # if contour is a possible char, note this does not compare to other chars (yet) . . .
            intCountOfPossibleChars = intCountOfPossibleChars + 1  # increment count of possible chars
            listOfPossibleChars.append(
                possibleChar)  # and add to list of possible chars
        # end if
    # end for

    if Main.showstep_plate:
        print("\nstep 2 - len(contours) = " + str(len(contours)))
        print("step 2 - intCountOfPossibleChars = " +
              str(intCountOfPossibleChars))
        cv2.imshow("2a", imgContours)

    return listOfPossibleChars
コード例 #11
0
ファイル: sOcropus.py プロジェクト: newtein/ComputerVision
def methodEight(imgpath):
    img = cv2.imread(imgpath)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    gray = cv2.resize(gray, (0, 0), fx=1.5, fy=1.5)
    ret, thresh = cv2.threshold(gray, 127, 255, 0)
    height, width = chain(gray.shape)

    _, contours, _ = cv2.findContours(thresh, cv2.RETR_TREE,
                                      cv2.CHAIN_APPROX_SIMPLE)
    #contours = sorted(contours, key=cv2.contourArea)
    for contour in contours:
        if cv2.contourArea(contour) > 50:
            rectangleInfo = PossibleChar.PossibleChar(contour)
            #h,w=rectangleInfo.intBoundingRectHeight,rectangleInfo.intBoundingRectWidth
            x, y, w, h = cv2.boundingRect(contour)
            mask = np.zeros((height, width), np.uint8)
            cv2.drawContours(mask, [contour], -1, 255.0, -1)
            dst = cv2.bitwise_and(gray, gray, mask=mask)
            crop = dst[y:y + h, x:x + w]
            showImage(crop)

    cv2.imwrite("book/0006.bin.png", thresh)
    result = pytesseract.image_to_string(Image.open("book/0006.bin.png"))
    writeInFile(outpath, result)
    accuracy = calculateAccuracy(imgpath, outpath, type='P')
    print(accuracy)

    return
コード例 #12
0
ファイル: DetectPlates.py プロジェクト: NDPNguyen-FE/AI-
def findPossibleCharsInScene(imgThresh):
    listOfPossibleChars = []

    intCountOfPossibleChars = 0

    imgThreshCopy = imgThresh.copy()

    imgContours, contours, npaHierarchy = cv2.findContours(
        imgThreshCopy, cv2.RETR_LIST,
        cv2.CHAIN_APPROX_SIMPLE)  #xác định các đường viền đã có
    height, width = imgThresh.shape
    imgContours = np.zeros((height, width, 3), np.uint8)

    for i in range(0, len(contours)):

        if Main.showSteps == True:
            cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE)

        possibleChar = PossibleChar.PossibleChar(contours[i])

        if DetectChars.checkIfPossibleChar(possibleChar):
            intCountOfPossibleChars = intCountOfPossibleChars + 1
            listOfPossibleChars.append(possibleChar)

    if Main.showSteps == True:
        print("\nstep 2 - len(contours) = " + str(len(contours)))
        print("step 2 - intCountOfPossibleChars = " +
              str(intCountOfPossibleChars))
        cv2.imshow("2a", imgContours)

    return listOfPossibleChars
コード例 #13
0
def find_psbl_chr(img_thresh, psbl_char_params, explore_area=False):
    """
    check all contours on image if can they be chrs
    """
    list_of_possible_chars = []
    none_char = []

    # find all contours in plate
    _, contours, _ = cv2.findContours(img_thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

    plate_area = img_thresh.shape[0] * img_thresh.shape[1]

    for contour in range(len(contours)):
        # make simple contour like instance of PossibleChar
        pssbl_chr = PossibleChar.PossibleChar(contours[contour])
        char_area = pssbl_chr.height * pssbl_chr.width

        # checking for: can contour be a character
        if not explore_area and check_if_pssbl_chr(pssbl_chr, psbl_char_params):
            list_of_possible_chars.append(pssbl_chr)
        elif explore_area and 0.04 < char_area / plate_area < 0.1 and check_if_pssbl_chr(pssbl_chr, psbl_char_params):
            list_of_possible_chars.append(pssbl_chr)
        else:
            none_char.append(pssbl_chr)

    number_of_chars = len(list_of_possible_chars)
    list_of_possible_chars = list(sorted(list_of_possible_chars, key=lambda obj: obj.area))

    return list_of_possible_chars, number_of_chars, none_char
コード例 #14
0
ファイル: detect_plates.py プロジェクト: andrzejwl/io
def findPossibleCharsInScene(imgThresh):
    list_of_possible_chars = []  # this will be the return value

    int_count_of_possible_chars = 0

    img_thresh_copy = imgThresh.copy()

    contours, npa_hierarchy = cv2.findContours(
        img_thresh_copy, cv2.RETR_LIST,
        cv2.CHAIN_APPROX_SIMPLE)  # find all contours

    height, width = imgThresh.shape
    img_contours = np.zeros((height, width, 3), np.uint8)

    for i in range(0, len(contours)):  # for each contour

        if app.showSteps:
            cv2.drawContours(img_contours, contours, i, app.SCALAR_WHITE)

        possible_char = PossibleChar.PossibleChar(contours[i])

        if detect_chars.checkIfPossibleChar(
                possible_char
        ):  # if contour is a possible char, note this does not compare to other chars
            int_count_of_possible_chars = int_count_of_possible_chars + 1  # increment count of possible chars
            list_of_possible_chars.append(
                possible_char)  # and add to list of possible chars

    if app.showSteps:
        print("\nstep 2 - len(contours) = " + str(len(contours)))
        print("step 2 - int_count_of_possible_chars = " +
              str(int_count_of_possible_chars))
        cv2.imshow("2a", img_contours)

    return list_of_possible_chars
コード例 #15
0
def findPossibleCharsInScene(imgThresh):
    listOfPossibleChars = []  # this will be the return value

    intCountOfPossibleChars = 0

    imgThreshCopy = imgThresh.copy()

    imgContours, contours, npaHierarchy = cv2.findContours(
        imgThreshCopy, cv2.RETR_LIST,
        cv2.CHAIN_APPROX_SIMPLE)  # find all contours

    height, width = imgThresh.shape
    imgContours = np.zeros((height, width, 3), np.uint8)

    for i in range(0, len(contours)):  # for each contour

        cv2.drawContours(imgContours, contours, i, SCALAR_WHITE)

        possibleChar = PossibleChar.PossibleChar(contours[i])

        if DetectChars.checkIfPossibleChar(
                possibleChar
        ):  # if contour is a possible char, note this does not compare to other chars (yet) . . .
            intCountOfPossibleChars = intCountOfPossibleChars + 1  # increment count of possible chars
            listOfPossibleChars.append(
                possibleChar)  # and add to list of possible chars

    print("\nstep 2 - len(contours) = " +
          str(len(contours)))  # 2362 with MCLRNF1 image
    print("step 2 - intCountOfPossibleChars = " +
          str(intCountOfPossibleChars))  # 131 with MCLRNF1 image
    cv2.imwrite("./images/2b.png", imgContours)
    print(intCountOfPossibleChars)
    return listOfPossibleChars
コード例 #16
0
def findPossibleCharsInScene(imgThresh):
    listOfPossibleChars = []                # this will be the return value

    intCountOfPossibleChars = 0

    imgThreshCopy = imgThresh.copy()

    # find all contours
    imgContours, contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE)

    height, width = imgThresh.shape
    imgContours = np.zeros((height, width, 3), np.uint8)

    for i in range(0, len(contours)):

        # Here we calculate the x,y,w,h,flatdiagonalsize,aspedctratio,area and (x,y) of the center of the rectangle that is bounding the contour.
        possibleChar = PossibleChar.PossibleChar(contours[i])

        if DetectChars.checkIfPossibleChar(possibleChar):
            intCountOfPossibleChars = intCountOfPossibleChars + 1
            listOfPossibleChars.append(possibleChar)
            cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE)


    return listOfPossibleChars
コード例 #17
0
def find_vld_chrs_by_cascad(img_thresh, gray):
    possible_chars = []

    # some bluring
    gray = cv2.GaussianBlur(gray, (5, 5), 0)

    # find plates by standard Hoar's cascad
    plates = cascade.detectMultiScale(gray, scaleFactor=1.01, minNeighbors=3)

    # find contours on image
    _, contours, _ = cv2.findContours(img_thresh, cv2.RETR_CCOMP,
                                      cv2.CHAIN_APPROX_SIMPLE)

    for i in range(len(contours)):
        #
        possible_char = PossibleChar.PossibleChar(contours[i])

        # if contour is a possible char, note this does not compare to other chars (yet) . . .
        if DetectChars.check_if_pssbl_chr(possible_char,
                                          [120, 8, 10, 0.25, 1.5]):
            for (x, y, w, h) in plates:
                if x < possible_char.pos_x < x + w and y < possible_char.center_y < y + h:
                    possible_chars.append(
                        possible_char)  # and add to list of possible chars
                    break
    return possible_chars
コード例 #18
0
ファイル: Launch.py プロジェクト: suvarnak/ALPR
def findPossibleCharsInPlate(imgGrayscale, imgThresh):
    '''
    This fucntion extracts all the contours from the number plate image and groups the relevant contours into a list
    and returns the list
    @input: Grayscale and thresholded image of the numberplate
    @output: List of relevant contours
    '''
    listOfPossibleChars = []  # this will be the return value
    contours = []
    imgThreshCopy = imgThresh.copy()

    # find all contours in plate
    imgContours, contours, npaHierarchy = cv2.findContours(
        imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)

    for contour in contours:  # for each contour
        possibleChar = PossibleChar.PossibleChar(contour)

        if checkIfPossibleChar(
                possibleChar
        ):  # if contour is a possible char, note this does not
            listOfPossibleChars.append(
                possibleChar
            )  # compare to other chars (yet) add to list of possible chars
        # end if
    # end if

    return listOfPossibleChars
コード例 #19
0
def findPossibleCharsInScene(imgThresh):
    listOfPossibleChars = []  # this will be the return value

    intCountOfPossibleChars = 0

    imgThreshCopy = imgThresh.copy()

    contours, npaHierarchy = cv2.findContours(
        imgThreshCopy, cv2.RETR_LIST,
        cv2.CHAIN_APPROX_SIMPLE)  # find all contours

    height, width = imgThresh.shape
    imgContours = np.zeros((height, width, 3), np.uint8)

    for i in range(0, len(contours)):

        if Main.showSteps == True:
            cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE)

        possibleChar = PossibleChar.PossibleChar(contours[i])

        if DetectChars.checkIfPossibleChar(possibleChar):
            intCountOfPossibleChars = intCountOfPossibleChars + 1
            listOfPossibleChars.append(possibleChar)
        # end if
    # end for

    if Main.showSteps == True:
        print("\nstep 2 - len(contours) = " +
              str(len(contours)))  # 2362 with MCLRNF1 image
        print("step 2 - intCountOfPossibleChars = " +
              str(intCountOfPossibleChars))  # 131 with MCLRNF1 image
        cv2.imshow("2a", imgContours)

    return listOfPossibleChars
コード例 #20
0
ファイル: DetectPlates.py プロジェクト: Zavxoz/BadGAI
def find_possible_chars_in_scene(img_thresh):
    list_of_possible_chars = []

    count_of_possible_chars = 0

    img_thresh_copy = img_thresh.copy()

    img_contours, contours, hierarchy = cv2.findContours(
        img_thresh_copy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
    height, width = img_thresh.shape
    img_contours = np.zeros((height, width, 3), np.uint8)

    for i in range(0, len(contours)):

        if PlateRecognition.showSteps:
            cv2.drawContours(img_contours, contours, i,
                             PlateRecognition.SCALAR_WHITE)

        possible_char = PossibleChar.PossibleChar(contours[i])

        if DetectChars.check_if_possible_char(possible_char):
            count_of_possible_chars = count_of_possible_chars + 1
            list_of_possible_chars.append(possible_char)

    return list_of_possible_chars
コード例 #21
0
ファイル: DetectChars.py プロジェクト: nickollasaranha/tcc
def findPossibleCharsInPlate(imgGrayscale, imgThresh, char_aspect_ratio_interval):
    listOfPossibleChars = []                        # this will be the return value
    contours = []
    imgThreshCopy = imgThresh.copy()

    # find all contours in plate
    imgContours, contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
    return [PossibleChar.PossibleChar(cnt) for cnt in contours if checkIfPossibleChar(PossibleChar.PossibleChar(cnt), char_aspect_ratio_interval)]
コード例 #22
0
def findPossibleCharsInPlate(imgGrayscale, imgThresh):
    listOfPossibleChars = []
    contours = []
    imgThreshCopy = imgThresh.copy()
    contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_LIST,
                                              cv2.CHAIN_APPROX_SIMPLE)
    for contour in contours:
        possibleChar = PossibleChar.PossibleChar(contour)
        if checkIfPossibleChar(possibleChar):
            listOfPossibleChars.append(possibleChar)
    return listOfPossibleChars
コード例 #23
0
def find_possible_chars(img_thresh):
    possible_chars = []
    count_possible_chars = 0
    img_thresh_copy = img_thresh.copy()
    img_contours, contours, npa_hierarchy = cv2.findContours(
        img_thresh_copy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
    for i in range(0, len(contours)):
        possible_char = PossibleChar.PossibleChar(contours[i])
        if possible_char.if_possible:
            count_possible_chars += 1
            possible_chars.append(possible_char)
    return possible_chars
コード例 #24
0
def findPossibleCharsInPlate(imgGrayscale, imgThresh):
    listOfPossibleChars = []                        # this will be the return value
    contours = []
    imgThreshCopy = imgThresh.copy()

            # find all contours in plate
    contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)

    for contour in contours:                        # for each contour
        possibleChar = PossibleChar.PossibleChar(contour)

        if checkIfPossibleChar(possibleChar):              # if contour is a possible char, note this does not compare to other chars (yet) . . .
            listOfPossibleChars.append(possibleChar)       # add to list of possible chars
    return listOfPossibleChars
コード例 #25
0
def get_Possible_chars(grayscale_image, threshold_image):
    Possible_Chars = []
    contours = []
    threshold_image_copy = threshold_image.copy()

    contours, npaHierarchy = cv2.findContours(threshold_image_copy,
                                              cv2.RETR_LIST,
                                              cv2.CHAIN_APPROX_SIMPLE)
    for contour in contours:
        possibleChar = PossibleChar.PossibleChar(contour)

        if checkIfPossibleChar(possibleChar):
            Possible_Chars.append(possibleChar)
    return Possible_Chars
コード例 #26
0
def find_possible_chars_in_plate(img_grayscale, img_thresh):
    list_of_possible_chars = []
    img_thresh_copy = img_thresh.copy()

    # find all contours in plate
    contours, contours, hierarchy = cv2.findContours(
        img_thresh_copy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)

    for contour in contours:
        possible_char = PossibleChar.PossibleChar(contour)

        if check_if_possible_char(possible_char):
            list_of_possible_chars.append(possible_char)
    return list_of_possible_chars
def findPossibleCharsInScene(imgThresh):
    listOfPossibleChars = []  # this will be the return value

    intCountOfPossibleChars = 0

    imgThreshCopy = imgThresh.copy()
    #print('Now we start to find the contours in the thresholded image that may be characters:')

    contours, npaHierarchy = cv2.findContours(
        imgThreshCopy, cv2.RETR_CCOMP,
        cv2.CHAIN_APPROX_SIMPLE)  # find all contours

    height, width = imgThresh.shape
    imgContours = np.zeros((height, width, 3), np.uint8)

    for i in range(0, len(contours)):  # for each contour

        if Main.showSteps == True:  # show steps ###################################################
            cv2.drawContours(imgContours, contours, i, Main.SCALAR_YELLOW)
            #cv2.imshow('Thresholded',imgContours)
            #cv2.waitKey(0)

        possibleChar = PossibleChar.PossibleChar(
            contours[i]
        )  # Here we calculate the x,y,w,h,flatdiagonalsize,aspedctratio,area and (x,y) of the center of the rectangle that is bounding the contour.

        if DetectChars.checkIfPossibleChar(
                possibleChar
        ):  # if contour is a possible char, note this does not compare to other chars (yet) . . .
            intCountOfPossibleChars = intCountOfPossibleChars + 1  # increment count of possible chars
            listOfPossibleChars.append(
                possibleChar)  # and add to list of possible chars
            #cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE)
            #print('This contour may be a character :')
        #else:
        #print('This contour is not a character :')
        # end if
    # end for

    if Main.showSteps == True:  # show steps #######################################################
        print("\nstep 2 - Total number of contours found in the image are = " +
              str(len(contours)))
        print("step 2 - number of contours those may be characters = " +
              str(intCountOfPossibleChars))
        #print("These are the contours those may be characters :")
        cv2.imshow("2a", imgContours)
        cv2.waitKey(0)
    # end if # show steps #########################################################################

    return listOfPossibleChars
コード例 #28
0
def findPossibleCharsInScene(imgThresh):
    listOfPossibleChars = []  #Dönüş değeri olacak
    intCountOfPossibleChars = 0
    imgThreshCopy = imgThresh.copy()
    contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)  # Tüm kontürleri bul SIMPLE ile 4 kontür bulunur

    height, width = imgThresh.shape
    imgContours = np.zeros((height, width, 3), np.uint8)
    for i in range(0, len(contours)):    # Her bir kontür için
        possibleChar = PossibleChar.PossibleChar(contours[i])
        if DetectChars.checkIfPossibleChar(possibleChar):         # Kontur olası bir karakter ise, bunun diğer karakterlerle (henüz) karşılaştırılmadığını unutma
            intCountOfPossibleChars = intCountOfPossibleChars + 1 # Olası karakterlerin sayısını arttır
            listOfPossibleChars.append(possibleChar)              # Olası listeye ekle
    return listOfPossibleChars
コード例 #29
0
def find_possible_chars_in_plate(img_grayscale, img_thresh) -> [PossibleChar]:
    list_of_possible_chars = []
    contours = []
    img_thresh_copy = img_thresh.copy()

    # Buscamos todos los contornos en la patente
    contours, npa_hierarchy = cv2.findContours(img_thresh_copy, cv2.RETR_LIST,
                                               cv2.CHAIN_APPROX_SIMPLE)

    for contour in contours:
        possible_char = PossibleChar.PossibleChar(contour)
        if check_if_possible_char(possible_char):
            list_of_possible_chars.append(possible_char)

    return list_of_possible_chars
コード例 #30
0
ファイル: DetectPlates.py プロジェクト: imharjotsingh/thesis
def findPossibleCharsInScene(imgThresh):
    listOfPossibleChars = []
    intCountOfPossibleChars = 0
    imgThreshCopy = imgThresh.copy()
    imgContours, contours, npaHierarchy = cv2.findContours(
        imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
    height, width = imgThresh.shape
    imgContours = np.zeros((height, width, 3), np.uint8)
    for i in range(0, len(contours)):
        possibleChar = PossibleChar.PossibleChar(contours[i])
        if DetectChars.checkIfPossibleChar(possibleChar):
            intCountOfPossibleChars = intCountOfPossibleChars + 1
            listOfPossibleChars.append(possibleChar)

    return listOfPossibleChars