问题描述
我最近一直在使用vfw(Windows视频),并成功地成功更改了笔记本电脑网络摄像头的捕获分辨率.
该相机的工作为1.3百万像素,最大分辨率为1280 x1024.
每当我使用系统对话框选择摄像机时,列表中仅显示2种分辨率-320x240& 640x480.这些都不是1.3Mpixels,所以我决定手动设置这些值.
我在此处 [ [ ^ ]并发现确实如此,相机报告的最大分辨率为1280x1024.
我有一对用于选择低分辨率或高分辨率捕获模式的功能.这些都可以完美地工作.我修改了值,将其设置为1280x1024.
这导致黑色的预览屏幕.此后,即使我从未明确要求,每次启动该应用程序时,系统都会显示"DeviceSelection"对话框. (在发送狡猾的视频设置之前,只有在要求时才会显示)
此外,无论我尝试选择一个唯一的相机还是坚决拒绝使用它的相机-仍然没有预览图像,单帧捕获到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));
}
推荐答案
这篇关于如何正确初始化网络摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!