How to get an image from a GenICam-compatible camera (e.g. a Genie Nano) using Harvester

Based on contributions by Jesse.

Harvester is a vendor-neutral Python library for GenICam-compatible cameras, such as a Genie Nano. This how-to sets up a conda environment, installs a GenTL producer, and gets you to a first captured, white-balanced image in Jupyter Notebook.

This how-to follows the official Harvesters documentation.

What you need

  • Anaconda (or Miniconda) with Jupyter Notebook.
  • A GenICam-compatible camera (e.g. a Genie Nano).
  • A GenTL producer for your camera (see step 3).

Steps

1. Create a dedicated conda environment

Using a dedicated environment means that if something gets corrupted, you can just delete it and start over. This guide uses Python 3.8, which is known to work with Harvesters; newer versions should also work, but 3.8 is a safe fallback if you run into trouble.

conda create -n genicam python=3.8
conda activate genicam

2. Install the required libraries

With the environment active (the prompt should now start with (genicam) instead of (base)):

conda install ipython
python -m pip install harvesters

You’ll also want matplotlib to display captured images, and OpenCV (including the contrib package, used later for white balance):

python -m pip install matplotlib opencv-python opencv-contrib-python

To be able to select this environment as a kernel in Jupyter Notebook, register it:

conda install ipykernel
python -m ipykernel install --user --name genicam --display-name "GenICam"

You should now be able to select this environment as a kernel in Jupyter Notebook. When you’re done installing, exit the environment:

conda deactivate

3. Download a GenTL producer

Harvester needs a GenTL producer to talk to the camera. ImpactAcquire is a good option.

  1. Download and install the latest version of ImpactAcquire for your machine.
  2. Find your GenTL producer file: on Windows, go to C:\Program Files\Balluff\ImpactAcquire and search for *.cti. It’s usually named something like mvGenTLProducer.cti. Note down the exact path, you’ll need it in the next step.

4. Acquire an image

Run this cell once, to set up the harvester and the capture function:

from harvesters.core import Harvester
import matplotlib.pyplot as plt
import numpy as np
import cv2
from genicam.gentl import TimeoutException

# Global declaration of h and buffer
h = None
buffer = None


class DeviceListException(Exception):
    pass


def init_harvester():
    global h
    h = Harvester()
    h.add_file(r"{path/to/.cti/file}")
    h.update()

    if len(h.device_info_list) == 0:
        raise DeviceListException("Device list is empty")


def init_ia():
    global ia
    ia = h.create()
    ia.start()
    return ia


def take_photo(ia):
    global buffer  # make the buffer global so it can be released in `finally`
    buffer = ia.fetch(timeout=3000)

    if buffer is None:
        raise ValueError("No buffer received")

    component = buffer.payload.components[0]
    width = component.width
    height = component.height
    img = component.data.reshape((height, width))

    if img is None:
        raise ValueError("Image is empty")
    return img


try:
    init_harvester()
except DeviceListException as e:
    print(e)

Run this second cell every time you want a new image:

try:
    ia = init_ia()
    img = take_photo(ia)

    # Genie Nano uses the Bayer-RG color format
    rgb_img = cv2.cvtColor(img, cv2.COLOR_BAYER_RG2RGB)

    # White-balance the image
    wb = cv2.xphoto.createSimpleWB()
    corrected_img = wb.balanceWhite(rgb_img)

    # Display the white-balanced image
    plt.figure(figsize=(8, 6))
    plt.imshow(cv2.cvtColor(corrected_img, cv2.COLOR_BGR2RGB))  # convert BGR to RGB for display
    plt.title("White-balanced image")
    plt.axis("off")
    plt.show()

except TimeoutException as e:
    print(e)
except ValueError as e:
    print(e)
except Exception as e:
    print(f"Something else went wrong: {e}")

finally:
    # Queue the buffer for the next image
    if buffer is not None:
        buffer.queue()

    # Close the connection to the camera
    if ia is not None:
        ia.stop()
        ia.destroy()

While installing, you should see output similar to:

pip install harvesters output

Troubleshooting

  • DeviceListException: Device list is empty: double-check the .cti path passed to h.add_file(), and that the camera is actually connected and powered.
  • TimeoutException on ia.fetch(): the camera didn’t deliver a frame in time; check the connection and trigger settings, or increase the timeout.

Related


Rewritten and consolidated (Sept 2026) from the original student how-to’s: How to get an image from a GenICam compatible camera (eg. a Genie Nano) using Harvester.