?
Solved

Capturing a Webcam Image using VB.Net

Posted on 2011-02-21
7
Medium Priority
?
6,380 Views
Last Modified: 2013-11-08
I have VB.Net application that captures an image from a webcam. I have used the following code for a number years without an issue:

       hWnd = capCreateCaptureWindowA("USB Camera",  WS_VISIBLE Or WS_CHILD, 0, 0, 0, _
            0, pbCtrl.Handle.ToInt32, 0)
       If SendMessage(hWnd, WM_CAP_DRIVER_CONNECT, CamSource, 0) Then
           SendMessage(hWnd, WM_CAP_SET_SCALE, True, 0)
            Blar Blar Blar................
       Else
            '--error connecting to video source---
       End If

However moving to Windows 7 .Net 3.5 when 'SendMessage' is issued to open the 'CamSource' the dialogue 'Capture Source' -  'Select a Video Device' - 'USB Camera' appears. What I ever do in response to this dialogue the webcam doesn't open.

I have resolved this issue in the past by upgrading the Bison drivers to the latest version (from the version that came with Win 7 32 bit). I installed Win 7 32 bit on the PC and the Bison drivers where installed by default.

The problem I now have is on a tablet - running Win 7 32 bit. The built in webcam uses the 'USBVideo.sys' driver.

I have tried to use the Bison drivers - but can't change the driver from 'USBVideo.sys' (I am not too sure that would solve the problem - I just know the Bison drivers work fine) i.e. I uninstall, disable, kill the webcam - but as soon as it is available to Win 7 - then USBVideo.sys drivers are installed.

