[Python] Raspberry Pi Freezing Up (No keyboard/mouse input)

Discussão em 'Python' iniciado por Stack, Junho 16, 2025.

  1. Stack

    Stack Membro Participativo

    I'm running a fairly simple function that should take two images (which I have taken via gphoto2) and display them to the user in a simple opencv gui. My program works well until the display command is reached. The displayed window itself is small with just a black screen, and at this point I believe the program stops running. I lose the ability to input to the pi in any way, and can only unplug/plug in the pi to restore function. I'm not sure why this is happening. Below is the function. There is a helper function I've commented out that serves to crop and resize the images; I got the same issue with and without calling that function.

    import cv2
    import numpy as np

    def confirm_images(front_image, back_image):
    # front_image = auto_crop_and_resize(front_image)
    # back_image = auto_crop_and_resize(back_image)

    if front_image is None or back_image is None:
    print(f"Error processing images")
    return

    front_img = cv2.imread(front_image)
    back_img = cv2.imread(back_image)

    if front_img is None or back_img is None:
    print(f"Error: Could not load images.")
    return

    height = min(front_img.shape[0], back_img.shape[0])
    front_img = cv2.resize(front_img, (int(height * 1.5), height))
    back_img = cv2.resize(back_img, (int(height * 1.5), height))
    combined_img = np.hstack((front_img, back_img))
    cv2.imshow("Confirm Images (Front & Back)", combined_img)

    screen_width = 1920
    screen_height = 1080

    img_height, img_width = combined_img.shape[:2]

    x = int((screen_width - img_width) //4)
    y = int((screen_height - img_height) //4)

    cv2.moveWindow("Confirm Images (Front & Back)", 1, 1)

    print("Press **'y'** to confirm and proceed or **'n'** to retake images.")
    key = cv2.waitKey(0)

    cv2.destroyAllWindows()

    if key == ord('n'):
    print("Retaking images...")
    intake_process()
    else:
    print("Images confirmed.")

    Continue reading...

Compartilhe esta Página