Skip to content

KCL-BMEIS/pynaneye

Repository files navigation

pynaneye

A Python interface for the AMS/Osram NANO-FIB-BOX_EVM_MO Evaluation Kit for NanEye cameras. Frame from two cameras connected to a evaluation kit cane be streamed to Python simultaneously. This package requires a compiled C# DLL to function. The C# source code is included in this repository in the csharp directory. You will need to compile this code before you can use the Python interface.

Prerequisites

To compile the C# library and use pynaneye, you will need:

Installation

1. Clone this repository or download a release

2. Install AMS/Osram SDK

  1. Download and Install the NanEye C# SDK:

  2. Run install_naneye_dlls.py (located in the pynaneye folder created when you cloned the repo):

    • Follow the instructions in the wizard that appears. You will be prompted to select the lib/x64, lib/x86, or lib/win32 folder from your SDK installation, depending on your system's architecture.

The script will then copy the required DLLs and firmware files into the csharp/lib/naneye directory within this project, enabling the Python application to interface with the camera.

3. Compile pynaneye with the .NET CLI

Run build_pynaneye.bat (or source build_pynaneye.bat in Bash). Or:

cd csharp
dotnet build csharp_naneye.sln -c Release

The compiled PyNanEye.dll will be located in the csharp/bin/Release/net48 directory.

4. Install into your project's Python environment with pip

pip install <path to pynaneye>

or if you want to run the examples, automatically install OpenCV at the same time with

pip install <path to your pynaneye clone>[examples]

Usage

See example.py for a working example using OpenCV for display. Here's a minimal example:

import time
from pynaneye import Camera, NanEyeSensorType, SensorChannel
from pynaneye.frame import NanEyeFrame

def handle_new_frame(frame_data: dict) -> None:
    """ Implement your own frame handling function, or use FrameQueue (see below)"""
    frame = NanEyeFrame(**frame_data)  # you can convert a frame data dict to a NanEyeFrame dataclass
    frame_pixels_array = frame.as_array()  # NanEyeFrame can then provide pixels as a numpy array

sensor_channel = SensorChannel.CH1
camera = Camera(NanEyeSensorType.NanEyeM, sensor_channel)
camera.SubscribeToImageProcessedEvent(handle_new_frame)  # handle_new_frame will be called every time a new frame arrives

camera.StartCapture()

time.sleep(5)

camera.StopCapture()

Frame Handling with FrameQueue

The pynaneye.FrameQueue class provides a mechanism for transferring frames from the camera to your Python application. Old, unread frames are discarded to ensure the application always has access to the most recent data. When using a dual-sensor setup (SensorChannel.BOTH), the FrameQueue automatically synchronizes the streams by their timestamps. You can use a FrameQueue to access your frames by subscribing it to the ImageProcessed event:

sensor_channel = SensorChannel.BOTH
camera = Camera(NanEyeSensorType.NanEyeM, sensor_channel)
frame_queue = FrameQueue(sensor_channel)
camera.SubscribeToImageProcessedEvent(frame_queue.put)

How it works

This package uses the pythonnet library to load and interact with the compiled C# DLL. The Python Camera class is a wrapper around the .NET Camera class, and it handles the initialization of the .NET runtime.

About

A Python interface for the ams OSRAM NanEye camera module evaluation kit

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages