Skip to content

Build the OpenCV plugin on the camera base class - #16

Merged
seb5g merged 1 commit into
mainfrom
feat/camera-base
Oct 27, 2026
Merged

seb5g merged 1 commit into
mainfrom
feat/camera-base

Conversation

@seb5g

@seb5g seb5g commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Before: DAQ_2DViewer_OpenCV read one frame per grab_data call, so there was no thread of its own, no ROI, no binning, no FPS and no averaging in the plugin (the viewer averaged). 'win' in platform also selected the Windows backend on macOS (darwin contains win), and the settings list included the DC1394 mode registers.

After: the plugin is a CameraBase of pymodaq_plugins_utils, like the other camera plugins (the cookbook camera of pymodaq_plugins_mockexamples is the reference). It has the live and snap modes in a thread of its own, averaging, the ROI drawn in the viewer, binning and FPS. The OpenCV part moved to a driver, hardware/opencv_camera.py (OpenCVCamera), that follows the CameraDriverBase interface: wait_for_frame reads the next frame, and the ROI and the binning (mean of the pixels) are applied on each image since a webcam has none. The windows backend is chosen with sys.platform.startswith('win').

What changes for users:

  • the Colors setting is replaced by the Color Conversion of the base class (default RGB2GRAY, like the former gray; None gives the red, green and blue channels). Experiments that set colors need color_conversion instead.
  • the exposure time and buffer settings of the base class are hidden: the exposure of OpenCV has backend dependent units and stays in Cam. Settings, with brightness, gain... as before (modes of the DC1394 registers are no longer listed). Changing the frame width or height there resets the ROI and updates the axes.

How: new tests/test_opencv_camera.py (25 tests). The driver is run on a video file by the real OpenCV (frames are RGB, colours checked) and on a fake of cv2.VideoCapture for what a file cannot do (properties, failing reads, a change of the frame size); the plugin is run through the harness of pymodaq.utils.plugin_testing on the fake: snap, channels, averaging, ROI, binning, live, ROI change during live, change of frame size, close. check_plugin reports no error and no TODO. No real webcam was available: please try it on a laptop (live view, ROI from the viewer, binning, Open Settings on Windows).

This needs pymodaq_plugins_utils>=5.3.1 (the camera base class), which is not released yet, so the checks of this pull request fail at the install until it is. Independent of #15 (alignment with the template).


Generated by Claude Code

The driver (OpenCVCamera) follows the CameraDriverBase interface of pymodaq_plugins_utils;
the plugin is a CameraBase with the properties of the camera as settings.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tdiso1u1ZhikSutj2Qs5Cg
@seb5g
seb5g merged commit 9931a91 into main Oct 27, 2026
5 of 7 checks passed
@seb5g
seb5g deleted the feat/camera-base branch October 27, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants