Forums
Reading webcam resolution - Printable Version

+- Forums (http://mitov.com/forum)
+-- Forum: VCL Components (/forum-6.html)
+--- Forum: VideoLab (/forum-19.html)
+--- Thread: Reading webcam resolution (/thread-3057.html)



Reading webcam resolution - BReeves - 05-03-2014 09:14 PM

Does Video lab have a fairly easy way to query a USB WebCam to see what resolutions the camera is capable of?

I am playing with two Logitech web cams and going back and forth between the Logitech software and a version of the AdvancedVideoCapture demo just to see what resolutions I can actually set that will work. Not every resolution that can be set in the Logitech software will work when set in VLDSCapture->VideoSize. Some just revert the camera back to 640X680.

What I have discovered that seems to always work is whatever the cameras max resolution is and of course 640X480. One camera will do 1920X1080 the other will do 1440X1080. I would like to be able to get these values from the camera and not have to ask the user to figure out what they are and enter them in setup.

I need to know because the video output needs to always be 4:3 aspect and I will have to crop the sides of the wide screen cameras. Would be really nice If the software could read the cameras Direct Show aspect and resolution.

Hope I have given you enough info to be able to point me in the right direction.


RE: Reading webcam resolution - Dave - 05-04-2014 01:06 AM

What i usually do to read actual values from a capture-source is connect a VLGenericFilter to the source, declare some global variables like Width, Height and in the GenericFilters OnProcessData event
read in these values using Width=InBuffer.GetWidth() and Height=Inbuffer.GetHeight(). Then use a Timer to show these values on a label for example.

Regards,
Dave


RE: Reading webcam resolution - BReeves - 05-06-2014 08:40 PM

Thanks Dave,

I'll play with it. Looks like I may need to provide a small utility to help the user determine what resolution values can be used for whatever webcam he has connected. I'll just create a stripped down version of the AdvancedVideoCapture demo.

Also decided to just place a button on the configuration screen that brings up the manufactures Camera Control utility. I wasn't getting consistent results between different cameras trying to use VLDSCapture CameraControl properties. I am thinking Logitech does some magic between the Camera and the Direct Show interface to be able to do everything the Logitech software does.


RE: Reading webcam resolution - BReeves - 05-12-2014 09:02 PM

A little update... Before I posted this question I had sent Boian an Emil asking almost the same question. He pointed me to VLDSCapture1->VideoModes which I was able to figure out and worked great.

Below is the code I ended up with, it populates a TComboBox I named ResolPickBox and stores the actual height and width numbers in a struct. I was only interested in 640x480 and above with an aspect of 1.33.

The aspect was converted to a string to provide consistent truncation of the decimal places for a comparison to what I was looking for.

One thing I didn't (and still don't) understand is without the line that looks for a duplicate entry I get two sets of identical resolution numbers. I looked at the other data fields returned in TVLVideoModeFormat and couldn't find anything that was different between the duplicate listings. For example, Format returned vfRGB24 in all cases.

Code:
void TCamera::GetCamResolutions(void)
{
float w, h, a;
int index, i;
String str;
char resol[41];
typedef struct WcResStruct {
        int WcHeight;
        int WcWidth;
        }WcResol;

    WcResol WcRes[10];
    index = 0;
    for(i = 0; i < VLDSCapture1->VideoModes->Count; i++) {
        h = VLDSCapture1->VideoModes->Items[i]->Height;
        w = VLDSCapture1->VideoModes->Items[i]->Width;
        a = w / h; // Get aspect
        str = str.FloatToStrF(a, AnsiString::sffFixed, 4, 2);
        if(str == "1.33"){ // Have aspect we are looking for
            if(w >= 640){  // Not interested in anything below 640x480
                if(index > 0 && WcRes[index - 1].WcHeight > VLDSCapture1->VideoModes->Items[i]->Height)
                    break;  // Only get first set of numbers
                WcRes[index].WcHeight = VLDSCapture1->VideoModes->Items[i]->Height;
                WcRes[index].WcWidth = VLDSCapture1->VideoModes->Items[i]->Width;
                sprintf(resol, "%d X %d", WcRes[index].WcWidth, WcRes[index].WcHeight);
                ResolPickBox->Items->Add(resol);
                index++;
            }
        }
    }