1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] How to get numbers from image using open cv?

Discussão em 'Python' iniciado por Stack, Setembro 11, 2024.

  1. Stack

    Stack Membro Participativo

    I'm trying to figure out the numerical values from the image.multi-digit numbers are fine, but there is a problem with single-digit numbers. It won't show or find them at all. I can't figure out the problem.

    def monitor_area():
    global bbox
    while True:
    if bbox is None:
    print("Žiadna oblasť nebola vybraná. Monitorovanie nemôže začať.")
    return

    # Získa snímku obrazovky vybranej oblasti
    screenshot = ImageGrab.grab(bbox)

    # Predspracovanie obrázka (zvýšenie kontrastu a jasu)
    screenshot = preprocess_image(screenshot)

    screenshot_np = np.array(screenshot)

    # Detekcia textu pomocou EasyOCR
    results = reader.readtext(screenshot_np)

    # Vypíšeme všetky detegované výsledky pre diagnostiku
    print("Výsledky OCR: ")
    for (detected_bbox, text, prob) in results:
    print(f"Detected text: '{text}', Probability: {prob}")

    # Detekcia a pokus o filtrovanie čísel, pridajme tu len diagnostiku
    detected_numbers = [text for (detected_bbox, text, prob) in results if prob > 0.4]

    if detected_numbers:
    try:
    number = int(detected_numbers[0].strip()) # Pokus o prevod prvého textu na číslo
    print(f"Detected number: {number}")
    update_button_colors(number)
    except ValueError:
    print(f"Detegovaný text nie je číslo: {detected_numbers[0]}")

    time.sleep(0.3)


    Could someone advise me how to solve this?

    Continue reading...

Compartilhe esta Página