Tuesday, September 4, 2012

Capture Portion of Image from Webcam


Are you interested in having something like a small application that captures an image from a webcam?  Just like when we get our driver's license where we simply stand on one side  then the operator says "hold still..." then later gives a thumbs up sign?  When the driver's license card is presented to us, we see that our face is snapped and cropped so it fits properly on said license.

Is this hard to do with VFP?  Not if you know where to look for tools already shared to us by others.



To tap onto a webcam from inside VFP, here is one graciously shared to us by Anatoliy Mogylevets:  http://fox.wikis.com/wc.dll?Wiki~VideoCaptureApi




But the tool by itself is not enough because you cannot simply crop the portion of the image you wanted. You get the whole video frame.  So while a trick is to make the frame small enough just based on our needed size, that IMHO is not the proper way to go.

Therefore we need another tool for cropping.  And that tool is graciously shared to us as well by Gelson L. Bremm via a post by a friend, Cesar, author of FoxyPreview, FoxCharts and a lot more GDI+ and GDIPlusX tools.   Here is the link with codes to capture screen portions:  http://weblogs.foxite.com/vfpimaging/2006/03/20/capture-screen-portions


Put those two together, adjust those based on your needs, and you have the needed instant Image Capturing with cropping ability like this:


Now the good thing about this approach is you can move around the frame for capturing so they don't need to be always exactly on the very same spot.  If the person is shorter, you can point the webcam a little downwards.  Then move the capture frame to get exactly the face portion of the person.  Same when a person is a little bit taller.

In my end, as I love to spice things up a little, I employ ssSkinner to give my module a little more color.  So the module can suddenly look like this with just a spin away:


Or this:


One thing I want you to notice in the above images  is the location of the capture form.  Like I said, this approach gives you more flexibility in that you can move it around based on the image you are trying to capture.

And you may wonder why the video frame is showing my watch while the image is showing a person?  That is because I have not clicked "Snap Picture Now!!!" button because if I do, then the face will be replaced by the watch.  And these are live data so I simply show here how things can be done without actually touching the records.


I hope this post gives you the necessary ideas how to have the same on your end. Cheers!