Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

tumicdq
Copy link
Contributor

@tumicdq tumicdq commented May 16, 2022

Added support for V4L2_PIX_FMT_XBGR32 and V4L2_PIX_FMT_ABGR32 pixel
formats.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake
force_builders=Custom
build_image:Custom=centos:7
buildworker:Custom=linux-f1

Added support for V4L2_PIX_FMT_XBGR32 and V4L2_PIX_FMT_ABGR32 pixel
formats.
@asmorkalov
Copy link
Contributor

Thanks a lot for the contribution. Could you point camera models that produce ARGB frames?

@tumicdq
Copy link
Contributor Author

tumicdq commented May 17, 2022

Well, I only know the one I'm working on, the Digiteq Automotive FrameGrabber4, which is a video grabber card for automotive LVDS. The card is in a "pre-production" state at the moment, so there is no fancy product page yet, but if you are interested, you can get the linux driver (which should go to the mainline kernel when ready) on the "beta" product page.

Just a note to the ARGB frames - the driver uses V4L2_PIX_FMT_ABGR32, but there is no real transparency in the pixel data, the color is always fully opaque in our case (the 4B alignment is required by some FPGA constraints/algorithms we use in the HW). V4L2_PIX_FMT_XBGR32 would probably be more appropriate, but some NVIDIA CUDA libraries we came accross do not support V4L2_PIX_FMT_XBGR32, so we use V4L2_PIX_FMT_ABGR32 for compatability.

@asmorkalov
Copy link
Contributor

According to documentation (like this https://www.kernel.org/doc/html/v4.9/media/uapi/v4l/pixfmt-packed-rgb.html) V4L2_PIX_FMT_ABGR32 and analogs have alpha channel first. OpenCV COLOR_BGRA2BGR expects alpha last. So the color conversion you propose does not fit data format.

@tumicdq
Copy link
Contributor Author

tumicdq commented May 17, 2022

Well, right now I'm looking at an (patched) opencv camera image/stream that displays correctly, so there must be some error in your understanding of the pixel data alignment either in the kernel or in opencv... Various other SW like qv4l2 or VLC also show the camera image correct, so there is almost for sure no problem in the driver. So the only explanation for me seeing a correct image and the patch code being wrong is either the opencv documentation or the opencv implementation is wrong.

I have however not tested the driver/opencv patch on a big-endian system as I do not have access to such HW. So on big-endian systems it may be wrong.

@tumicdq
Copy link
Contributor Author

tumicdq commented May 17, 2022

V4L2_PIX_FMT_ABGR32 and analogs have alpha channel first.

That's not true. The alpha channel (or the unused byte) is the last byte in memory according to the kernel documentation.

@asmorkalov
Copy link
Contributor

Sorry, I was confused by columns order. Looks good to me then.

@asmorkalov asmorkalov self-requested a review May 17, 2022 13:30
@alalek
Copy link
Member

alalek commented May 17, 2022

Broken CentOS 7 build:

/build/precommit_custom_linux/4.x/opencv/modules/videoio/src/cap_v4l.cpp:567:13: error: 'V4L2_PIX_FMT_XBGR32' was not declared in this scope
             V4L2_PIX_FMT_XBGR32,
             ^
/build/precommit_custom_linux/4.x/opencv/modules/videoio/src/cap_v4l.cpp:568:13: error: 'V4L2_PIX_FMT_ABGR32' was not declared in this scope
             V4L2_PIX_FMT_ABGR32,
             ^

Reuse approach similar to V4L2_PIX_FMT_Y10

Copy link
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done! Thank you for contribution 👍

@alalek alalek merged commit df2e7fa into opencv:4.x May 19, 2022
@alalek alalek mentioned this pull request Aug 21, 2022
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
* Added support for 4B RGB V4L2 pixel formats

Added support for V4L2_PIX_FMT_XBGR32 and V4L2_PIX_FMT_ABGR32 pixel
formats.

* Added workaround for missing V4L2_PIX_FMT_ABGR32 and V4L2_PIX_FMT_XBGR32
defines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants