Results 1 to 10 of 10

Thread: Snapshot from webcam

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Snapshot from webcam

    i started this project in interest of a thread for taking ID photos

    the code, using AMCAP, has been put together from many sources including research in msdn, and several other forums and is not original by me, i had trouble to make my webcam work, or select which cam to use if more than 1 was attached, there maybe better solutions than the way i have done it, but it works for me on XP home, with a generic webcam and a kodak dual mode camera.

    i have used a timer to take a series (6) of snaps, which would allow the user, to select the best photo, to do whatever they wanted, as there seems to be no other code for webcams in the code bank i decided to post this project
    Attached Files Attached Files
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  2. #2
    Lively Member
    Join Date
    Nov 2007
    Location
    Rochester, NY
    Posts
    111

    Re: Snapshot from webcam

    Nice work. This also works for me (XP pro with Logitech cam)
    Please use the search function prior to posting a question and see if someone's already answered it.
    -If I helped you, please rate me, as I'd do the same for you =)
    -Remember to select the Resolved option for your post when you've gotten the answers you need.

  3. #3
    Lively Member
    Join Date
    Jan 2007
    Posts
    76

    Re: Snapshot from webcam

    but, when the windows is not on the top, it captures a part of the window on the top!!!

    that's my problem,

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Snapshot from webcam

    set that to topmost window then
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5
    Junior Member
    Join Date
    Sep 2009
    Posts
    21

    Re: Snapshot from webcam

    the program only taking 5 snapshort only right it didnot save the picture correct?
    what if i want to save the photo in desktop how should i write it?

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Snapshot from webcam

    try
    savepicture picture1(index).picture, path & "\campic.bmp"
    where index is the picture box you want to save and path is the folder to save in
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7
    Junior Member
    Join Date
    Sep 2009
    Posts
    21

    Re: Snapshot from webcam

    do you mean by savepicture picture1(0).picture, "desktop" & "\campic.bmp"

    it gives an error

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Snapshot from webcam

    desktop is not a vaild path
    you would need the full path, something like, C:\Documents and Settings\ericeoh\Desktop
    search in vb6 forum for code to return special folders
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9
    Lively Member
    Join Date
    Feb 2008
    Posts
    105

    Re: Snapshot from webcam

    when i try to close this it just locks up?

  10. #10
    New Member
    Join Date
    Dec 2011
    Posts
    2

    Re: Snapshot from webcam

    This thread is a little old, but I came across it trying to solve a problem using a built-in webcam (as opposed to external usb-connected), and now that my code finally works I thought I'd share it in case anyone out there is still looking....

    [Originally posted to the thread "Re: WM_CAP_DRIVER_CONNECT connects but black window?", but added here by request from pete]

    The problem I had was with code almost identical to that listed here, which worked fine with a USB-attached webcam, but not with a built-in device. I noticed that the SendMessage was always failing, but could find no versions of this code which actually investigate WHY it fails; all they ever do is just give up and destroy the capture window.

    After many attempts to find the actual error, I noticed that *occasionally*, maybe 1 time in 10, the code did actually work, for no good reason.

    I had to give up on finding the error, as the code got less and less stable the more error-handling code I put in. BUT, I finally put some retry code in, and the whole application burst into life and now works 100% reliably!

    What fixed it for me was to replace the single IF SendMessage line with the following:

    Code:
            Dim connectAttempts As Integer = 0
            While Not CBool(SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, 0, Nothing))
                connectAttempts += 1
                If connectAttempts > 10 Then
                    DestroyWindow(hHwnd)
                    Me.Cursor = Cursors.Default
                    Return False
                End If
                Threading.Thread.Sleep(1000)
            End While
    Hope this helps someone, as it cost me a couple of frustrating days getting this to work!

    Ade
    Last edited by lewisar; Dec 7th, 2011 at 09:31 AM. Reason: Missing code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width