A small Python interface for the Lightel DI-2000 USB digital inspector.
The public DI-2000 documentation describes a USB video camera but does not publish a command protocol or SDK. This package therefore uses the operating system's camera driver through OpenCV. It supports camera discovery, connection, frame acquisition, image capture, and standard UVC/OpenCV properties.
pip install .For development:
pip install -e ".[dev]"
python -m pytestfrom di2000 import Di2000, find_devices
print("Camera indexes:", find_devices())
inspector = Di2000()
inspector.connect(0)
try:
frame = inspector.read_frame()
saved_path = inspector.capture_image("inspection.png")
print(saved_path)
finally:
inspector.disconnect()On Windows, Lightel's installed camera driver may work better through DirectShow:
import cv2
from di2000 import Di2000
with Di2000() as inspector:
inspector.connect(0, backend=cv2.CAP_DSHOW)
inspector.capture_image("inspection.png")Standard camera controls can be attempted through OpenCV:
import cv2
inspector.set_autofocus(True)
inspector.set_property(cv2.CAP_PROP_BRIGHTNESS, 100)
print(inspector.get_property(cv2.CAP_PROP_BRIGHTNESS))Lightel has published the probe's capture button, onboard autofocus
trigger, and autofocus status as a UVC Extension Unit (confirmed by USB
descriptor enumeration against unit: bUnitID=3, GUID
63610682-5070-49AB-B8CC-B3855E8D221D), documented at
kernel.org's uvcvideo driver doc
and Microsoft's UVC 1.5 extensions doc.
inspector.trigger_autofocus()
status = inspector.get_autofocus_status() # AutofocusStatus.RUNNING / DONE_OK / DONE_FAILED
pressed = inspector.get_capture_button_pressed()Linux only for now, via the kernel's UVCIOC_CTRL_QUERY ioctl on
/dev/videoN -- the same mechanism the kernel doc above describes, and the
standard way to reach a UVC extension unit without disturbing an active
V4L2 video stream. There's no macOS implementation: the built-in
AVFoundation UVC driver holds the interface with no user-accessible way to
detach it, so raw USB control transfers there fail at the OS level, not at
the device. Windows would need a separate implementation (DirectShow/Media
Foundation).
inspection.autofocus() uses trigger_autofocus()/get_autofocus_status()
automatically when the camera object exposes them (see AutofocusResult.method),
falling back to the generic UVC/manual-sweep heuristics otherwise.
find_devices() returns all camera indexes OpenCV can open, not only Lightel
devices. Disconnect other cameras or try each returned index and inspect a
frame.
inspection.py builds on top of a connected Di2000 to bring the fiber end into focus, classify whether the shot is front- or back-illuminated (there is no UVC control to read this from hardware, so it's detected from the image), expose for that mode, and flag dirt/debris.
from di2000 import Di2000
from inspection import inspect
with Di2000() as inspector:
inspector.connect(0)
result = inspect(inspector)
print(result.illumination.mode, result.defect_area_fraction, result.passed)The individual stages (locate_fiber_end, autofocus, classify_illumination,
autoexpose, detect_defects) are also usable on their own, and all operate
on plain numpy frames so they can be tested without a camera.
gui.py is a small PySide6 app
pip install -e ".[gui]"
python gui.py
# or, after install: lightel-inspect-gui