import cv2, pytesseract
from tkinter import Tk, filedialog, messagebox, Text, Button, Label

def extract_text(image_path):
    image = cv2.imread(image_path)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    gray = cv2.resize(
        gray, None, fx=2, fy=2,
        interpolation=cv2.INTER_CUBIC
    )
    text = pytesseract.image_to_string(gray, config="--psm 6")
    return text

def select_image():
    file_path = filedialog.askopenfilename(
        filetypes=[("Image Files", "*.png *.jpg *.jpeg")]
    )
    if file_path:
        extracted_text = extract_text(file_path)
        text_area.delete("1.0", "end")
        text_area.insert("1.0", extracted_text)

if __name__ == "__main__":
    teksti = extract_text("/polku/kuva.jpg")
    print(teksti)
