Click here to Skip to main content
Click here to Skip to main content

Webcam Web Service

By , 23 Apr 2002
 

Contents

Introduction

Webcam is a Simple Object Access Protocol (SOAP) project that will permit client's software to get, from a Web Service, JPEG pictures captured by a Webcam. It is my first step experiment in the world of SOAP after several projects using COM/DCOM and ATL.

The project is split in three parts:

  • Server: Active Template Library Server capturing a picture from the Webcam.
  • Web Service: Generated with WSDL Generator from Microsoft®.
  • Client: ActiveX client connecting to Webcam SOAP Server getting pictures and displaying them.

Server

We use Visual C++ and the Active Template Library (ATL) object Wizard to create a Simple COM object, called Camera. It handles the grabbing of the picture and the JPEG compression.

The jpeg compression is achieved with Intel® JPEG Library v1.5. Get it here. You may use other libraries, like IJG JPEG LIBRARY, by using the abstract base class CPicturePacker.

Camera handling is done using Microsoft® Video for Windows® (VFW). Get more information on MSDN / Platform SDK Documentation / Graphics and Multimedia Services / Windows Multimedia / Video Capture.

Trick: VFW needs a handler on a window to attach the camera driver to. As we chose to create a Simple COM object we do not have access to any window handler. Calling GetDesktopWindow() got us one.

    // Don't have access to the container's window so just use the desktop.
    // RMK: If the desktop is not at least 24bits colors, then the grab will
    //      fail
    HWND hWnd = ::GetDesktopWindow();

    if ( hWnd )
    { ...
All functionalities needed to grab a picture on a Webcam are done in the class CWebCam. For example the method GrabFrame:
    bool CWebCam::GrabFrame( CPicturePacker * pPacker,
                             unsigned char  ** ppPackedPicture,
                             unsigned long  * pnPackedPictureBytes )
Use a reference to a CPicturePacker base class to pack the original picture's bits, permitting to extend the packing to whatever format you want, as mentioned before. In this sample I have written the class CIntelJpegPacker inheriting from CPicturePacker and using the Intel® JPEG Library v1.5 to pack the picture grabbed. You may consider using GDI+ for example to do the same.

The rest of the source is dealing with COM and is nothing special.

Server Interface

Our server needs to achieve two simple operations: grabbing a picture from a Webcam and compressing it as a JPEG picture according to a compression ratio defined by the caller. This is achieved in the GrabFrame method.

HRESULT GrabFrame( [in] short nQuality, 
                   [out, retval] SAFEARRAY(unsigned char) * ppGrabbedPicture );
The input parameter 'nQuality' represents the jpeg compression ratio, from 1 to 99. A value of one meaning lowest quality (highest compression) and a value of ninety-nine meaning highest quality (lowest compression).

As an output return value the client get the jpeg picture in a SAFEARRAY of unsigned char. We use this data type because it is fully supported by SOAP (See faced problem 1 and 2).

Our COM object supports the interface IErrorInfo as indicated by the ISupportErrorInfo interface. It permits sending back to the client information about possible issues encountered by the server. The good point is that it is fully automatic for us. Read more about that point in Microsoft SOAP User Guide: "Understanding the SOAP Fault <detail> Contents".

Before writing your interfaces check out the different types supported by SOAP in "Data Type Mappings" and there equivalence in programming languages. You find them in the Microsoft SOAP User Guide.

Web Service

We simply use Microsoft WSDL Generator to wrap our COM object, Camera, into a SOAP Web Service.

On the welcome page click Next.

On the dialog "Select the COM .dll to analyze":

Enter the name of your Web Service, i.e. webcam. 

Browse to select your dll.

Click Next.

On the dialog "Select the services you would like to expose":

Expand the list and check the GrabFrame method.

Click Next.

 

On the dialog "SOAP listener information":

In the URI text box, type the url of your webservice, i.e. http://localhost/webservices/webcam.

Choose ISAPI Listener type.

Then select 2001 as XSD Schema Namespace.

Click Next.

On the dialog "Specify the location for the new WSDL and WSML files":

Select UTF-8 as character set.

Then select the place you want to store the new files, i.e. c:\inetpub\WebServices\webcam.

Click Next.

Click Finish.

 


Now we have our Web Service! You must also define a Virtual Directory called WebServices in IIS.
In the case you want to change the location of the Web Service you need to change the WSDL file generated by Microsoft WSDL Generator.

Client

We use Visual C++ and Active Template Library (ATL) object Wizard to create an ActiveX, called Webcam. This ActiveX is the client part of the Web Service Webcam. It is connecting to the Webcam Web Service, receiving back a jpeg picture and displaying it.

To be able to compile the project you must have installed SOAP Toolkit on your computer. Find it here. For the client you must also have WTL installed. If It is not the case donwload it here.

Client Interface

To be able to grab a picture on the Webcam Web Service, we need to specify the location of the Web Service and a compression ratio. We define this interface:

    HRESULT GrabFrame([in] BSTR strWeb ServiceURL, [in] short nQuality);
  • Input parameter 'strWeb ServiceURL' represents Web Service's URL.
  • Input parameter 'nQuality' represents the jpeg compression ratio, from 1 to 99. A value of one meaning lowest quality (highest compression) and a value of ninety-nine meaning highest quality (lowest compression).

If we get an error, we display it in a tooltip. To create and display the tooltip we use Windows Template Library (WTL).

Test

You may test this Web Service after installing client ActiveX on this page.

Problems Faced

  • When adding the "GrabFrame" method to Webcam Server using the ATL "Add Method to Interface", the method was created correctly in .idl and .h files but the not in the .cpp. We can find a kind of explanation on MSDN: Q198017.
  • Before SOAP SDK SP2, SAFEARRAY(unsigned char) was not correctly handled. You need the SP2 to get a correct wrapping from SAFEARRAY(unisgned char) to base64Binary.

History

Version 1.00 December 4, 2001
First release.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Laurent Kempé
Architect
France France
Member

Laurent Kempé is the editor, founder, and primary contributor of Tech Head Brothers, a French portal about Microsoft .NET technologies.

He is currently employed by Innoveo Solutions since 10/2007 as a Senior Solution Architect and certified Scrum Master.

Founder, owner and Managing Partner of Jobping, which provides a unique and efficient platform for connecting Microsoft skilled job seekers with employers using Microsoft technologies.

Laurent is awarded by Microsoft since Avril 2002: Most Valuable Professional (MVP).


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionmy vote of 5membermuhamad yousef4 Jun '12 - 19:45 
Great work i will try it Smile | :)
GeneralIt's about time to leave the VFW and move to DirectShowmemberuvik30 Sep '10 - 11:20 
VFW is an old technology that is still good to produce still pictures
from a Camera but not good enough for Computer Vision.
Moving objects create blur effect it's about time to move on to DirectShow
that is better and can handle Interface to modern Input devices.
GeneralRe: It's about time to leave the VFW and move to DirectShowmemberLaurent Kempé30 Sep '10 - 20:23 
Can't agree more with that !
Best Regards,
 
