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.
To compile the C# library and use pynaneye, you will need:
- A Windows operating system.
- The .NET Framework 4.8 SDK https://dotnet.microsoft.com/en-us/download/dotnet-framework/net48
- The AMS/OSRAM NanEye SDK (see below)
-
Download and Install the NanEye C# SDK:
- Visit the product page: https://ams-osram.com/products/sensor-solutions/cmos-image-sensors/ams-naneyem-miniature-camera-modules
- Direct download link: https://ams-osram.com/o/download-server/document-download/download/29941803
- Install the SDK on your Windows machine.
-
Run
install_naneye_dlls.py(located in thepynaneyefolder 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, orlib/win32folder from your SDK installation, depending on your system's architecture.
- Follow the instructions in the wizard that appears. You will be prompted to select the
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.
Run build_pynaneye.bat (or source build_pynaneye.bat in Bash). Or:
cd csharp
dotnet build csharp_naneye.sln -c ReleaseThe compiled PyNanEye.dll will be located in the csharp/bin/Release/net48 directory.
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]
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()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)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.