How to use the pytesseract.image_to_boxes function in pytesseract

To help you get started, we’ve selected a few pytesseract examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github iSysLab / sketch2html / findText.py View on Github external
def findText(img, mode = "default", offset = 10):
    # img = cv2.imread(img)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #Converting to GrayScale
    text = cleanText(pytesseract.image_to_boxes(gray, config="--psm 11 --oem 1"))
    text = text.split("\n")
    if text[0] == '':
        return None
    array = []
    for m in text:
        info = m.split(" ")
        x1, y1, x2, y2 = int(info[1]) - offset, int(height - int(info[4])) - offset, int(info[3]) + offset, int(height - int(info[2])) + offset
        if x1 < 0:
            x1 = 0
        elif y1 < 0:
            y1 = 0
        elif x2 > 800:
            x2 = 800
        elif y2 > 600:
            y2 = 600
        info = [info[0], [x1, y1, x2, y2]]
github AlexCovizzi / ScreencapToTextBot / ocr.py View on Github external
def tesseract_ocr(pil_img):
    string_boxes = pytesseract.image_to_boxes(pil_img, lang="eng")
    rows = string_boxes.split("\n")

    hsize = pil_img.size[1]
    chars = []
    for row in rows:
        tokens = row.split(" ")
        char = {'text':tokens[0], 'x1':int(tokens[1]), 'y1':hsize-int(tokens[4]), 'x2':int(tokens[3]), 'y2':hsize-int(tokens[2])}
        chars.append(char)

    words = chars_to_words(chars)
    lines = words_to_lines(words)

    return lines
github AlexCovizzi / ScreencapToTextBot / screencaptotext.py View on Github external
def ocr(pil_img):
    prep_img = ocr_preprocess(pil_img)

    string = pytesseract.image_to_boxes(prep_img, lang="eng", config="tessconfig")
    lines = tesseract_string_to_lines(string, pil_img.size[1])

    prep_img.close()

    return lines
github jpnaterer / smashscan / ocr.py View on Github external
def show_ocr_result(frame):
    start_time = time.time()
    text = pytesseract.image_to_string(frame, lang="eng", config="--psm 8")
    print(text)
    util.display_total_time(start_time)

    start_time = time.time()
    pytess_result = pytesseract.image_to_boxes(frame, lang="eng",
        config="--psm 8", output_type=pytesseract.Output.DICT)
    print(pytess_result)
    util.display_total_time(start_time)

    bbox_list = list()
    for i, _ in enumerate(pytess_result['bottom']):
        tl = (pytess_result['left'][i], pytess_result['bottom'][i])
        br = (pytess_result['right'][i], pytess_result['top'][i])
        bbox_list.append((tl, br))
    util.show_frame(frame, bbox_list=bbox_list, wait_flag=True)

    start_time = time.time()
    pytess_data = pytesseract.image_to_data(frame, lang="eng",
        config="--psm 8", output_type=pytesseract.Output.DICT)
    print(pytess_data)
    util.display_total_time(start_time)