Skip to content
⚡ Developer documentation for INFINICAM, the real-time high-speed camera (UC-1.1 / GbE-2)

HelloWorld (connecting to the camera)

The most basic program: it connects to the INFINICAM GbE-2 and displays information about the camera. The flow used here, “connect to the camera” and “close it when you are done”, is the foundation for every other sample.

  1. Enter and save the program

    Open Notepad, paste the following code, and save it as hello_camera.py in C:\infinicam_projects\python (set “Save as type” to All files and “Encoding” to UTF-8).

    from pypuclib import CameraFactory, PUCException
    print("Connecting to the camera...")
    try:
    # Connect to the GbE-2 at this IP address
    cam = CameraFactory().create(ip="192.168.0.10")
    except PUCException as e:
    print("Error: could not connect to the camera.", e)
    raise SystemExit(1)
    print("Connected.")
    print("Serial number:", cam.serialNo())
    reso = cam.resolution()
    print("Resolution:", reso.width, "x", reso.height)
    print("Frame rate:", cam.framerate(), "fps")
    # Close the camera when you are done with it
    cam.close()
    print("Done.")
  2. Run it

    Connect the camera and run the following 2 lines, one at a time, in Command Prompt (or PowerShell).

    Terminal window
    cd C:\infinicam_projects\python
    Terminal window
    python hello_camera.py

    If you see output like the following, it worked (the serial number and frame rate depend on your camera).

    Connecting to the camera...
    Connected.
    Serial number: 99334002087
    Resolution: 800 x 600
    Frame rate: 1000 fps
    Done.

from pypuclib import CameraFactory, PUCException

This takes the 2 parts the program uses out of pypuclib.

Part Role
CameraFactory The “front desk” that finds and connects to cameras
PUCException The type of error raised when a camera operation fails
try:
cam = CameraFactory().create(ip="192.168.0.10")
except PUCException as e:
print("Error: could not connect to the camera.", e)
raise SystemExit(1)
  • create(ip="192.168.0.10") connects to the GbE-2 at this IP address. When the connection succeeds, you get cam, which you use to control the camera. From then on you control the camera in the form cam.something().
  • try: … except is how Python lets you write “what to do if this fails”. If the camera cannot be found, for example, a PUCException is raised, so the program prints the error and exits.
  • raise SystemExit(1) ends the program at that point.
print("Serial number:", cam.serialNo())
reso = cam.resolution()
print("Resolution:", reso.width, "x", reso.height)
print("Frame rate:", cam.framerate(), "fps")
Call What it reads
cam.serialNo() The serial number (the same number as on the label on the back of the camera)
cam.resolution() The current resolution. Use .width and .height to get the width and height
cam.framerate() The current frame rate (frames captured per second)
cam.close()

Always close the camera with close() when you are done. A camera can be used by only one program at a time, so if you don’t close it, other programs or the sample software may not be able to connect.


If you get an error, see Setting up a Python development environment. If you cannot connect to the camera, check these 2 things: