Share via


Timed Camera Capture

Jason Langrage asked if it’s possible to automatically capture an image from the camera of a WM 5.0 Smartphone every 30 mins, and then to upload to a web service.

WM5.0 has three new ways of working with the camera, but unfortunately the two mechanisms easily accessible from managed code both require user input in order to capture an image.

The first new api is CameraCaptureDialog that allows an application to invoke the camera view so the user can capture stills, video or video and audio files to a store location on the device.

CameraCaptureDialog ccd = new CameraCaptureDialog();

ccd.ShowDialog();

pictureBox1.Image = new Bitmap(ccd.FileName);

The second api is SelectPictureDialog and is a step further away from the camera, providing a list of images found on the device and an option to invoke the camera to capture another.

SelectPictureDialog ssdn = new SelectPictureDialog();

ssdn.ShowDialog();

pictureBox1.Image = new Bitmap(ssdn.FileName);

Both of these are useful, but can’t be used to automatically drive camera capture. The third new technique for working with the camera is through DirectShow. This is a fairly complex set of COM objects taken from the desktop equivalent and reduced to fit the device. It provides modular structure for processing video and audio data both for capture and for display. For full documentation of DirectShow on the desktop take a look here. For more specific info on DirectShow for Windows CE 5.0 take a look here.

There is a sample native app in the SDK called CameraCapture that shows how to use DShow to build a filter graph that takes the camera input, encodes it as a WMV and stores a video file. It also has a still image graph that stores a single still image as a file. It’s possible with CF 2.0 to turn the whole sample into managed code, but I couldn’t be bothered so I just converted the CameraCapture into a DLL, stripped the video bits to leave just the still image processing. Then a simple managed app with a timer fires the request every 30 seconds and uploads to a web service using Base64 encoding. Pretty straight forward really.

Anyway, if you want the code then its here:

TimedCamera.ZIP        - device camera code.

ImageUpload.zip          - web server code.

Extract the web site to your inetpub\wwwroot, right click on ImageUpload select Sharing and Security, then select the web tab and enable sharing with the default settings. Next build and run the TimedCapture code on your device. The standard code disclaimer applies.

I guess the next step is to use a socket to stream camera video from device to a desktop…

 

Marcus

