AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

GetCurrentVideoFrame output resolution too low

Forum to discuss AForge.NET Framework, its features, API, how-tos, etc.

GetCurrentVideoFrame output resolution too low

Postby johanneshfuerth » Fri Oct 13, 2017 4:12 am

Hi,

i'm currently working on a small application that will do basically the same as the Snapshot Maker sample application provided by AForge but it will be integrated into a larger application at a later point.
I'm using vb.net in Visual Basic Express 2010 and (as is probably obvious from that) I'm not an actual programmer, but I'm very good at googling stuff and I know my way around computers a bit...and it does seem to work
out surprisingly well so far, but now I have really hit a bit of a roadblock and need help from others with more knowledge and experience than me:

The camera I use is a Logitech C920 USB webcam which natively has FullHD 1080p resolution and the VideoSourcePlayer will output a crystal clear image in what looks very much to be FullHD resolution (that is if I run it in full screen of course). But when I try to get the current video frame, the saved file is always 640x480px.

Here's what I think the relevant piece of code is:

VideoSourcePlayer.GetCurrentVideoFrame.Save(System.Windows.Forms.Application.StartupPath & "\" & strFilename, System.Drawing.Imaging.ImageFormat.Jpeg)
label.Text = "Image Saved : " & strFilename

I guess the rest of the code is probably irrelevant since it's for the most part pretty standard and what everyone else is using and has been posted a million times elsewhere. But I can provide all the code if that is needed for some reason...
I have tried using the old desired frame size method which is no longer working of course and I have tried using videocapabilities unsuccessfully for unknown reasons (I adapted pieces of code from several other people that got it working but my combo box stays empty). But I would expect that to likely not be the reason.

From what I could find out, the Logitech C920 apparently doesn't support frame grabbing and the Snapshot Maker sample application will also show "not supported" under snapshot resolution. Taking stills, of course, works with the Logitech software, but the preview window there is so small it's practically unuseable and can't be rescaled, hence all my efforts trying to get AForge to do the same thing only with a larger preview...

Now my thoughts were that if AForge is able to pull proper resolution video from this webcam in livestream it theoretically shouldn't be a problem for AForge to grab a frame off that HD livestream and just save it in that resolution. But it seems like the webcam's driver somehow knows that AForge is grabbing a frame and maliciousy sabotages those efforts. Why it should do that is another mystery but there MUST be some way to get around that either by preventing the driver from noticing the framegrab or by cloning the HD livestream to a sandbox type of environment where it can get grabbed uninterrupted or simply by using some other method I haven't heard of yet.
But the most likely scenario is probably still that I'm just doing something wrong and a few lines of properly written code will fix the issue...

Is anybody able and willing to help me solve the issue? Any help would be greatly appreciated!
johanneshfuerth
 
Posts: 2
Joined: Fri Oct 13, 2017 3:34 am

Re: GetCurrentVideoFrame output resolution too low

Postby andrew.kirillov » Fri Oct 13, 2017 7:03 am

Hello,

Personally I would take the frame to save from NewFrame event handler, but GetCurrentVideoFrame() will work as all. Just a matter of preference.

johanneshfuerth wrote:I adapted pieces of code from several other people that got it working but my combo box stays empty

This is the main issue you need to address. Check the Snapshot Maker sample you are trying to mimic. If it does allow you to set video resolution, then it is clearly problem in your code. Go through the code of that application, see how it done. There is no magic in using the new video capabilities stuff.

johanneshfuerth wrote:From what I could find out, the Logitech C920 apparently doesn't support frame grabbing and the Snapshot Maker sample application will also show "not supported" under snapshot resolution.

It might not be true. Some cameras have a hardware trigger to make a snapshot - a button on a camera. However other cameras may have software trigger - a signal to make snapshot is sent from software. There was a fix recently in AForge.NET code. Before only hardware trigger was allowed, but now both types are supported. However there was no release since then. So you may need to get source code from GitHub and build it.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3230
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: GetCurrentVideoFrame output resolution too low

Postby johanneshfuerth » Sun Oct 15, 2017 8:34 pm

Thank you very much, Andrew. Your answer put me in the right direction...

I took a look at the Snapshot Maker source code, but sadly it still uses desired frame size and so does the Fabrika LAB source code which is where I took most of my code from.
So I tried a ton of things, found some unrelated mistakes I made, but the final missing piece was how to get the videoresolution argument right, which I just couldn't wrap my head around for hours (since I'm not a programmer and the documentation is of course written to be read by someone who at least knows the basics), but I FINALLY found a little piece of sample code in VBforums which I somehow managed to adapt to my project:

videoDevice.VideoResolution = videoDevice.VideoCapabilities(ComboBoxModes.SelectedIndex)

Now everything is working just as it was supposed to in the first place and from the looks of things the mistake was simply that I didn't manage to tell AForge which resolution to use, so it just took default settings for everything (and of course it did, that's what it's supposed to do) and those so happen to be 1920x1080 for livestream and 640x480 for still captures. Apparently.

So for everybody reading this who is as much an amateur as me and has a similar issue (I've seen on google that there are some): get the videoresolution working and it should be fine...there's no issue with the c920, no issue with DirectShow and no issue with AForge working with the c920 and DirectShow...don't be paranoid, the error is most likely sitting at the keyboard ;-)
johanneshfuerth
 
Posts: 2
Joined: Fri Oct 13, 2017 3:34 am




Return to AForge.NET Framework