Laurent Kempé [Microsoft ASP.NET MVP]
Visit my web site Tech Head Brothers.
 
---
Old programmers never die, they just branch to a new address.

GeneralA thank youmemberuvik30 Sep '10 - 23:54 
Dear Laurent,
 
Certainly your VFW component was great and popular for a lot of years.
For this I would like to thank you Big Grin | :-D
 
My reply was not to you but to people that still arrive to your article
to open their mind to new options.
 
An Idea, Visual C 6 is still very popular among a lot of Computer
Vision developers.
 
There are components that contain the DirectShow inside even here at
the CodeProject site but they were made for .NET
 
How about that you will contribute a new article to the CodeProject that will fill the gap and will implement a component to VS6.
 

Best regards,
 
Yoav
QuestionHow to creat the ".DLL" file??member8200151830 Jul '09 - 21:57 
About the WSDL/WSML Generator,there is a dll file,how to creat the "dll file"?
Generalit helps me!member7916711529 Jul '09 - 19:40 
Thanks,your article has helped me so much!I am a software fan,I am very like your article,though I am chinese.my site the firejay welcome you.
QuestionSOAP SDK v2.0 required?memberDan Thurman13 Jul '06 - 16:04 
I tried to build this program but apparently
it appears that the soap dll is missing?
 