Comments

  • Anonymous
    March 06, 2006
    I don't think anyone would want a new picture of the inside of my pocket every 30 minutes :)

  • Anonymous
    March 06, 2006
    Scott,
    I'm sure you are right :) But imagine a mounted Pocket PC or Smartphone used as a 'cheap' security device sending images to a web server. For example, if you are a student using a shared fridge, stick your device to the inside door and catch the thief steeling your milk. Could be a lot of fun!
    Or use the device for time laps image capture on a construction site.

    Marcus

  • Anonymous
    March 17, 2006
    PingBack from https://newyear2006.wordpress.com/2006/03/08/automatisches-aufnehmen-von-bildern-unter-wm5/

  • Anonymous
    March 24, 2006
    The comment has been removed

  • Anonymous
    April 09, 2006
    i only want to get the Image'date(Example: BMP's Data),i don't how to do. when i find the TimeCamera.zip,
    i download TimedCamera.zip,and use the graphmanager.cpp as the capture still image's app and transfer as CE tool's CameraCapture.nls.

    when i debug this CameraCapture.exe:
    m_pCaptureGraphBuilder->ControlStream( &PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, m_pVideoCaptureFilter, 0, 0 ,0,0 ));

    hr != S_OK.

    i use the mobile of Dopoda 830 for Develop!

    what is wrong?
    Thanks in advance.

  • Anonymous
    April 09, 2006
    Marcus:

    I download the "TimedCamera.ZIP" and load into VS 2005, I got error message is "Error retrieving information from user database. Platform not found", I had install Mobile 5.0 PPC SDK and DirectX SDK (2006.2 version). so, do you know how can I do ?
    Thank you..

  • Anonymous
    April 10, 2006
    i get the TimedCamera.ZIP.
    why alwasy faile at "CHK( m_pCaptureGraphBuilder->ControlStream( &PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, m_pVideoCaptureFilter, 0, 0 ,0,0 ));"
    when i debug the nls on Dopod 830(WinCe 5.0 Pocket PC).

    i come from china,i am an exacting task to read the article in English.maybe i miss same important's explain.

    thanks very much for all helps.

  • Anonymous
    April 12, 2006
    The comment has been removed

  • Anonymous
    April 26, 2006
    The comment has been removed

  • Anonymous
    May 07, 2006
    I download .zip file. Successully compile CameraCaptureDLL.dll

    Now I want to use it in my native code application. I tried:

    =======================================
    typedef BOOL (*fnInitializeGraph)(HWND hwnd);
    typedef BOOL (*fnCaptureStill)(TCHAR szfile[MAX_PATH]);

    BOOL CamCap()
    {
    INSTANCE hCam = LoadLibrary(TEXT("CameraCaptureDLL.dll"));
    fnInitializeGraph funcInitializeGraph = NULL;
    fnCaptureStill funcCaptureStill = NULL;

    funcInitializeGraph = (fnInitializeGraph)GetProcAddress(hCam, TEXT("InitializeGraph"));

    if (funcInitializeGraph)
    {
        funcInitializeGraph(hWnd);
    }
    ...
    =======================================

    the last function hungs up my application

    what did I made worng?

  • Anonymous
    May 12, 2006
    when I run the TimedCamera i get an error saying:

    System.MissingMethodException was unhandled
     Message="Can't find PInvoke DLL 'CameraCaptureDLL.DLL'."
     StackTrace:
       at TimedCamera.TimedCaptureForm.Form1_Load()
       at System.Windows.Forms.Form.OnLoad()
       at System.Windows.Forms.Form._SetVisibleNotify()
       at System.Windows.Forms.Control.set_Visible()
       at System.Windows.Forms.Application.Run()
       at TimedCamera.Program.Main()

    what am I doing wrong?

    thanks!

    lucasjordan AT gmail DOT com

  • Anonymous
    May 20, 2006
    the code runs fine but no images.  put a breakpoint just after it captures the image but the image file does not exist.  dont really know how to stop the code at graphmanager.cpp so could not know what is going on.

  • Anonymous
    May 22, 2006
    Hi!

    Has anyone tried to use it on i-mate SP5 smartphone. The error is "Error from capture" for me too, I think is has something with the hardcoded cameraGuid. :(. How can I find out the real guid?

  • Anonymous
    May 22, 2006
    The comment has been removed

  • Anonymous
    October 30, 2006
    The comment has been removed

  • Anonymous
    December 03, 2006
    Hello Do you have an example of performing real-time video analysis, using an i-mate camera ? Thanks Oren

  • Anonymous
    December 20, 2006
    hi, I  have been having the same problem when trying to load the project file into VS 2005. I get the following messages: 'Error retrieving information from user datastore - Platform not found' 'The project could not be opened because it refers to a device platform that does not exist in your datastore' The thing that worries me most is the fact that I have installed VS2005, windows ce 5.0, NET Framework etc, tried to rename/delete folder CoreCon/1.0 but still get the same error. Has someone any ideas? Many thanks.

  • Anonymous
    January 20, 2007
    The comment has been removed

  • Anonymous
    February 07, 2007
    You should install the Mobile 5 SmartPhone SDK

  • Anonymous
    February 08, 2007
    Does anyone know how to take the video stream and display it in a mobile 5 application usng a media control to create a video preview form? Any links that would be useful as well. Thanks

  • Anonymous
    March 23, 2007
    Hi, I am using the modified DirectShow Camera Capture sample for capturing the Video from my Win Mobile device. Now my problem is that I want to capture it direct-to-disk using directshow (so that the user can see real-time increase in size of the captured file and should also be abel to preview the file midway in between (using the local media player), while recording is still going on). I could easily capture the video from the win mobile camera, and also the associated Audio. But it gets written to an asf file in the specified location, only after I manually stop the capturing by click of the Stop button on my custom interface. My need is that the captured audio and video keeps on getting written to the asf file continously as i capture, without depending on user input to stop the recording. This means that on start of the camera capture, a file should be instantaneously created in the specified location, and captured video/audio keeps on getting written frame-per-frame to this file and the file should keep on growing in size with the progress in capturing. Please let me know how to do that, since I could not find anything on the same. Please mail me if you got any solution on this at arjun.bahree@gmail.com Thanks in Advance

  • Anonymous
    April 27, 2007
    I wonder how to modify the upload portion, so the images can be uploaded using a standard web server via POST method.  I haven't found an API that does this, even though it's possible to construct a data stream resembling a POST action.

  • Anonymous
    May 25, 2007
    Hi, thnx for this code! It comes really handy. I only can't find where to change the resolution. Do you (or anybody else)know where to do this. Grtz and thnx again!!

  • Anonymous
    June 15, 2007
    Hi Marcus, This is a really useful bit of code, shame they couldn't put this into the managed API. Could you give me a pointer as to how I can get it to capture higher res? Do I need to create a custom filter?

  • Anonymous
    June 21, 2007
    do you have c# code please?thank you

  • Anonymous
    July 02, 2007
    Regards the Timed Camera Capture sample I posted last month, lots of you came across a bug in my code

  • Anonymous
    July 03, 2007
    The comment has been removed

  • Anonymous
    September 03, 2007
    Hi I didn't belive it helps - nevertheless I tried ;) Code like this: camera.Resolution = new Size(640, 480); Doesn't help me with changeing the resolution! Any other Ideas? BR Daniel

  • Anonymous
    September 12, 2007
    when I run the TimedCamera i get an error saying: System.MissingMethodException was unhandled Message="Can't find PInvoke DLL 'CameraCaptureDLL.DLL'." StackTrace:   at TimedCamera.TimedCaptureForm.Form1_Load()   at System.Windows.Forms.Form.OnLoad()   at System.Windows.Forms.Form._SetVisibleNotify()   at System.Windows.Forms.Control.set_Visible()   at System.Windows.Forms.Application.Run()   at TimedCamera.Program.Main() what am I doing wrong? thanks!

  • Anonymous
    September 13, 2007
    Hi! How To change Camera Rotation and Resolution Please Help...

  • Anonymous
    September 22, 2007
    Hello, I have the same problem as you all. I can't change the resolution for the pictures (only 160x120) Did any of you found a solution ?

  • Anonymous
    September 25, 2007
    I got the following error when i try to deploy the application:- Unable to start program '%CSIDL_PROGRAM_FILES%TimedCameraTimedCamera.exe'. The system cannot find the file specified. Can anybody please help me out?? It's very urgent please!!!

  • Anonymous
    October 10, 2007
    Hi I want to change the camera zoom value but I've had some troubles. I must use IACameraControl::Set interface Can you help me with this please?

  • Anonymous
    October 10, 2007
    I don't have ImageUpload web site. Is anyone willing to share his URL with me? Thanks a lot. MSN/Email: hendryyang@hotmail.com

  • Anonymous
    October 16, 2007
    I would like to change the resolution to 640 by 480. Can anybody post a code sample of how to change this.

  • Anonymous
    November 14, 2007
    Anyone found a resolution for this error yet: Can't find PInvoke DLL 'CameraCaptureDLL.dll' Thanks, nb

  • Anonymous
    December 04, 2007
    Resolution for "Can't find PInvoke DLL 'CameraCaptureDLL.dll" It is during deployment of the app to your phone/pda that this file is not getting copied.  That's why when the app executes, it can't find the file -- it was never there to begin with. A solution is to add this file into your VS.net 2005 project.  in Solution explorer, right-click the project and choose Add>Existing Files, then select the CameraCaptureDLL.dll. Once the file is added, check the properties.  It should say that the file is considered as 'Content'.  Set the option to Copy to Output Directory All the Time. Rebuild and re-deploy.  The error should now disappear.

  • Anonymous
    December 11, 2007
    PingBack from http://www.christec.co.nz/blog/archives/208

  • Anonymous
    March 18, 2008
    I have used your program to record video and still image capture but when added the code for preview its getting hanged. Do u know whats the reason behind it. I am using HP iPaq Mobile device with windows mobile ver 5.0. I am using a panel to show the preview in C# and passing this handle to dll function private static extern bool InitializeGraph(IntPtr hWnd, IntPtr hwndPanel);

  • Anonymous
    April 02, 2008
    Hello I try to captre images from Pocket PC's camera, about 10 images/s. the CameraCaptureDialog() doesn't work as I need. so can you tell me how to do? thanks

  • Anonymous
    April 02, 2008
    for you task about Can't find PInvoke DLL 'CameraCaptureDLL.dll' you have to put the dll file in the same directory with your compiled programm in the device you use. I hope it will be helpful for you

  • Anonymous
    June 06, 2008
    For those asking about image size, goto MSDN and look-up the COM API's used in "CGrapManager::CaptureStillImageInternal()" and fix it yourself...

  • Anonymous
    June 10, 2008
    Hi Marcus, Really great work! I was able to make run this on HTC mobile phones. Can you just give a clue on how to make the camera available to users in the code. Regards Sasi

  • Anonymous
    July 02, 2008
    Works great on CE5 HP device. Anybody run this on CE6?  All I get is a black screen, tried 2 different device makes.   Regards, Seán.

  • Anonymous
    July 07, 2008
    It works fine for 1 sec but throws error for less than one second capturing. Do some fix is required to capture 1 / 2image per second.

  • Anonymous
    July 28, 2008
    The comment has been removed

  • Anonymous
    September 16, 2008
    Folks, I am using Visual C# 2008 and windows mobile 6 and I wander if anybody has used it under the same system.

  • Anonymous
    September 18, 2008
    Did anybody figure out how to set the resolution of the camera using IAMCameraControl. I can not find the right parameters for the set function

  • Anonymous
    September 20, 2008
    i use these code in two camera (HP Photo Samart SD camera & FlyCam CF 1.3M) but it didn't work CameraCaptureDialog ccd = new CameraCaptureDialog(); ccd.ShowDialog(); pictureBox1.Image = new Bitmap(ccd.FileName); i don't know why it doesn't work and appear errors ?

  • Anonymous
    September 20, 2008
    i use these code in C# with two camera (HP Photo Samart SD camera & FlyCam CF 1.3M) but it didn't work CameraCaptureDialog ccd = new CameraCaptureDialog(); ccd.ShowDialog(); pictureBox1.Image = new Bitmap(ccd.FileName); i don't know why it doesn't work and appear errors ? anyone could capture image with this method ? Thanks in advance

  • Anonymous
    September 20, 2008
    i use these code in C# with two camera (HP Photo Samart SD camera & FlyCam CF 1.3M) but it didn't work CameraCaptureDialog ccd = new CameraCaptureDialog(); ccd.ShowDialog(); pictureBox1.Image = new Bitmap(ccd.FileName); i don't know why it doesn't work and appear errors ? anyone could capture image with this method ? Thanks in advance

  • Anonymous
    September 20, 2008
    PingBack from http://blog.israrkhan.com/?p=144

  • Anonymous
    October 26, 2008
    I've always wanted my phone to take a picture with the camera a few seconds after I initiate a phone

  • Anonymous
    November 16, 2008
    hi, i've project on pocket pc my problem is: how can i deal with camera directly so that i can take pictures and save them while capturing a video . (snapshots) thanx anyway kind regards

  • Anonymous
    December 24, 2008
    Can't download any of the zip files. Are they still available???

  • Anonymous
    January 13, 2009
    sorry but you're wrong, you can use the camera capture dialog to take pictures automatically if you use it with another thread wich press the take picture key for you. it's really easy to made.

  • Anonymous
    January 18, 2009
    PingBack from http://www.keyongtech.com/4347058-directshow

  • Anonymous
    January 21, 2009
    PingBack from http://www.keyongtech.com/467121-auto-image-capture-from-camera

  • Anonymous
    January 23, 2009
    Guys! I used this code: CameraCaptureDialog ccd = new CameraCaptureDialog(); ccd.ShowDialog(); pictureBox1.Image = new Bitmap(ccd.FileName); But it´s needed to add references in project.

  • Microsoft.WindowsMobile
  • Microsoft.WindowsMobile.Forms. Without this references the class CameraCaptureDialog doesn´t works corretly.
  • Anonymous
    March 01, 2009
    The downloads are timing out. Any mirrors for them? Thanks

  • Anonymous
    March 13, 2009
    Hi Everbody, i have the same dll not found problem. i could not open CameraCaptureDLL project in VS2005. Can you help me to get CameraCaptureDLL.dll file please?

  • Anonymous
    March 17, 2009
    Hi, I want CameraCaptureDialog should not go in Standby Mode after 30 seconds as it is going. I want to extend this time. Is it possible ?

  • Anonymous
    March 19, 2009
    Hi Marcus, Can you help about the image resolution?

  • Anonymous
    June 10, 2009
    Hmm, if I'm not mistaken you could use this code to create a custom camera dialog?