I've been playing with vfw (video for windows) lately and have managed to successfully change the capture resolution of my laptop's web-cam.
The camera is a 1.3 megapixel job, supporting a max resolution of 1280 x 1024.
Whenever I select the camera using the system dialog, there are only 2 resolutions shown in the list - 320x240 & 640x480. Neither of these are 1.3Mpixels, so I decided to manually set the values.
I rechecked the specs for the laptop
here[
^] and saw that yes indeed, the camera's reported max res is 1280x1024.
I have a pair of functions I use for selecting either the lo-res or the hi-res capture mode. These both work flawlessly. I modified the values such that it would set 1280x1024.
This resulted in a black preview screen. After this point, each time I started the app I was shown the DeviceSelection dialog, even though I never explicitly asked for it. (prior to the dodgy video settings being sent, it would only appear when requested)
Furthermore, no matter how many times I tried to select the one and only camera it resolutely refused to work - still no preview image, single-frame captures to a bmp file also black.
This is quite similar to behaviour I've seen in web-cam motion-detection software in the past. Somehow I disovered ages ago that the *cough* *splutter* FaceBook "Upload a picture from my web-cam" feature would correctly 'reset' my camera and allow it to function once more. Prior to this discovery of FBs one redeeming quality, I would have to reset the computer to get video functioning again.
- Previous apps would report that there were no available capture devices
- My app would report the installed device, though selecting it had no apparent effect.
In each scenario, the flash-based camera capture thing at the aforementioned 'site' would re-initialize the camera correctly.
I realize that it's quite possible that the 1280x1024 mode is not YUY2, which would mean that my calculation of biSizeImage would likely be incorrect. But even setting either of the other two modes to BI_RGB didn't 'kill' the camera like setUltraRes does.
My question is - is there something obvious (or not) that I'm overlooking?
I'd have preferred to keep this post shorter, but don't know enough to know what (if any) of this information is irrelevant and unimportant. I really appreciate any & all insights/assistance. :)
Dialog Init Code:
case WM_INITDIALOG:
camHwnd = createPreviewWindow(IDC_STATIC_CONTAINER, hwndDlg);
capDriverConnect(camHwnd, 0);
setLoRes();
capPreviewScale(camHwnd, true);
capPreviewRate(camHwnd, 66);
capPreview(camHwnd, true);
capGetVideoFormat(camHwnd, &bmInfo, sizeof(bmInfo));
capWidth = bmInfo.bmiHeader.biWidth;
capHeight = abs(bmInfo.bmiHeader.biHeight);
return TRUE;
createPreviewWindowCode:
HWND createPreviewWindow(int controlIdToReplace, HWND hwndDlg)
{
RECT wndRect, ctlRect;
RECT tRect;
HWND tgt;
POINT tl, br;
int width, height, posX, posY;
tgt = GetDlgItem(hwndDlg, controlIdToReplace);
bool wasOk = GetWindowRect(tgt, &wndRect);
tl.x = wndRect.left;
tl.y = wndRect.top;
br.x = wndRect.right;
br.y = wndRect.bottom;
ScreenToClient(hwndDlg, &tl);
ScreenToClient(hwndDlg, &br);
width = br.x - tl.x;
height = br.y - tl.y;
DestroyWindow(tgt);
tgt = capCreateCaptureWindow ("camera preview", WS_CHILD|WS_BORDER|SS_SUNKEN, tl.x, tl.y, width, height, hwndDlg, controlIdToReplace); return tgt;
}
Resolution setting code:
void setLoRes()
{
capGetVideoFormat(camHwnd, &bmInfo, sizeof(bmInfo));
bmInfo.bmiHeader.biWidth = 320;
bmInfo.bmiHeader.biHeight = 240;
bmInfo.bmiHeader.biCompression = 0x32595559; bmInfo.bmiHeader.biSizeImage = 320 * 240 * 2;
capSetVideoFormat(camHwnd, &bmInfo, sizeof(bmInfo));
}
void setHiRes()
{
capGetVideoFormat(camHwnd, &bmInfo, sizeof(bmInfo));
bmInfo.bmiHeader.biWidth = 640;
bmInfo.bmiHeader.biHeight = 480;
bmInfo.bmiHeader.biCompression = 0x32595559; bmInfo.bmiHeader.biSizeImage = 640 * 480 * 2;
capSetVideoFormat(camHwnd, &bmInfo, sizeof(bmInfo));
}
void setUltraRes()
{
capGetVideoFormat(camHwnd, &bmInfo, sizeof(bmInfo));
bmInfo.bmiHeader.biWidth = 1280;
bmInfo.bmiHeader.biHeight = 1024;
bmInfo.bmiHeader.biCompression = 0x32595559; bmInfo.bmiHeader.biSizeImage = 1280 * 1024 * 2;
capSetVideoFormat(camHwnd, &bmInfo, sizeof(bmInfo));
}