How to... Connect to a Daheng Imaging camera through Python

Download the right software + sdk

Go to the Daheng Imaging Software page: From here download the file named Galaxy Windows SDK (V2). For this you will have to first make an account.

Test if connection can be made

In order to test if the camera can be reached and to change the camera settings you can start up the now downloaded program called Galaxy Viewer. Here you should be able to find your camera and connect to it. Important settings you can change are the Exposure time under Acquisition control and the Gain under Analog control.

Create Python program

Next you can try connecting to the camera through Python. For this you first need to pip install the Harvesters library with “pip install harvesters”. The following code allows you to make a single image using Python.

from harvesters.core import Harvester
import cv2

CTI_FILE_PATH = "C:/Program Files/Daheng Imaging/GalaxySDK/GenTL/Win64/GxGVTL.cti"  # The filepath to the CTI file

with Harvester() as h:
    with h.create() as ia:
        with ia.fetch() as buffer:
            component = buffer.payload.components[0]
            width = component.width
            height = component.height
            bayer =, width))
            img = cv2.cvtColor(bayer, cv2.COLOR_BayerRG2BGR)
            img = img[..., ::-1]
            cv2.imshow("image", img)