Changing capture settings + SingleImage
This sample changes the INFINICAM GbE-2’s resolution, frame rate, and shutter speed from a program and captures one image.
-
Enter and save the program
Save the following code as
single_image_settings.pyinC:\infinicam_projects\python.import cv2from pypuclib import CameraFactory, PUCExceptionprint("Connecting to the camera...")try:# Connect to the GbE-2 at this IP addresscam = CameraFactory().create(ip="192.168.0.10")except PUCException as e:print("Error: could not connect to the camera.", e)raise SystemExit(1)try:reso = cam.resolution()framerate, shutter = cam.framerateShutter()print(f"Settings when connected: {reso.width} x {reso.height} / {framerate} fps / shutter 1/{shutter} s")# Change the resolution (width and height must be multiples of 8)cam.setResolution(800, 320)# Change the frame rate and shutter speed (1000 fps, shutter 1/2000 s)cam.setFramerateShutter(1000, 2000)reso = cam.resolution()framerate, shutter = cam.framerateShutter()print(f"After the change: {reso.width} x {reso.height} / {framerate} fps / shutter 1/{shutter} s")# Take one frame with the new settings and save it as PNGimage = cam.decoder().decode(cam.grab())filename = "custom_setting_image.png"cv2.imwrite(filename, image)print(f"Saved: {filename} (size: {image.shape[1]} x {image.shape[0]})")except PUCException as e:print("Error: could not change the settings or capture.", e)finally:cam.close() -
Run it
Run the following 2 lines, one at a time, in Command Prompt (or PowerShell).
Terminal window cd C:\infinicam_projects\pythonTerminal window python single_image_settings.pyIf you see the following and a 320-pixel-tall image
custom_setting_image.pngis created, it worked.Connecting to the camera...Settings when connected: 800 x 600 / 1000 fps / shutter 1/1000 sAfter the change: 800 x 320 / 1000 fps / shutter 1/2000 sSaved: custom_setting_image.png (size: 800 x 320)
How the program works
Section titled “How the program works”1. Read the current settings
Section titled “1. Read the current settings”reso = cam.resolution()framerate, shutter = cam.framerateShutter()cam.framerateShutter() returns 2 values at once: the frame rate and the shutter speed. With 2 variables on the left, as in framerate, shutter = ..., you receive each one separately.
2. Change the resolution
Section titled “2. Change the resolution”cam.setResolution(800, 320)- Specify the width and height. Width and height must be multiples of 8.
- Making the resolution (especially the height) smaller raises the maximum frame rate you can set. At 800 × 600 you can set up to 1,000 fps; at 800 × 48, up to 10,000 fps.
3. Change the frame rate and shutter speed
Section titled “3. Change the frame rate and shutter speed”cam.setFramerateShutter(1000, 2000)| Argument | Meaning | Example |
|---|---|---|
| First | Frame rate (frames captured per second) | 1000 = 1,000 fps |
| Second | Denominator of the shutter speed | 2000 = 1/2000 s |
The shutter speed (exposure time) cannot be longer than the time to capture one frame (1/frame rate). The second value must be greater than or equal to the first (1000 or more at 1,000 fps).
