It can be a real hassle to be a class monitor while classes are moved online during the epidemic. especially when the teacher asks you record attendance of your classmates, that’s why I got bore of looking at the list of attendees in the meeting room about three years ago and I take up with this python script in a tempt to save this once and for all.
Re-upload of the updated version of the script, original written in April 2021
import pytesseract
from PIL import ImageGrab, Image
names_to_check = ["Jack Qin", "Jack Ma", "Jack Li", "Echo", 'Ray',"Jack Chen",'Sharon',"Felix","Max","Averil"]
# make sure to switch out these names for your list LOL
def grab_image_from_clipboard():
image = ImageGrab.grabclipboard()
if isinstance(image, Image.Image):
return image
else:
raise ValueError("No image found in clipboard")
def extract_text_from_image(image):
text = pytesseract.image_to_string(image)
return text
def check_names_in_text(names, text):
absent=[]
for i in names:
if i in text:
print(i+' is present')
else:
absent.append(i)
return absent
def main():
try:
# image = Image.open("Screenshot 2024-05-25 at 12.54.48.png")
image= grab_image_from_clipboard()
extracted_text = extract_text_from_image(image)
print(f"Extracted text:\n {extracted_text}")
missing_names = check_names_in_text(names_to_check, extracted_text)
print('='*34)
if missing_names:
print("\033[1m"+" Names in the list but not in the image:")
for i in missing_names:
print(i)
else:
print("All names are present in the image.")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
main()
Make sure you actually install the dependencies:
pip install pytesseract pillow
As well as installing tesseract on the system. I found this guide to be useful
So, yeah if any of you run into the same issue of having to take attendance in an online meeting, this is the code for you. just make sure you have the screenshot in the clipboard when running this program.
Leave a Reply