Results 1 to 7 of 7

Thread: Webcam / Video Capture - Dialogless Camera Select?

  1. #1

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065

    Webcam / Video Capture - Dialogless Camera Select?

    hi guys...

    im using the AVICap code to open up a view of a webcam - then setting the parent "window" of the image to on my form - so it appears my application owns the image etc...

    Microsoft WDM Image Capture (Win32) < the "Driver" being used to capture the image...

    Starting video like this....
    vBCode Code:
    1. Dim lpszName As String * 100
    2.     Dim lpszVer As String * 100
    3.     Dim Caps As CAPDRIVERCAPS
    4.  
    5.     '//Create Capture Window
    6.     capGetDriverDescriptionA 0, lpszName, 100, lpszVer, 100  '// Retrieves driver info
    7.    
    8.     lwndC = capCreateCaptureWindowA(lpszName, WS_CHILD Or WS_VISIBLE, 0, 0, 160, 120, lgOwner, 0)
    9.  
    10.     '// Connect the capture window to the driver
    11.     capDriverConnect lwndC, 0
    12.    
    13.     '// Get the capabilities of the capture driver
    14.     capDriverGetCaps lwndC, VarPtr(Caps), Len(Caps)
    15.    
    16.     '// Set the video stream callback function
    17.     capSetCallbackOnVideoStream lwndC, AddressOf MyVideoStreamCallback
    18.     capSetCallbackOnFrame lwndC, AddressOf MyFrameCallback
    19.    
    20.     '// Set the preview rate in milliseconds
    21.     capPreviewRate lwndC, 66
    22.    
    23.     '// Start previewing the image from the camera
    24.     capPreview lwndC, True
    25.        
    26.     '// Resize the capture window to show the whole image
    27.     ResizeCaptureWindow lwndC
    28.    
    29.     ' say we are viewing the video
    30.     bViewVideo = True


    and disabling the video like this:

    vbcode Code:
    1. '// Disable all callbacks
    2.     capSetCallbackOnStatus lwndC, vbNull
    3.     capSetCallbackOnYield lwndC, vbNull
    4.     capSetCallbackOnFrame lwndC, vbNull
    5.     capSetCallbackOnVideoStream lwndC, vbNull
    6.     capSetCallbackOnWaveStream lwndC, vbNull
    7.     capSetCallbackOnCapControl lwndC, vbNull
    8.     capSetCallbackOnError lwndC, vbNull
    9.    
    10.     DoEvents
    11.    
    12.     bViewVideo = False


    all working great... EXCEPT:

    am i correct in thinking i also need to DESTROY the window that was created using this code...
    vbcode Code:
    1. lwndC = capCreateCaptureWindowA(lpszName, WS_CHILD Or WS_VISIBLE, 0, 0, 160, 120, lgOwner, 0)

    just got wondering this, since the last visible image from the camera remains on my form, even though the window should of closed? (not a problem, since i hide this control anyway, but would be nice to keep the resources free)


    and secondly.. i have two cameras that i can select... - i dont suppose there is a dialogless way to select either camera is there

    i have searched the forums and have come to the conclusing the dialog is required, but would be nice just for confirmation of this. Cheers.
    Wayne

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Webcam / Video Capture - Dialogless Camera Select?

    and secondly.. i have two cameras that i can select... - i dont suppose there is a dialogless way to select either camera is there

    i have searched the forums and have come to the conclusing the dialog is required, but would be nice just for confirmation of this. Cheers.
    i spent a time looking and did not find a way
    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

  3. #3

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065

    Re: Webcam / Video Capture - Dialogless Camera Select?

    thats what most of the posts ive found suggest - there being no way to do it. but surely there must be some way?

    - maybe hide the visible dialog and choose the option via code maybe?

    do you have an answer about destroying the window created? - if view the cam a second time it asks me to select the source [ displaying the dialog ] ... this also leads me to feel that the first video is still open? - would a "Close Window" message suffice for terminating the camera processes?
    Wayne

  4. #4
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Webcam / Video Capture - Dialogless Camera Select?

    You could do it programatically by using FindWindow/FindWindowEx, and even enumerate items in the dropdown list (probably using SendMessage API) and simulate a key press on the Ok button.

    I've never had to do this before so I'm not exactly sure how.

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Webcam / Video Capture - Dialogless Camera Select?

    do you have an answer about destroying the window created? - if view the cam a second time it asks me to select the source [ displaying the dialog ] ... this also leads me to feel that the first video is still open? - would a "Close Window" message suffice for terminating the camera processes?
    i was just using
    SendMessage hCapWin, WM_CAP_DRIVER_DISCONNECT, 0, 0
    to stop the webcam

    have you looked if there is any registry setting for current webcam?
    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

  6. #6
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Webcam / Video Capture - Dialogless Camera Select?

    I think selecting the webcam source via code is possible, I have seen some threads about it when I googled it a few weeks back. It involves reading the registry for the code of the webcam, the samples I have seen are for .Net but the codes are applicable to VB6.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  7. #7

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065

    Re: Webcam / Video Capture - Dialogless Camera Select?

    - well this is strange, i posted a reply yesterday that hasnt shown up :S.

    well just to let you know...

    i use the
    DestroyWindow lhwndC
    code to destroy the window
    and on reading westconn's reply, also added the disconnect driver command prior to this. :P got rid of the last image from my form, AND no long shows the dialog on the second run of the code on the same app instatance..

    ill try google for some code for reading from registry.


    - although, i will use a settings form initially to "Select Camera 1" > get input from dialog > save input
    then camera1_click > get setting > [im guessing i then need to send this to the CAPTURE Driver, and not my Preview window?]

    ill have a look for some code for this... im guessing i have all the api i need for it already in my code... but its not a major thing YET as the main camera i need to use is the rear camera i can just set this up as default, and only need to change for a front view.
    Wayne

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