How to use the pytesseract.pytesseract.tesseract_cmd 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 madmaze / pytesseract / tests / test_pytesseract.py View on Github external
def test_wrong_tesseract_cmd(test_file, test_path):
    """Test wrong or missing tesseract command."""
    import pytesseract
    pytesseract.pytesseract.tesseract_cmd = test_path
    with pytest.raises(TesseractNotFoundError):
        pytesseract.pytesseract.image_to_string(test_file)
    pytesseract.pytesseract.tesseract_cmd = 'tesseract'  # restore the def value
github madmaze / pytesseract / tests / test_pytesseract.py View on Github external
def test_wrong_tesseract_cmd(test_file, test_path):
    """Test wrong or missing tesseract command."""
    import pytesseract
    pytesseract.pytesseract.tesseract_cmd = test_path
    with pytest.raises(TesseractNotFoundError):
        pytesseract.pytesseract.image_to_string(test_file)
    pytesseract.pytesseract.tesseract_cmd = 'tesseract'  # restore the def value
github SmileSmith / autoAnswer / src / units / ocr.py View on Github external
# 切割题目+选项区域,左上角坐标和右下角坐标,自行测试分辨率
    region_im = image.crop(
        (combine_region[0], combine_region[1], combine_region[2], combine_region[3]))

    # 转化为灰度图
    region_im = region_im.convert('L')

    # 把图片变成二值图像
    region_im = binarizing(region_im, 190)

    # region_im.show()

    # win环境
    # tesseract 路径

    pytesseract.pytesseract.tesseract_cmd = config.TESSERACT_CMD

    # 语言包目录和参数
    tessdata_dir_config = config.TESSDATA_DIR

    # lang 指定中文简体
    region_text = pytesseract.image_to_string(
        region_im, lang='chi_sim', config=tessdata_dir_config)

    region_text = region_text.replace("_", "一").split("\n")
    texts = [x for x in region_text if x != '']
    # print(texts)
    question = ""
    choices = []

    if len(texts) > 2:
        question = texts[0]
github Maxinger15 / PokemonRumbleRushBot / bin / Player.py View on Github external
def __init__(self, init=False):
        client = AdbClient(host="127.0.0.1", port=5037)
        devices = client.devices()
        if len(devices) <= 0:
            raise ValueError("No device connected")
        self.device = client.device(str(devices[0].get_serial_no()))
        self.settings = Settings("config.cfg", init=init)
        self.adbscreen = ADBScreen(self.device)
        self.ENDC = '\033[0m'
        self.WARNING = '\033[93m'
        self.BLUE = '\033[94m'
        self.RED = '\033[91m'
        pytesseract.pytesseract.tesseract_cmd = self.settings.tesseract_dir
    def log(self, message):
github mozilla / iris / moziris / util / system.py View on Github external
.decode("utf-8")
    )
    path_not_found = False

    if OSHelper.is_windows():
        win_default_tesseract_path = "C:\\Program Files (x86)\\Tesseract-OCR"

        if "/c/" in str(which_tesseract):
            win_which_tesseract_path = (
                which_tesseract.replace("/c/", "C:\\").replace("/", "\\") + ".exe"
            )
        else:
            win_which_tesseract_path = which_tesseract.replace("\\", "\\\\")

        if _check_path(win_default_tesseract_path):
            pytesseract.pytesseract.tesseract_cmd = (
                win_default_tesseract_path + "\\tesseract"
            )
        elif _check_path(win_which_tesseract_path):
            pytesseract.pytesseract.tesseract_cmd = win_which_tesseract_path
        else:
            path_not_found = True

    elif OSHelper.is_linux() or OSHelper.is_mac():
        if _check_path(which_tesseract):
            pytesseract.pytesseract.tesseract_cmd = which_tesseract
        else:
            path_not_found = True
    else:
        path_not_found = True

    if path_not_found:
github KurtMoran / F1-Data-Extractor / F1 Data.py View on Github external
print ('Amount of green pixels = ' + str(green))
	cv2.imshow("Color", dst)
	cv2.waitKey(0)
	
	dst = cv2.inRange(roiColor, redMin, redMax)
	red = cv2.countNonZero(dst)
	
	
	if red > 0: red = 1 #Brake is binary
	
	throttleMap = interp(green,[0,12250],[0,100])    
	print('Mapped Throttle = ' + str(throttleMap))
	print('red = ' + str(red))

	pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract' #tesseract path

	##### Velocity
	print('Velocity = ' + pytesseract.image_to_string(roiVelocity, lang='F1r', config='--psm 6')) ##config='--psm 6' Assumes a single uniform block of text.
	Velocity = (pytesseract.image_to_string(roiVelocity, lang='F1r', config='--psm 6'))
	cv2.imshow("Velocity", roiVelocity)
	cv2.waitKey(0)

	##### Lap time
	print('Lap time = ' + pytesseract.image_to_string(roiLapT, lang='lapTime', config='--psm 6'))
	lapTime= (pytesseract.image_to_string(roiLapT, lang='lapTime', config='--psm 6'))
	cv2.imshow("Lap Time", roiLapT)
	cv2.waitKey(0)
	
	##### RPM
	print('RPM = ' + pytesseract.image_to_string(roiRPM, lang='F1r', config='--psm 6'))
	RPM = (pytesseract.image_to_string(roiRPM, lang='F1r', config='--psm 6',))
github SahilChoudhary22 / pdf2csv-converter / pdf2csv.py View on Github external
def jpg_to_txt(tesseractLoc, filename):
    # This is added so that python knows where the location of tesseract-OCR is
    pytesseract.pytesseract.tesseract_cmd = tesseractLoc
    # again using the function return value
    sourceImg = get_path_of_source(filename).with_suffix('.jpg')
    # Using pillow to open image
    img = Image.open(sourceImg)
    filenameOfImg = img.filename
    text = pytesseract.image_to_string(img)

    #calling the function which was defined above this function
    save_to_file_as_txt(filenameOfImg, text)
github mozilla / iris_firefox / iris / __main__.py View on Github external
def init_tesseract_path(self):

        win_tesseract_path = 'C:\\Program Files (x86)\\Tesseract-OCR'
        osx_linux_tesseract_path_1 = '/usr/local/bin/tesseract'
        osx_linux_tesseract_path_2 = '/usr/bin/tesseract'

        path_not_found = False
        current_os = Settings.get_os()

        if current_os == Platform.WINDOWS:
            if self.check_tesseract_path(win_tesseract_path):
                pytesseract.pytesseract.tesseract_cmd = win_tesseract_path + '\\tesseract'
            else:
                path_not_found = True
        elif current_os == Platform.LINUX or current_os == Platform.MAC:
            if self.check_tesseract_path(osx_linux_tesseract_path_1):
                pytesseract.pytesseract.tesseract_cmd = osx_linux_tesseract_path_1
            elif self.check_tesseract_path(osx_linux_tesseract_path_2):
                pytesseract.pytesseract.tesseract_cmd = osx_linux_tesseract_path_2
            else:
                path_not_found = True
        else:
            path_not_found = True

        if path_not_found:
            logger.critical('Unable to find Tesseract.')
            logger.critical('Please consult wiki for complete setup instructions.')
            self.finish(1)