StdAfx.cpp
C:\Documents and Settings\dant.CDKKT\Desktop\Code Project\WebCam Service\WebCam\ActiveX Client\stdafx.h(30) : fatal error C1083: Cannot open type library file: 'C:\Program Files\Common Files\MSSoap\Binaries\mssoap1.dll': No such file or directory
Error executing cl.exe.
 
Ok, so I tried to find the SOAP Toolkit SDK v2.0 to download and
install it but M$ appears to have removed it and replaced this
with SOAP ToolKit SDK with v3.0?
 
I tried changing the code from mssoap1.dll to mssoap30.dll but them
the next line of code appears missing:
 
StdAfx.cpp
==========
...
#import "C:\Program Files\Common Files\MSSoap\Binaries\mssoap1.dll" exclude("IStream", "ISequentialStream", "_LARGE_INTEGER", "_ULARGE_INTEGER", "tagSTATSTG", "_FILETIME")
using namespace MSSOAPLib; <=== missing
...
 
So, can anyone get this to build anymore?

AnswerRe: SOAP SDK v2.0 required?memberDan Thurman14 Jul '06 - 10:02 
Hi Folks,
 
In order to build this applications you will need:
 
Windows Template Library (WTL) v3.1
- this library is obsolete and does not exist online,
and requires OCT2000 PSDK CD if you still have it.
I have tried v7.1 and there are too many unresolvables
to deal with.
 
Microsoft SOAP v1.0 or maybe even up to v2.0. V3.0 will not work.
- SOAP v1.x is no longer available from M$ as far
as I know. If you attempt to install Web Services Toolkit SOAP
v2.0 or v2.01 you are required to have Office 2003 and VBA installed
otherwise setup will refuse to install.
 
So folks, IMHO this application is not worth building unless
you have the exact environment or want to take the pains to
update or re-port it.

Questionhow to caopture images in C++ using webcammemberrichytany12 Jul '06 - 3:10 
hello! I just bought a logitech quickcam pro 5000 (webcam), I have successfully installed it and can capture images on my pc. My problem is how to capture an image using MVC++. I don't know how to use the sdk and is there an algorithm or source code needed? Can you help me... thanks!
QuestionHow to get array of int, or byte without the safearraymemberguocang11 Jul '06 - 11:59 
Hi,
 
In COM method you used safe array to get the image buffer back. I wonder if I can safely get array of integers or bytes back without using the safe array as I am using an existing COM component.
 
Thank you.
 
Mike Zhang.
Questionusing camera example for a printer filememberdavid barnwell16 May '06 - 10:13 
I want to be able to send text output from a point of sale system to a remote sql server 2000 database. your article makes me think i could do this via atl
. What are the base classes for printed text. I think i could use that the same way you use the picture base class. Next I want to transform point of sale text data to xml format. would i need to call a windows service to do this- that is to caputure data as sale is rung up,via win 32 api up without cashier assistance.
My project is similar to yours. I want to transform Point of sale data from 30 point of sale clients to xml format send it over the web to sql server 2000 OLTP database and then have authenticated clients view the data via Excel from OLAP sql server 2000 database. Id like to be able to adapt your method but I need a base class for printed files since POS systems generate bills and i need to know how to transform those files to proper XML format
Thanks
sorry post is so longConfused | :confused:
Questionvirtual WebCammemberolariuadrian17 Feb '06 - 1:00 
I want to create a virtual webcam on windows. Can anyone help me?
 
