Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4803

Camera board • Re: RaspberryPi Camera module 3 WIDE resolution

$
0
0
Hello! These were the changes that I made according to your indications:

Code:

from gpiozero import Buttonimport timeimport osfrom picamera2 import Picamera2from libcamera import controlsdef capture_images(interval, duration, output_folder):        camera = Picamera2()    preview_config = camera.create_preview_configuration()    capture_config = camera.create_still_configuration()    camera.configure(preview_config)    camera.start(show_preview=True)    try:        os.makedirs(output_folder, exist_ok=True)        image_count = 0        start_time = time.time()                # Set exposure time        camera.set_controls({'ExposureTime': 5000}) # Example: 5000 microseconds (0.005 seconds)        camera.set_controls({'AfMode': controls.AfModeEnum.Manual})        camera.set_controls({'LensPosition': 0.5})  # Set focus distance: 2 meters                while time.time() - start_time < duration:            # Capture image            image_path = os.path.join(output_folder, f"image_{image_count:04d}.jpg")            camera.switch_mode_and_capture_file(capture_config, image_path)            print(f"Captured {image_path}")            image_count += 1            time.sleep(interval)                except KeyboardInterrupt:        print("Stopping image capture")    finally:        camera.close()# Define button with its BCM pin number and enable internal pull-upcenter_button = Button(24, pull_up=True)folder_counter = 1  # Initialize folder counterwhile True:        if center_button.is_pressed:                print("Center pressed")                output_folder = f"/home/Documents/Images_{folder_counter}"        interval = 4  # Interval between captures in seconds        duration = 40  # Duration for capturing images in seconds                capture_images(interval, duration, output_folder)        folder_counter += 1  # Increment folder counter for next button press        time.sleep(20)  # Debounce delay to avoid multiple triggers
Are the changes well made? Am I configuring the focus (at 2 meters) and the resolution correctly?
I appreciated the help. Thank you very much! :D

Statistics: Posted by BeaPeCo — Tue Jul 16, 2024 8:25 am



Viewing all articles
Browse latest Browse all 4803

Trending Articles