import cv2
import time

def get_image():
    cap = cv2.VideoCapture(0)

    window_name = 'Camera Capture'
    countdown_duration = 60

    # Check if the camera is opened successfully
    if not cap.isOpened():
        print("Error: Could not open the camera.")
        return None

    for countdown in range(countdown_duration, 10, -1):
        ret, frame = cap.read()

        # Check if the frame is read successfully
        if not ret:
            print("Error: Could not read frame.")
            return None

        font = cv2.FONT_HERSHEY_SIMPLEX
        cv2.putText(frame, str(countdown)[0], (10, 30), font, 1, (0, 255, 0), 2, cv2.LINE_AA)
        cv2.imshow(window_name, frame)
        cv2.waitKey(100)

    output_path = 'image.png'
    cv2.imwrite(output_path, frame)

    # Release the camera capture object
    cap.release()

    # Destroy all OpenCV windows
    cv2.destroyAllWindows()

    print(f"Image saved successfully at '{output_path}'.")
    return output_path