I think the problem is that another process (I can't see what the process this could be) already has the webcam 'locked' i.e. it can't be shared.

So at this point in time I am stuffed! Thoughts and solutions much appreciated.

Regards

BeagleDog
0
Comment
Question by:BeagleDog
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 4

Expert Comment

by:dailypcguy
ID: 34946803
Have you tried a safe or selective boot to eliminate the USBVideo.sys driver from the equation?
0
 

Author Comment

by:BeagleDog
ID: 34947588
I re-booted in safe mode. Under device manager and looked at the properties of the webcam 'Status is not available for this devicewhen Windows is running in Safe Mode'

Ran the application - and while I didn't get the 'Select Video Source' dialog - neither did I get a preview from the webcam.

Was that what you where thinking in 'try a safe or selective boot'?

Thanks for your response.

BeagleDog
0
 
LVL 4

Expert Comment

by:dailypcguy
ID: 34948441
Yeah I just wondered if you could selectively load drivers for boot time. Safe boot doesn't work, but you could also try typing msconfig in the Start | Search box and see if the driver for the webcam is listed there under services or startup. You would then be doing a selective startup to see if you can access the webcam with your code in the absence of the driver. msconfig will ask you to resart when you make your changes and close it down (sorry if I'm assuming you haven't done this before)

It may well be the case that you cannot access the camera with out the 'middleware' driver being in place, but it would be nice to know one way or the other. At least then you could possibly add some code to end the drivers process allowing you the access you need - but that is more your area of skill than mine!
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 

Author Comment

by:BeagleDog
ID: 34948681
OK did this:
Only 8 services running:

DCOM Server.....
Group Policy Client
Plug and Play
Remote Proc Call
RPC EndPoint
Task Sched
User Profile
Software Protection

The application starts - but exactly the same symptoms
The PC comes with Camera software:

Video View - DirectShow Video Capture Sample Version 1.00
And this fires up and works perfectly...........

Yes - it feels like I need to have a another service running (as you say 'middleware') - it doesn't feel that it is a sharing conflict.

Again thanks for your help and your response.

Regards

BeagleDog


0
 
LVL 4

Expert Comment

by:dailypcguy
ID: 34948717
Okay I'm not a VB.net programmer but I managed to apply myself and do the following using this script downloadable from a smarter guy named Ken Tucker from here:
http://www.vb-helper.com/howto_net_video_capture.html
I then realised I'd need to install some vb.net tools so I used express edition 2008 (the free one),
and somehow (trial & error) I managed to get it working.

Ken's script does what it says it does - lists the existing camera feed /driver sources on the machine you are using it on, shows you the feed in a window (the aspect ratio was off a bit) and allows for taking a picture.

Maybe examining Ken's code will point you towards a solution that works, if it tuns out that on that specific tablet your code requires more specific tailoring, that is also likely the case on other devices too.

It seems to be of limited value to bother with a selective startup proces if the above idea works on that tablet! Good luck, keep me posted.
0
 

Accepted Solution

by:
BeagleDog earned 0 total points
ID: 34989301
I raised this issue the Microsoft - and got an excellent response. I have posted it here.............

Microsoft replied:


I’d like to inform you that, I’ve written a small C++ sample and used ‘capCreateCaptureWindow’ and ‘capDriverConnect’ APIs to access WebCamera on my Windows 7 system. I found both of these APIs are working fine on my Windows 7 System.

I’ve used ‘Microsoft LifeCam VX-6000. The issue could be with the Bison driver compatibility. I think it’s worth to give a try to re-install the driver in “Windows XP or Vista Compatible” mode on your Windows 7 system and then try with your existing code.

Please follow the steps as mentioned below:
1.      Uninstall the bison web cam driver from your system.
2.      Download the driver from the official website.
3.      Right click on the driver executable / installer file. A context menu will appear.
4.      Select ‘Properties’ menu item
5.      Click on the Compatibility tab.
6.      Check the option “Run this program in Compatibility mode for” and Select Windows XP (Service Pack 3).
7.      Then click on Apply and OK.
8.      Please right click again on the driver executable / installer file and Select the option “Run as Administrator”.
9.      Then follow instructions to install the driver on the system.
10.      Once installation is done, please restart the system and use your program to check if it’s working or not.
11.      Please ensure that you’re running the program in “Elevated mode”.

You can also test with Windows Vista compatibility mode using same steps.

Since, VFW is a very old technology, it’s good to consider moving to DirectShow. I’ll provide a separate email about DirectShow related stuff on 28th Feb 2011.

Please let me know how the thing goes after installing the driver in Compatibility mode.

I tried this. The following is my response:

Thanks for all this :

Tried the following but I didn’t succeed because:

1.      I hadn’t managed to install the Bison drive on this Table. The Webcam was using USBVideo.sys.
2.      I followed your instructions, but the drivers I had couldn’t install because the USBVideo.sys as already installed.
3.      The install for the Bison didn’t seem to have .inf file (I may have been doing something wrong also)

The other things I have tried.

1.      I found a C# DirectShow sample that did exactly what I wanted to do – show the video in preview, then snap the image into a second picture box window. Great!
2.      But I am an old VB programmer and our application is VB. I don’t seem to be able to get my head around C#. First attempted to convert the C# to VB but soon became lost.
3.      Decided to create a user control using the C# code – then include the control in the VB app. Good thinking! The only problem was returning the captured image from the control back to the VB app. However I decided to make sure the control could access the webcam correctly.
4.      When I tried this – yes it worked – I didn’t get the ‘Select A Video’ source message – but the video was very distorted. I suspect that this was a setting on the camera – a refresh rate or something……….
5.      Had a cup of coffee.

Rather than keep pursuing down this path (as I suspected it was going to take me nowhere – if I couldn’t retrieve the snap imaged). I decided to try a new video driver. Went to ‘DriversForFree’ and found a Bison driver for a generic USB webcam. This driver came with an .inf file. Was able to kick USBVideo.sys in the guts and install the Bison USB Webcam drivers.

Fired up my app – and it worked perfectly!!!!

It may not be the best solution – but at least gets me back up and running.

Comments – while DirectShow maybe the best solution – hell it complicated! Even with all this complication it still couldn’t deliver a picture from the WebCam (I accept it could be the driver or a setting).

If I go down the DirectShow path again – I will look for an OCX that saves me from the complications. I would look for an OCX that would do face recognition – software that would enhance the face – differentiate the face from the background (not to be able to recognise the face from a library of faces). If anyone knows of such an animal you like to know.

Again thanks for your support and interest in this problem – I really appreciate it.

If you want to feed me any more info re DirectShow – please do – otherwise please feel free to close this issue.

If there is anything else I can do to provide information on this problem please let me know.

Regards
0
 

Author Closing Comment

by:BeagleDog
ID: 35025215
Resolved the issue through Microsoft and posted here for completeness. i.e. when you have a problem its great to pickup threads of like problems so that you can find and implement the best solution.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question