0

My question is pretty simple, but I haven’t been able to work it out. Basically, what I want to do is, I want to read a 4-digit keyword off a picture posted on Discord every x minutes. This picture will appear on my screen, of course, I just want to be able to read the text on the image, and then grab the 4 digit keyword on it.

Here’s what the image looks like: [1]: https://i.stack.imgur.com/E2uwY.jpg

The keyword I want to grab is at the bottom of the image.

In short, I want to grab a code from an image that will appear every x minutes on my screen. The code will be at the bottom of the image, and the coordinates of both the image and the code will always be same (as in, they will appear in the same place on my screen every single time).

  • if my answer has solved your question, could you please mark it as the selected answer by clicking on the tick icon next to the answer ? – Vandan Revanur May 29 '22 at 07:06

2 Answers2

1

To automate the process of screenshotting check this answer: Python: Fastest way to take and save screenshots

Once you have the image stored locally, then you could accomplish the code grabbing with the OCR library : pytesseract and the computer vision library opencv.

Install them like this:

pip install pytesseract
pip install opencv-python

And then with your image (image.jpeg) run the following code:

import cv2
import pytesseract
img = cv2.imread("image.jpeg")
img = cv2.resize(img, (400, 450))
cv2.imshow("Image", img)
text = pytesseract.image_to_string(img)
print(text)
cv2.destroyAllWindows()

I tested it and it outputs the code:

FTO2
Vandan Revanur
  • 459
  • 6
  • 17
0

Given that the location and the timings can be predicted, check PyTesseract out. Here's a tutorial to get you started.