N
N
Nutikss2021-09-04 11:45:46
Python
Nutikss, 2021-09-04 11:45:46

Why doesn't the program output anything to the command line?

Hello, I am a very strong python newbie. Faced such a problem, when looping the script, the text from the screen should be output to the console in real time, with any change, but this does not happen, although the script works. Screenshots are taken with this no problem. If the script is not looped, then the text is displayed once and everything is fine with that.

import time
import numpy as np
import pyscreenshot as ImageGrab
import cv2
import os
import pytesseract
import re 
 
 
filename = 'Image.png'
x = 1
last_time = time.time()
 
while(True):
    screen =  np.array(ImageGrab.grab(bbox=(0, 680, 454, 1007)))
    #print('loop took {} seconds'.format(time.time()-last_time))
    last_time = time.time()
    #cv2.imshow('window',cv2.cvtColor(screen, cv2.COLOR_BGR2RGB))
    cv2.imwrite(filename, screen)
    x = x + 1
    #print(x)
    #if x == 2:
      #cv2.destroyAllWindows()
      #break
img = cv2.imread('Image.png')
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
text = pytesseract.image_to_string(img)
print(text)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Developer, 2021-09-04
@Nutikss

Well, you have an infinite loop and it just doesn’t reach the output of the text

i'm a very strong newbie

Perfectly! Will have to remember this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question