2Fast
GeneralMicrosoft WSDL GeneratorsussAnonymous14 Jul '05 - 10:54 
How to launch Microsoft WSDL Generator?
GeneralYahoo ProtocolmemberManpreet Chadha25 Oct '04 - 19:01 
Hi I am Manpreet Can any one help me that how
I send message to yahoo messanger through my own
application? Plz Help me..
GeneralRe: Yahoo Protocolmemberpengdingfu24 Dec '04 - 17:01 
I can do it for you ,
pengdingfu@hotmail.com
GeneralHelp -- Compile Error for ClientmemberZhijie Wang27 Aug '04 - 11:34 
Hi,
 
Very nice sample. But when I am trying to compile the client application under .NET 2003, I got compile error "error C2065: 'LIBID_CAMSERVERLib' : undeclared identifier". Is there anything I am missing? Please help. Thanks in advance!
 

 
Zhijie
GeneralWeb ServicesussAnonymous11 Aug '04 - 23:11 
how can i call web service function from a ATL com component
Questionis .NET framework required ?memberhspc30 Jul '04 - 19:18 
Hi
thank you for this article..
A question here :
I did not try to consume a web service using VC++
Can I call a web service from ATL 3.0 or 7.0 without installing .NET Framework on the client ?
GeneralWebcammemberhungrau28 Apr '04 - 17:33 
Cool | :cool: I have a webcam JETEK 6006-11 series. I want to ask you how to write a program that take picture from that webcam and put it in to a specific location. Please, reply me as soon as posible..
Many thanks!!!
 
hunghong
QuestionCamera pilotable via interface web et ActiveX de la carte de capture video ?memberALIBAS26 Apr '04 - 20:25 

 
Hello,
 
I'm sorry but the text is in French, I hope Dear Laurent Kempé will help me
sure any one else . Thanks
 

Bonjour,
 

Voila, j'ai une carte de capture video inserée dans
le port PCI d'un PC et cette carte a un logiciel fourni avec.
 

A cette carte est relié une camera, le logiciel
permet de capturer les images observées par la
caméra et même de les enregistrées, bref à tas
d'autres choses.
 

Il existe une application du logiciel (Système WebCam) de
la carte de capture qui permet à un utilisateur connécté
sur Internet de visualiser les images de la caméra et
ceci sans rien installer dans son pc sauf bien sûr un
navigateur pour surfer sur Internet ( logique! ) .
L'utilisateur doit aller à l'adresse Internet du serveur
où se trouve la carte et le logiciel, une fois connecté
l'utilisateur clique sur la page demo de visualisation
de la camera et voit apparaïtre, en page internet (HTML),
sur son ecran un interface utilisateur (comme pour les
webcam, une sorte de fenêtre à l'intérieur duquel il y a
les images cameras) cette interface à un design propre à lui.
 

Ma question est :
>Pourrais-je modifier ce design de l'interface en insérant les logos que je veux , modifier la forme, etc... en travaillant le code HTML, Javascript de la page Internet
 
>ou dois-je carrément reprogrammer l'Activex propre à la carte (et si c'est le cas comment)?
 

NB: en faisant "affichage -> source", le code Html de
la page demo apparait et je vois à l'interieur javascript
et Activex et aussi du code tel que: document.WebCamX1.PlayX(); )

 
---->Donc cela veut peut-ëtre dire que je dois soit modifier les
Activex (COM)du logiciel installé dans le PC serveur, soit modifier
les fichiers web du logiciel installé dans le PC serveur?
 

---->Et qu'est-ce que ActiveX ?
 
1) est-ce au fond un DLL de microsoft ?
 
2)ou bien un programme propre à la carte de capture
qui joue le rôle d'associer à un logiciel du materiel?
 
