Files
opencv-MIRROR/modules/videoio
Alexander Smorkalov fbc9bf4ba0 videoio(aravis): select the best pixel format and always output BGR
open() used to accept only Mono8/Mono12/Mono16/BayerGR8 and silently forced
the camera to Mono8 for everything else, so color cameras were degraded to
grayscale. retrieveFrame() passed the payload through as is, leaving the
demosaicing and the bit depth of the result to the caller.

open() now enumerates the pixel formats the camera offers and picks the best
one it can decode, in this order:
  1. true color   - BGR8/RGB8, BGRa8/RGBa8, BGR10/12, RGB10/12,
  2. Bayer CFA    - BayerRG/BG/GR/GB, 8, 10, 12 and 16 bit,
  3. grayscale    - Mono8, Mono10, Mono12, Mono14, Mono16.
The least deep format is preferred within a group, as the result is 8 bit
anyway. Bit packed formats are not selected, their payload cannot be mapped
to a Mat without unpacking it first.

retrieveFrame() converts whatever arrives to BGR CV_8UC3: Bayer data is
demosaiced, RGB is swapped to BGR, grayscale is replicated to three
channels and deeper formats are scaled down from their significant bits.

The pixel format description is kept in a single table, which also drives
CAP_PROP_FOURCC. Both directions of the property now cover all the formats
above instead of just four, setProperty() reports failure for a fourcc the
camera cannot provide and refreshes the cached format description, which
the old code did not do.

Note that Aravis names a Bayer pattern after its top left 2x2 tile, while
OpenCV names it after the second row, so the codes are related by an
R <-> B swap: BayerRG8 is demosaiced with COLOR_BayerBG2BGR.

An explicit payload size check is added to retrieveFrame(), the frame is no
longer wrapped in a Mat without knowing the buffer is large enough.
2026-08-31 08:41:23 +03:00
..
2025-09-05 01:00:28 +08:00