Skip to content

Added support for V4L2_PIX_FMT_Y16 - #7196

Closed
stbnps wants to merge 1 commit into
opencv:masterfrom
stbnps:master
Closed

stbnps wants to merge 1 commit into
opencv:masterfrom
stbnps:master

Conversation

@stbnps

@stbnps stbnps commented Aug 29, 2016

Copy link
Copy Markdown
Contributor

Resolves #7194

  • Changed cap_v4l.cpp so that opencv tries to use V4L2_PIX_FMT_Y16.
  • convert_rgb is turned off when using Y16 since it is a monochrome format.
  • When using Y16 the module sets the image depth to IPL_DEPTH_16U.

@alalek

alalek commented Aug 30, 2016

Copy link
Copy Markdown
Member

sets the image depth to IPL_DEPTH_16U

I believe, by default video capture should provide BGR/Gray 8U image. Switching to 16UC1 is possible after explicit additional property settings by user for CV_CAP_PROP_CONVERT_RGB or CV_CAP_PROP_FORMAT (which value looks like incorrect at this moment because it still uses 8U) or CAP_PROP_MODE.
There is some discussion in #5485 about support of custom modes, but unfortunately there is no approved architecture decision.

@vpisarev

Copy link
Copy Markdown
Contributor

@stbnps, I agree with @alalek. Your patch changes the default behavior of video capturing functionality in the case of one specific backend. Many OpenCV samples assume that the output from video capture is 8-bit 3-channel RGB image. Anything else should be explicitly configured using VideoCapture::set(int) method. Please, add some video capturing property (or a few) and set this property/properties in the beginning of your app when using VideoCapture

@Algomorph

Algomorph commented Sep 13, 2016 •

Copy link
Copy Markdown
Contributor

@alalek, @stbnps Could you explain how does the patch change the behavior of video capturing functionality?

  • The ``autosetup_capture_mode_v4l2` function picks BGR and a large list of "default-behavior" formats before it ever gets to Y16.

  • Y16 format is defined to yield 16-bit greyscale single-channel... If the user wants a BGR image, they should not use Y16 format in the first place, that defies all logic.

    I think what's really missing here is the ability to explicitly set the CV_CAP_PROP_FOURCC property in the icvSetPropertyCAM_V4L function. I have implemented a patch for that, but it goes on top of this patch, so I cannot make a pull request until this is accepted.
    Real-life example: I have a USB-3 stereo camera called "Tara" from e-con systems. With only this patch, it defaults to BGR and produces some wacky output. With my patch on top of that, I manually set the CV_CAP_PROP_FOURCC to Y16, and the capture works correctly.

@alalek

alalek commented Sep 13, 2016 •

Copy link
Copy Markdown
Member

I mean, that the most part of user applications assumes these conditions of VideoCapture behavior:

VideoCapture cap;
cap.open(...);
// no calls for set properties
Mat frame;
cap >> frame;
assert(frame.depth() == CV_8U);
assert(frame.channels() == 3);

wacky output

It is a bug, but VideoCapture backend should convert camera format to BGR 8U by default, but it should not change output format to CV_16U.

@Algomorph

Algomorph commented Sep 13, 2016 •

Copy link
Copy Markdown
Contributor

@alalek I respectfully disagree, to me it makes no sense to have a camera that only supports Y16, under default behavior, yield BGR 8-bit images (which will essentially contain garbage? Or should these be converted to 8-bit single-channel, then replicated to 2 other channels to yield a "BGR" image?). However, seeing that the patch won't get accepted without the changes you suggested, I'll try to implement them on my end and make a new PR from my fork.

@alalek

alalek commented Sep 13, 2016

Copy link
Copy Markdown
Member

Yes, return "gray" 8U image with cloned channels.

No need to make a new PR, just update this.

if (try_palette_v4l2(capture)) {
if (capture->palette == V4L2_PIX_FMT_Y16) {
capture->convert_rgb = false;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Problem is here.
capture->convert_rgb = false should be changed explicitly by user only (via set property call with CV_CAP_PROP_CONVERT_RGB = false).

@Algomorph

Algomorph commented Sep 15, 2016 •

Copy link
Copy Markdown
Contributor

@alalek , I implemented and tested the changes. I'll need you to verify that the way I'm doing setting CV_CAP_PROP_FOURCC is okay. The changes don't seem to have broken anything, but I only tested with two different cameras. I understand now what you meant by default behavior, I didn't realize there was a conversion involved.

However, you said I can just modify this PR? How do I do this, since it's not mine?

P.S. added my own PR here: #7293

@alalek

alalek commented Sep 15, 2016

Copy link
Copy Markdown
Member

@Algomorph thanks!
This PR is replaced by #7293.

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.

4 participants