---->Pourrais-je programmer à part un Activex sans que celui-ci ai des répercutions sur l'ensemble logiciel de la carte
 

Merci à toute personne me rapportant des réponses et conseils.
 

 


QuestionCamera pilotable via interface web et pour l'ActiveX de la carte de capture video ?memberALIBAS26 Apr '04 - 4:46 

Bonjour,
 
Voila, j'ai une carte de capture video inserée dans
le port PCI d'un PC et cette carte a un logiciel fourni avec.
 

A cette carte est relié une camera, le logiciel
permet de capturer les images observées par la
caméra et même de les enregistrées, bref à tas
d'autres choses.
 

Il existe une application du logiciel (Système WebCam) de
la carte de capture qui permet à un utilisateur connécté
sur Internet de visualiser les images de la caméra et
ceci sans rien installer dans son pc sauf bien sûr un
navigateur pour surfer sur Internet ( logique! ) .
L'utilisateur doit aller à l'adresse Internet du serveur
où se trouve la carte et le logiciel, une fois connecté
l'utilisateur clique sur la page demo de visualisation
de la camera et voit apparaïtre, en page internet (HTML),
sur son ecran un interface utilisateur (comme pour les
webcam, une sorte de fenêtre à l'intérieur duquel il y a
les images cameras) cette interface à un design propre à lui.
 

Ma question est :
>Pourrais-je modifier ce design de l'interface en insérant les logos que je veux , modifier la forme, etc... en travaillant le code HTML, Javascript de la page Internet
 
>ou dois-je carrément reprogrammer l'Activex propre à la carte (et si c'est le cas comment)?
 

NB: en faisant "affichage -> source", le code Html de
la page demo apparait et je vois à l'interieur javascript
et Activex et aussi du code tel que: document.WebCamX1.PlayX(); )

 
Donc cela veut peut-ëtre dire que je dois soit modifier les
Activex du logiciel installé dans le PC serveur soit modifier
les fichiers web du logiciel?
 

Et qu'est-ce que ActiveX ?
 
1) est-ce au fond un DLL de microsoft ?
 
2)ou bien un programme propre à la carte de capture
qui joue le rôle d'associer à un logiciel du materiel?
 

Merci à toute personne me rapportant des réponses et conseils.
 
Note: I'm sorry to write this texte into French because it's more sure for me, Thank you

 

Questionweb page sample doesn't exist ?memberorenboskila19 Feb '04 - 13:37 
the web page sample doesn't exist ?
AnswerRe: web page sample doesn't exist ?memberLaurent Kempé19 Feb '04 - 21:20 
sorry for that but I could not let it run more.
 
Best Regards,
 
Laurent Kempé [Microsoft .NET MVP]
Visit my web site Tech Head Brothers.
 
---
Old programmers never die, they just branch to a new address.
Questionhow to save a flash file created with a object as a gif/jpg/bmp file?memberzhongxunyang24 Sep '03 - 16:49 

i used a flash object downloaded from http://bukoo.sourceforge.net to create a flash file, and now i want to add a function and it can allow people to save this flash file as a jpg/gif/bmp file.how shold i do?Do i have to find a component to realize this function?




AnswerRe: how to save a flash file created with a object as a gif/jpg/bmp file?editorNishant S24 Sep '03 - 17:26 
zhongxunyang wrote:
i used a flash object downloaded from http://bukoo.sourceforge.net to create a flash file, and now i want to add a function and it can allow people to save this flash file as a jpg/gif/bmp file.how shold i do?Do i have to find a component to realize this function?
 
Definitely the wrong place to ask this question.
 
Nish
 

Extending MFC Applications with the .NET Framework [NW] (coming soon...)
Summer Love and Some more Cricket [NW] (My first novel)
Shog's review of SLASMC [NW]
Come with me if you want to live

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 24 Apr 2002
Article Copyright 2002 by Laurent Kempé
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid