Page 1 of 2

Web Camera in Windows 8.1

Posted: Tue Nov 25, 2014 1:13 pm
by akee
How do you enable your web cam in Windows 8.1? The usual way produces a black screen and disallows us to connect to the avicap32.dll driver? Some places say you need a manifest. Thanks.

Re: Web Camera in Windows 8.1

Posted: Tue Nov 25, 2014 4:27 pm
by IdeasVacuum
You mean via PB?
This is excellent: PureBasic Interface to OpenCV
Also: USB video camera help

Re: Web Camera in Windows 8.1

Posted: Tue Nov 25, 2014 5:53 pm
by kvitaliy
akee wrote:How do you enable your web cam in Windows 8.1? .
http://www.purebasic.fr/english/viewtop ... 13&t=43670

Re: Web Camera in Windows 8.1

Posted: Wed Nov 26, 2014 4:20 pm
by akee
Ok, I checked OpenCV. Thanks for the response guys...

OpenCV is a bit of an overkill for my project. All I need is to invoke the dialog (like in Camera) to allow access to avicap32.dll capDriverConnect() and the WebCam... and I'm done. How do you do that?

Currently, I need to open an existing program like Camera, then only run my program.

Re: Web Camera in Windows 8.1

Posted: Wed Nov 26, 2014 4:34 pm
by IdeasVacuum
Need more info from you :)
1) What exactly is "Camera"? Is it a Windows8.1 utility app? Or is it an app that is delivered with your specific web cam?
2) What is your exact OS?
3) What is your exact Web Cam device?
4) Your program - what does it do? Connect to the Web Cam?

Re: Web Camera in Windows 8.1

Posted: Wed Nov 26, 2014 7:01 pm
by akee
Hi IdeasVacuum,
a. Camera is the camera on your laptop.
b. Win 8.1 pro 64-bit.
c. The source dialog says Integrated Webcam.
d. 1. OpenLibrary(0, "avicap32.dll")
2. webcam_preview = capCreateCaptureWindow("webcam", #WS_CHILD | #WS_VISIBLE, 10, 50, 320, 240, WindowID(win_camera_handle), 0)
3. capDriverConnect(webcam_preview) <--- It fails here @ SendMessage_(lwnd, #WM_CAP_DRIVER_CONNECT, 0, 0)

... for it to pass #3, you must open up an app like Camera then only run my .exe. You then close the Camera app to pass camera control to my program...

Thanks... :D

Re: Web Camera in Windows 8.1

Posted: Wed Nov 26, 2014 10:13 pm
by IdeasVacuum
Aha, with you now. I think the Camera software is registered as the 'first choice'. In Win8.1, go to Control Panel/Default Programs/Set Default Programs.

Re: Web Camera in Windows 8.1

Posted: Thu Nov 27, 2014 4:30 am
by akee
IdeasVacuum wrote:Aha, with you now. I think the Camera software is registered as the 'first choice'. In Win8.1, go to Control Panel/Default Programs/Set Default Programs.
Hmmm.... on my PC, Camera or my program is not even listed... :(

Re: Web Camera in Windows 8.1

Posted: Thu Nov 27, 2014 8:39 am
by IdeasVacuum
Hmm, tricky! For your program to be listed, it probably needs to be installed, with a registry entry, but in theory you should be able to browse to your exe file and select it.

It seems there are known issues with the MS Camera App which occur when Win8 is upgraded to Win8.1.
Web Cam only shows black screen

Basically, first job is to ensure that you have the latest web cam driver installed from the manufacturer of your laptop/PC/Web Cam.

I can see one snag is that MS Camera is a Metro (Modern) App, whilst yours is a Desktop App.

This article might be the answer: Win 8.1 How to Set Which Apps May Use the Webcam

Re: Web Camera in Windows 8.1

Posted: Thu Nov 27, 2014 9:33 am
by PB
> How do you enable your web cam in Windows 8.1?

I've been using this forever (mod of someone else's code).

Test it with 8.1 and see if it works, and please report back.

Code: Select all

UseJPEGImageEncoder()

Procedure SaveWebcamSnapshot(file$,w=640,h=480)
  lib=OpenLibrary(#PB_Any,"avicap32.dll")
  If lib
    camwin=OpenWindow(#PB_Any,0,0,0,0,"",#PB_Window_Invisible)
    If camwin
      hwnd=CallFunctionFast(GetFunction(lib,"capCreateCaptureWindowA"),@"",#WS_CHILD|#WS_VISIBLE,0,0,w,h,WindowID(camwin),0)
      If hwnd
        c$=GetClipboardText() ; Because contents get destroyed by #WM_CAP_EDIT_COPY.
        connect=SendMessage_(hwnd,#WM_CAP_DRIVER_CONNECT,0,0) : Sleep_(125)
        copy=SendMessage_(hwnd,#WM_CAP_EDIT_COPY,0,0) : Sleep_(125)
        If connect And copy
          img=GetClipboardImage(#PB_Any)
          If img
            ResizeImage(img,w,h) : ok=SaveImage(img,file$,#PB_ImagePlugin_JPEG) : FreeImage(img)
          EndIf
          SendMessage_(hwnd,#WM_CAP_DRIVER_DISCONNECT,0,0) : DestroyWindow_(hwnd)
        EndIf
        SetClipboardText(c$) ; Restore previous clipboard text.
      EndIf
      CloseWindow(camwin)
    EndIf
    CloseLibrary(lib)
  EndIf
  ProcedureReturn ok
EndProcedure

Debug SaveWebcamSnapshot("c:\webcam.jpg")

Re: Web Camera in Windows 8.1

Posted: Sat Nov 29, 2014 4:41 pm
by akee
IdeasVacuum & PB... Both methods did not work... :( Let me try if there is another driver I can use instead of the default Microsoft one.

Re: Web Camera in Windows 8.1

Posted: Sun Nov 30, 2014 12:02 am
by PB
> Both methods did not work

So, which part of my code failed?

Did the webcam turn on it?
Was an image created?
Did it not save?

Give us a clue. :)

Re: Web Camera in Windows 8.1

Posted: Sun Nov 30, 2014 4:39 pm
by akee
PB,
It always fails here...

connect=SendMessage_(hwnd,#WM_CAP_DRIVER_CONNECT,0,0)

Re: Web Camera in Windows 8.1

Posted: Sun Nov 30, 2014 7:15 pm
by IdeasVacuum
Actually PB, it fails on my WinXP PC - the image captured is just black, and fails on my Win8.1 laptop - no image file saved. Both cases run from PB IDE, no errors reported.

Re: Web Camera in Windows 8.1

Posted: Sat Dec 13, 2014 11:31 am
by akee
I wonder how OpenCV does it? The camera is ok if I run their examples but we cannot read the .lib file... :(