如何正确初始化网络摄像头 [英] How to correctly initialize web-cam
问题描述
我最近一直在使用vfw(Windows视频),并成功地成功更改了笔记本电脑网络摄像头的捕获分辨率.
该相机的工作为1.3百万像素,最大分辨率为1280 x1024.
每当我使用系统对话框选择摄像机时,列表中仅显示2种分辨率-320x240& 640x480.这些都不是1.3Mpixels,所以我决定手动设置这些值.
我在此处 [ [
此外,无论我尝试选择一个唯一的相机还是坚决拒绝使用它的相机-仍然没有预览图像,单帧捕获到bmp文件时也会变黑.
这与我过去在网络摄像头运动检测软件中看到的行为非常相似.我以某种方式过去已经变老了,*咳嗽* splutter * FaceBook从网络摄像头上传图片"功能可以正确地重置"我的相机并使其再次运行.在发现FB的一种赎回质量之前,我必须重置计算机才能使视频再次运行.
- 以前的应用会报告没有可用的捕获设备
- 我的应用会报告已安装的设备,尽管选择没有明显效果.
- 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.
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.
我意识到1280x1024模式很有可能不是YUY2,这意味着我对biSizeImage的计算可能不正确.但是,即使将其他两种模式中的任何一种设置为BI_RGB都没有像setUltraRes那样杀死"摄像机.
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.
我本来希望使这篇文章简短一些,但对这些信息中无关紧要的(如果有的话)了解不足.我真的很感激任何&所有见解/帮助. :)
对话框初始化代码:
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:
/*
* TODO: Add code to initialize the dialog.
*/
// camHwnd = capCreateCaptureWindow ("camera preview", WS_THICKFRAME|WS_EX_TOOLWINDOW, 0, 40, 320, 240, hwndDlg, 0); //create capture window
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:
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); //create capture window
return tgt;
}
分辨率设置代码:
Resolution setting code:
// works okay
void setLoRes()
{
capGetVideoFormat(camHwnd, &bmInfo, sizeof(bmInfo));
bmInfo.bmiHeader.biWidth = 320;
bmInfo.bmiHeader.biHeight = 240;
bmInfo.bmiHeader.biCompression = 0x32595559; // YUY2 compression
bmInfo.bmiHeader.biSizeImage = 320 * 240 * 2;
capSetVideoFormat(camHwnd, &bmInfo, sizeof(bmInfo));
}
// works okay
void setHiRes()
{
capGetVideoFormat(camHwnd, &bmInfo, sizeof(bmInfo));
bmInfo.bmiHeader.biWidth = 640;
bmInfo.bmiHeader.biHeight = 480;
bmInfo.bmiHeader.biCompression = 0x32595559; // YUY2 compression
bmInfo.bmiHeader.biSizeImage = 640 * 480 * 2;
capSetVideoFormat(camHwnd, &bmInfo, sizeof(bmInfo));
}
// turns vid camera into a brick
void setUltraRes()
{
capGetVideoFormat(camHwnd, &bmInfo, sizeof(bmInfo));
bmInfo.bmiHeader.biWidth = 1280;
bmInfo.bmiHeader.biHeight = 1024;
bmInfo.bmiHeader.biCompression = 0x32595559; // YUY2 compression
bmInfo.bmiHeader.biSizeImage = 1280 * 1024 * 2;
capSetVideoFormat(camHwnd, &bmInfo, sizeof(bmInfo));
}
推荐答案
您要对以这种方式捕获的视频进行任何处理,还是只是想将摄像机重置为最大分辨率?
如果您确实想捕获YUY2格式的原始视频并对其进行处理"(例如运动检测或对象跟踪),那么我相信您可以获得的最大分辨率为720x576,但是自从我使用以来已经有很多年了VFW,所以如果我错了,请不要射击我.
您将收到原始的,未压缩的视频,其规格植根于NTSC/PAL模拟视频.我确实记得有关capDlgVideoCompression()宏的文章,但是我不知道这是否实际上为您提供了选择在系统上注册或由摄像机本身支持的任何编解码器的选项.
Soren Madsen
Are you going to do anything with the video you are capturing this way, or are you just looking for a way to reset the camera to its maximum resolution?
If you indeed want to capture the raw video in YUY2 format and "do something" with it (such as motion detection or object tracking), then I believe the maximum resolution you can get is 720x576, but it has been many years since I used VFW, so please don''t shoot me if I am wrong.
You are receiving the raw, uncompressed video and the specs for that are rooted in NTSC/PAL analog video. I do recall reading about the capDlgVideoCompression() macro, but I do not know if that actually gives you options to select any CODEC registered on your system or supported by the camera itself.
Soren Madsen
这篇关于如何正确初始化网络摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!