Reputation:
I'm making my own webcam timelapsing application, but having issues with some webcams. The one in particular advertises that it can take 5MP photos, but it runs a native 320x240 (or something horrible) which is the feed that I'm getting.
I'm using code that seems to be well copy-and-pasted across the web, the incarnation I'm using for access to the webcam is here http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=1339&lngWId=10 and uses avicap32 to access the webcam, the call looking like this
mCapHwnd = capCreateCaptureWindowA("WebCap", 0, 0, 0, m_Width, m_Height, this.Handle.ToInt32(), 0);
SendMessage(mCapHwnd, WM_CAP_CONNECT, 0, 0);
SendMessage(mCapHwnd, WM_CAP_SET_PREVIEW, 0, 0);
I've tested with two other webcams (one in built into my laptop, one oldie I had kicking around) and both of those seem to get respectable resolutions.
I've modified the Webcam_Capture code to attempt to take a ridiculously high-res image
//private int m_Width = 320;
//private int m_Height = 240;
private int m_Width = 1600;
private int m_Height = 1200;
//private int m_Width = 3200;
//private int m_Height = 2400;
using a few different resolutions, as seen above.
My gut tells me that I need to do something to make the webcam use a different resolution, since it seems to be defaulting to some native value.
Thoughts?
I'd be happy to post more code that I'm using, but this seems to be the meat of it. WM_SET_PREVIEW may need some explaining, it's an API constant.
public const int WM_CAP_CONNECT = 1034;
public const int WM_CAP_DISCONNECT = 1035;
public const int WM_CAP_GET_FRAME = 1084;
public const int WM_CAP_COPY = 1054;
public const int WM_CAP_START = WM_USER;
public const int WM_CAP_DLG_VIDEOFORMAT = WM_CAP_START + 41;
public const int WM_CAP_DLG_VIDEOSOURCE = WM_CAP_START + 42;
public const int WM_CAP_DLG_VIDEODISPLAY = WM_CAP_START + 43;
public const int WM_CAP_GET_VIDEOFORMAT = WM_CAP_START + 44;
public const int WM_CAP_SET_VIDEOFORMAT = WM_CAP_START + 45;
public const int WM_CAP_DLG_VIDEOCOMPRESSION = WM_CAP_START + 46;
public const int WM_CAP_SET_PREVIEW = WM_CAP_START + 50;
Any ideas are welcome! robg
Upvotes: 0
Views: 3909
Reputation: 69687
There has been no code shown to set up the camera. So a default low resolution might be applied. Ideas:
To not use Video for Windows - the API is obsolete, limited and not flexible programmatically. Anyway, WM_CAP_SET_VIDEOFORMAT
message would set the webcam and change resolution. Consider using DirectShow or Media Foundation instead.
Windows SDK provides you with GraphEdit tool where you can build capture pipeline interactively and in particular inspect available resolutions.
Check camera spec: 5 MP stills does not mean this resolution is available for streaming video. Video res might be 1/4 of that, however it should certainly be better then 320x240.
Upvotes: 0