Web Camera in Windows 8.1

Just starting out? Need help? Post your questions and find answers here.
akee
Enthusiast
Enthusiast
Posts: 504
Joined: Wed Aug 18, 2004 9:52 am
Location: Penang, Malaysia

Web Camera in Windows 8.1

Post 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.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Web Camera in Windows 8.1

Post by IdeasVacuum »

You mean via PB?
This is excellent: PureBasic Interface to OpenCV
Also: USB video camera help
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
kvitaliy
Enthusiast
Enthusiast
Posts: 162
Joined: Mon May 10, 2010 4:02 pm

Re: Web Camera in Windows 8.1

Post by kvitaliy »

akee wrote:How do you enable your web cam in Windows 8.1? .
http://www.purebasic.fr/english/viewtop ... 13&t=43670
akee
Enthusiast
Enthusiast
Posts: 504
Joined: Wed Aug 18, 2004 9:52 am
Location: Penang, Malaysia

Re: Web Camera in Windows 8.1

Post 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.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Web Camera in Windows 8.1

Post 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?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
akee
Enthusiast
Enthusiast
Posts: 504
Joined: Wed Aug 18, 2004 9:52 am
Location: Penang, Malaysia

Re: Web Camera in Windows 8.1

Post 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
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Web Camera in Windows 8.1

Post 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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
akee
Enthusiast
Enthusiast
Posts: 504
Joined: Wed Aug 18, 2004 9:52 am
Location: Penang, Malaysia

Re: Web Camera in Windows 8.1

Post 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... :(
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Web Camera in Windows 8.1

Post 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
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Web Camera in Windows 8.1

Post 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")
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
akee
Enthusiast
Enthusiast
Posts: 504
Joined: Wed Aug 18, 2004 9:52 am
Location: Penang, Malaysia

Re: Web Camera in Windows 8.1

Post 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.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Web Camera in Windows 8.1

Post 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. :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
akee
Enthusiast
Enthusiast
Posts: 504
Joined: Wed Aug 18, 2004 9:52 am
Location: Penang, Malaysia

Re: Web Camera in Windows 8.1

Post by akee »

PB,
It always fails here...

connect=SendMessage_(hwnd,#WM_CAP_DRIVER_CONNECT,0,0)
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Web Camera in Windows 8.1

Post 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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
akee
Enthusiast
Enthusiast
Posts: 504
Joined: Wed Aug 18, 2004 9:52 am
Location: Penang, Malaysia

Re: Web Camera in Windows 8.1

Post by akee »

I wonder how OpenCV does it? The camera is ok if I run their examples but we cannot read the .lib file... :(
Post Reply