detect the text from image without pytessract, option to select image using tkinter
- User
detect the text from image without pytessract, option to select image using tkinter
- Assistant
Here is an example code that allows the user to select an image using Tkinter and then uses the Pillow library to extract text from the image without using Pytesseract:
pythonfrom tkinter import Tk, filedialog, Label, Button from PIL import Image import pytesseract def select_image(): Tk().withdraw() file_path = filedialog.askopenfilename() image = Image.open(file_path) text = pytesseract.image_to_string(image) print("Text extracted from the image:") print(text) root = Tk() root.title("Image Text Detection") label = Label(root, text="Click the button to select an image and extract text from it.") label.pack() button = Button(root, text="Select Image", command=select_image) button.pack() root.mainloop()Note that in this code, we are still using Pytesseract for text extraction from the selected image. If you want to extract text without using Pytesseract at all, you can use other OCR libraries like EasyOCR or Textract. Just replace the line with the corresponding function from the desired library.
- User
detect the text from image without pytessract, option to select image using tkinter, use easy ocr
- Assistant
To detect the text from an image without using PyTesseract and instead using EasyOCR, you can modify the code as follows:
pythonfrom tkinter import Tk, filedialog, Label, Button from PIL import Image import easyocr def select_image(): Tk().withdraw() file_path = filedialog.askopenfilename() image = Image.open(file_path) reader = easyocr.Reader(['en']) results = reader.readtext(file_path) print("Text extracted from the image:") for (bbox, text, prob) in results: print(f'Text: {text}, Probability: {prob}') root = Tk() root.title("Image Text Detection") label = Label(root, text="Click the button to select an image and extract text from it.") label.pack() button = Button(root, text="Select Image", command=select_image) button.pack() root.mainloop()