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 (65)

  1. Scott says:

    I don’t think anyone would want a new picture of the inside of my pocket every 30 minutes 🙂

  2. marcpe says:

    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

  3. Nino.Mobile says:

    TGIF!

    Software / Hardware

    Sling Media has released SlingPlayer for Windows Mobile (via msmobiles.com) …

  4. Nlgavin says:

    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.

  5. Roger says:

    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..

  6. Gavin.Chen says:

    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.

  7. Jon says:

    Hi Marcus,

    I am finding that some win mobile 5 devices just wont run the Directshow TimedCamera code. Have you found the support of  cameras under winmob5 not as  standardized as it was supposed to be?

    On the devices that do run it, I am having a real fight setting the image size, can anyone point me the right direction 🙂

  8. Simon says:

    Hi there!

    This code is exactly what I have been trawling the web for!  I need to make an application that will stream images from a Windows Mobile 2005 PocketPC (HTC Universal) to a web service so that clients can then view the "latest" image.  The standard Camera dialog is not suitable to the user intervention it requires, and my C++ knowledge is practically none-existent, so this wrapper for it is ideal.

    However, I have run into a problem with it.  I have got the code working fine on the device, but every time I get a response from the camera of "Error from capture" and am unable to identify why. (This is in the ResponseToMessage method, in the switch statement, at the line "case (int)DSHOW_MESSAGE.MESSAGE_ERROR:".

    I was wondering if you had any ideas why this might be, or could point me in the right direction?

    Cheers!

  9. JG says:

    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?

  10. Lucas Jordan says:

    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

  11. acs says:

    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.

  12. Roby says:

    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?

  13. marcpe says:

    BUG BUG

    there is a cut paste error in my code. Sorry!

    Just before I posted this I was tidying up the code to take out video capture and I remove one line that adds the filter graph for encoding.

    I have dropped an updated ZIP over at the same link.

    Marcus

  14. Marcus

    Thanks for this code sample.  I tried it out on my new Cingular 8125, and it works like a charm.  However, I have only one problem:  the still images it takes are always 160 wide X 120 pixels high, and I can’t seem to find any way in your code to set the image size.  

    The phone has a 1.3 megapixel camera, and when I use the built-in picture taking program, 160X120 is the smallest size available, with a couple other bigger sizes including 1240 X 760 or something high resolution like that.

    Do you know of any way to set this picture size?  Thanks.

  15. Oren says:

    Hello

    Do you have an example of performing real-time video analysis, using an i-mate camera ?

    Thanks

    Oren

  16. tzim says:

    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.

  17. aries firdiansyah says:

    I’ve been compiling CameraCaptureDLL.DLL with windows mobile 5 device platform successfully but when i add it into my windows mobile 5 smart device application reference, it will not be able to add and show message like this : A reference to CameraCapture.DLL could not be added. When I change DllImport into correct path of CameraCaptureDLL.DLL (Or when I copy file CameraCaptureDLL.DLL to c:windowssystem32 without changing the DllImport syntax),it will return message like this : MissingMethodException Can’t find PInvoke DLL ‘C:/CameraCaptureDLL.DLL’. I’m using ETEN Windows Mobile 5 Pocket PC. So how can i try your code ????? i need your help… thanks before email me at : cipinkman@cs.its.ac.id

  18. Yosef says:

    You should install the Mobile 5 SmartPhone SDK

  19. Yosef says:

    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

  20. Arjun says:

    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

  21. doubletree says:

    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.

  22. Annihil8 says:

    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!!

  23. Thom Shannon says:

    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?

  24. china says:

    do you have c# code please?thank you

  25. Regards the Timed Camera Capture sample I posted last month, lots of you came across a bug in my code

  26. Nasir says:

    Hello,

    Many of you ask how to change the resolution of the image taken. I think following line of code should do it for you:

    camera.Resolution = New Size(640, 480)

    where camera is an object of class CameraCaptureDialog.

    Cheers

  27. Daniel says:

    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

  28. ibrahim says:

    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!

  29. ibrahim says:

    Hi!

    How To change Camera Rotation and Resolution

    Please Help…

  30. Mayor says:

    Hello,

    I have the same problem as you all. I can’t change the resolution for the pictures (only 160×120)

    Did any of you found a solution ?

  31. Amit Verma says:

    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!!!

  32. Omar says:

    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?

  33. greathendry says:

    I don’t have ImageUpload web site. Is anyone willing to share his URL with me?

    Thanks a lot.

    MSN/Email: hendryyang@hotmail.com

  34. Jami says:

    I would like to change the resolution to 640 by 480. Can anybody post a code sample of how to change this.

  35. Anyone found a resolution for this error yet:

    Can’t find PInvoke DLL ‘CameraCaptureDLL.dll’

    Thanks,

    nb

  36. Herman says:

    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.

  37. Anil Sambasivan says:

    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);

  38. kim says:

    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

  39. archer says:

    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

  40. peopleNeedToUseMSDN says:

    For those asking about image size, goto MSDN and look-up the COM API’s used in "CGrapManager::CaptureStillImageInternal()" and fix it yourself…

  41. Sasikumar says:

    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

  42. Sean says:

    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.

  43. Sasikumar says:

    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.

  44. karol says:

    I`m looking for code using camera flash because I`m trying to do flash light from phone. I have seen your code but is hard for me. Could you give some url to material about programing phone camera(exacly i need turning on and off the camera flash)?

  45. Mohammad rahimi says:

    Folks,

    I am using Visual C# 2008 and windows mobile 6 and I wander if anybody has used it under the same system.

  46. Mohammad rahimi says:

    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

  47. S.Majid says:

    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 ?

  48. S.Majid says:

    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

  49. S.Majid says:

    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

  50. I've always wanted my phone to take a picture with the camera a few seconds after I initiate a phone

  51. salam says:

    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

  52. IraqiGeek says:

    Can’t download any of the zip files. Are they still available???

  53. Carlos says:

    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.

  54. Andre Putz says:

    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.

  55. TrickiDicki says:

    The downloads are timing out. Any mirrors for them?

    Thanks

  56. Resul Özdemir says:

    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?

  57. Aqil says:

    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 ?

  58. resooul says:

    Hi Marcus,

    Can you help about the image resolution?

  59. junk says:

    Hmm, if I’m not mistaken you could use this code to create a custom camera dialog?

Skip to main content