Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting size and subtype is ignored / Hints for a solution #6

Open
bambusch opened this issue Nov 7, 2012 · 3 comments
Open

Setting size and subtype is ignored / Hints for a solution #6

bambusch opened this issue Nov 7, 2012 · 3 comments

Comments

@bambusch
Copy link

bambusch commented Nov 7, 2012

Hi Theo,

first of all, thank you for that useful piece of code!

When I tried to set another size and another fourcc, it was always ignored and the default settings were taken.

After a while I figured out, that in the method "setSizeAndSubtype" (Line 1656) you calculate lSampleSize = attemptWidth_attemptHeight_3 (Line 1677).

It always resulted in E_FAIL when calling SetFormat (Line 1685).

The reason is that my Microsoft LifeCam Studio (only?) uses YUY2 which is 2 bytes per pixel (instead of 3). So the lSampleSize must be calculated by attemptWidth_attemptHeight_2 in this case - then it works.

A solution might be an additional array with bytes-per-pixel information for each mediatype.

Regards
Stefan

(Environment: Windows 8 / Visual Studio 2012 / x64)

@ofTheo
Copy link
Owner

ofTheo commented Nov 9, 2012

that could be because we only do RGB output.
we're you trying to get YUV2 output?

VI can handle a range of YUV inputs but it converts them to RGB before the pixels get sent back to the user.
( hence why w_h_3 was hardcoded )

@bambusch
Copy link
Author

bambusch commented Nov 9, 2012

I've just realized, that the code in the opencv source differs in some parts from your original.
(The opencv code allows to setup the device with a fourcc-code.)
Perhaps the described problem only resides in the opencv version.

However, since the method setSizeAndSubtype looks the same in both versions, I will describe my observation:

The method setSizeAndSubtype first retrieves the current format (tmpType). This always resulted in S_OK. But later, when setting the format (VD->pAmMediaType) inside the same method it always resulted in E_FAIL - also when trying all mediaSubtypes in the for-loop (1813 to 1823 in your code).

So I compared the content of the retrieved tmpType and the newly created VD->pAmMediaType and found out, that the lSampleSize of the tmpType only was w_h_2. I changed the calculation of the lSampleSize of VD->pAmMediaType to w_h_2 and it works for me.

This led to my assumption, that the camera itself allows only a two-byte-per-pixel format (YUY2).

(The output image was and is still converted to RGB.)

@ofTheo
Copy link
Owner

ofTheo commented Aug 14, 2014

Also got another report of this in #12 - Not sure if you have a patch that figures out the Bytes Per Pixels based on media types.

If you do please send a pull request - otherwise I'll put this on my todo list.

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

No branches or pull requests

2 participants