Getting Started with Python and Camera

From The Imaging Source Knowledgebase
Jump to navigation Jump to search

With Python, as well as with C, C++ and C# you can do everything needed:

  • Display a video stream
  • Capture single images, manual and automatically
  • Capture video files
  • Set all camera properties


Installation: python3 -m pip install imagingcontrol4

Driver: The GenTL Producer for your The Imaging Source Camera from

Documentation: IC Imaging Control 4 Python Library

Samples: [

Sample script for grabbing an image:

import imagingcontrol4 as ic4

# Create a Grabber object
grabber = ic4.Grabber()

# Open the first available video capture device
first_device_info = ic4.DeviceEnum.devices()[0]

# Set the resolution to 640x480
grabber.device_property_map.set_value(ic4.PropId.WIDTH, 640)
grabber.device_property_map.set_value(ic4.PropId.HEIGHT, 480)

# Create a SnapSink. A SnapSink allows grabbing single images (or image sequences) out of a data stream.
sink = ic4.SnapSink()
# Setup data stream from the video capture device to the sink and start image acquisition.
grabber.stream_setup(sink, setup_option=ic4.StreamSetupOption.ACQUISITION_START)

    # Grab a single image out of the data stream.
    image = sink.snap_single(1000)

    # Print image information.
    print(f"Received an image. ImageType: {image.image_type}")

    # Save the image.

except ic4.IC4Exception as ex:
# Stop the data stream.


Installation: At in chapter “SDKs”. Download “tiscamera” for your Linux platform.

Driver: not needed.

Documentation: tiscamera

Samples: and

Sample script for live stream:

import time
import sys
import gi

gi.require_version("Gst", "1.0")

from gi.repository import Gst

def main():

    Gst.init(sys.argv)  # init gstreamer

    serial = None

    pipeline = Gst.parse_launch("tcambin name=bin "
                                " ! videoconvert"
                                " ! ximagesink sync=false")

    # retrieve the bin element from the pipeline
    camera = pipeline.get_by_name("bin")

    # serial is defined, thus make the source open that device
    if serial is not None:
        camera.set_property("serial", serial)


    print("Press Ctrl-C to stop.")

    # We wait with this thread until a
    # KeyboardInterrupt in the form of a Ctrl-C
    # arrives. This will cause the pipline
    # to be set to state NULL
        while True:
    except KeyboardInterrupt:

if __name__ == "__main__":

Additional information for PI5, which may also is necessary for PI4:

Packets to be installed:

sudo apt install python3-gi python3-gst-1.0

Additionally OpenCV can be installed

sudo apt install python3-opencv

This shows, how to do that with apt. It should work similar with pip3. It is not a good idea to mix apt and pip3 installations.

For further questions, please use our contact form