Overlays#
Graphical overlays for QVideoScreen.
Each overlay is a pyqtgraph.GraphicsObject subclass that renders
analysis results directly on the live video image. A companion
QGroupBox widget owns the background
worker thread, exposes analysis parameters, and forwards results via a
newData signal.
Typical usage:
widget = QTrackpyWidget(parent) # or QYoloWidget
widget.source = camera_source
screen.addOverlay(widget.overlay)
widget.newData.connect(my_slot)
Trackpy#
QTrackpyWidget detects bright particles in
each video frame using the trackpy
library, which implements the Crocker–Grier algorithm [CG96]. Detected
positions are rendered in real time as a scatter-plot overlay by
QTrackpyOverlay. Particle diameter and
minimum separation are adjustable from the widget.
J.C. Crocker and D.G. Grier, “Methods of digital video microscopy for colloidal studies”, Journal of Colloid and Interface Science, 179(1):298–310, 1996.
Real-time particle tracking overlay using trackpy.
References
Allan, D. B., Caswell, T., Keim, N. C., van der Wel, C. M., & Verweij, R. W. trackpy: Fast, Friendly Particle Tracking in Python. Zenodo. https://doi.org/10.5281/zenodo.9971
Crocker, J. C., & Grier, D. G. (1996). Methods of digital video microscopy for colloidal studies. Journal of Colloid and Interface Science, 179(1), 298-310. https://doi.org/10.1006/jcis.1996.0217
- class QVideo.overlays.trackpy.QTrackpyWidget(parent=None, diameter=11, minmass=100.0, separation=None, noise_size=1, invert=False)[source]#
Bases:
QGroupBoxControl widget for the trackpy particle-tracking overlay.
Runs
trackpy.locate()in a background thread and renders detected particle positions as aQTrackpyOverlayscatter plot on aQVideoScreen.Use
screen.addOverlay(widget.overlay)to register the overlay graphics item with a screen, and setsourceto supply video frames.- Parameters:
parent (QtWidgets.QWidget or None) – Parent widget.
diameter (int) – Initial expected particle diameter [pixels]. Must be odd. Default:
11.minmass (float) – Initial minimum integrated brightness. Default:
100.separation (float or None) – Minimum separation between particle centers [pixels].
None(default) lets trackpy choose (diameter + 1).noise_size (int) – Radius of the Gaussian blur applied for noise suppression [pixels]. Default:
1.invert (bool) – If
True, invert the image before locating particles (for dark particles on a bright background). Default:False.
- newData#
Emitted for each processed frame with the
trackpy.locate()DataFrame, orNoneon error.
- property source#
The
QVideoSourcebeing tracked.
- property overlay: QTrackpyOverlay#
The
QTrackpyOverlaygraphics item for this widget.
- class QVideo.overlays.trackpy.QTrackpyOverlay(**kwargs)[source]#
Bases:
ScatterPlotItemScatter-plot overlay that marks trackpy particle positions.
A
pyqtgraph.ScatterPlotItempre-configured for particle display. Add it to aQVideoScreenviascreen.view.addItem(overlay), or usescreen.addOverlay(widget.overlay).
YOLO#
QYoloWidget runs a
YOLO object-detection model on each video
frame. Detected bounding boxes and class labels are rendered in real time by
QYoloOverlay. The confidence threshold can be
adjusted from the widget; any model supported by the Ultralytics library can
be selected at construction time.
Real-time object detection overlay using YOLO.
References
Jocher, G., Chaurasia, A., & Qiu, J. (2023). Ultralytics YOLO. ultralytics/ultralytics
Redmon, J., Divvala, S., Girshick, R., & Farhadi, A. (2016). You only look once: Unified, real-time object detection. Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, 779-788. https://doi.org/10.1109/CVPR.2016.91
- class QVideo.overlays.yolo.QYoloWidget(parent=None, model_name='yolo11n.pt', confidence=0.25)[source]#
Bases:
QGroupBoxControl widget for the YOLO object-detection overlay.
Runs YOLO inference in a background thread and renders detected object bounding boxes as a
QYoloOverlayon aQVideoScreen.Use
screen.addOverlay(widget.overlay)to register the overlay graphics item with a screen, and setsourceto supply video frames.- Parameters:
parent (QtWidgets.QWidget or None) – Parent widget.
model_name (str) – YOLO model weights file. Default:
'yolo11n.pt'.confidence (float) – Initial confidence threshold. Default:
0.25.
- newData#
Emitted for each processed frame with the detections
DataFrame, orNoneon error / no detections.
- property source#
The
QVideoSourcebeing analyzed.
- property overlay: QYoloOverlay#
The
QYoloOverlaygraphics item for this widget.
- class QVideo.overlays.yolo.QYoloOverlay[source]#
Bases:
GraphicsObjectBounding-box overlay that marks YOLO detected objects.
A
pyqtgraph.GraphicsObjectthat draws axis-aligned bounding boxes over detected objects. Add it to aQVideoScreenviascreen.addOverlay(widget.overlay).