Link to home
Start Free TrialLog in
Avatar of Member_2_1348041
Member_2_1348041Flag for Ireland

asked on

Dealing with Vermin

And for those of you who don't visit the Lounge on a regular basis, please read this first:
https://www.experts-exchange.com/questions/21222015/Vermin.html

Now then, I've had an idea. And I would like to get some input from you experts. Now I realise that this is a solution that will come in many parts, and I'd like to reward each contribution separately. I will therefore leave this question at the bare minimum of points, will post "points for" questions for every suggestion contributing to the solution.

What I am looking for is this:

1) A programatic approach toward capturing images from a PC Cam. Please do not post 3rd party tools here, I am looking for vanilla VB code that goes and gets the image directly from the camera, if necessary through API calls.

2) Secondly some suggestions toward "motion sensing". My idea was to take the images in sequence, divide them into, say, nine sub-images and if more than one (two, three?) sub-image is different from before I will treat that as motion occurring and will act on this. My guess is that this would be sufficient to avoid it recording the slow brightening and darkening of the image due to the changes in daylight during the day, but it should pick up the drastic changes from something appearing in front of the camera.

Cheers

Pino
Avatar of Member_2_1348041
Member_2_1348041
Flag of Ireland image

ASKER

With regard to the image capture I guess perhaps some TWAIN-based mechanism would be appropriate? That way it could even handle multiple cameras?
Hum...

Looks like I'm barking up the wrong tree with TWAIN - it invokes some interface that I cannot get rid off. I need to directly access the Cam's output.

Back to square one....

Is anyone actually reading this or am I talking to myself?
Found Ray Mercer's vidcap project. Impressive. Only thing is I realise there is no way I can do movement sensing with this. I pointed cam at blank wall and took two separate pictures. They're different. You get two bitmaps of the identical image, and their CRCs are totally difficult. Camera keeps readjusting exposure and so on changing the picture constantly....

Hi ho hi ho....
You're looking at noise in the picture.

Difficult subject, but let's have some fun.  You'll have to do some image processing to clean up the images a bit: apply a soften effect to reduce noise, convert to grayscale, and maybe increase the contrast somewhat.

Now compare 2 images taken at different times. Reading the differences of 2 images is relatively easy:

1) Grab and process 2 images as above.

2) Use StretchBlt to copy the first image to a picturebox using the SRCCOPY rop code while scaling it down to a smaller size, maybe 64 x 64 pixels.

3) With the second image, use StretchBlt to the same picturebox as above, but with the SCRINVERT rop code.  Also scaling down to the same size as above.

4) The resulting picture will be black where the pixels are identical, and gray or white where the pixels are different.  Loop the pixels in the picture and keep count of the non-black pixels.

That is the most basic approach.  But don't blame me if the cops show up at your door because the sun came out from behind the clouds!

:-)
Nice one, Erick - I do grok the ol' blittin' gig so I think you may be on to something.

I guess then the trick with the "motion detection" is to go for distinctive changes in the image. If the double-blit result from your suggestion there is a fairly uniform *grey* rather than *black* you can still assume that all that happened is, like you suggested there, a sudden brightening or darkening of the whole image due to weather conditions. If an *area* of the image turns grey/white while the rest remains pretty much black/grey, we have real movement on our hands.

This sounds promising and I shall investigate. If it works.... I have 550 points to play with and I dare say some of those may be on their way to you, my son....
By Jove Erick. You really do appear to have hit the jackpot there old boy.

That StretchBltting does do the job alright, and if you reduce the size to 64x64 it's pretty much uniform black until you move.

Still, a little bit of flickering - what about that "softening" and "contrast" stuff you were talking about. How does one go about doing that then?
ASKER CERTIFIED SOLUTION
Avatar of Erick37
Erick37
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That first link is a gem, Erick. It should do quite nicely, thanks....
Sorry Erick, we've had a very sick baby over the weekend. Suffice to say that the last thing on my mind was playing with software. Will keep you posted.

Pino
No hurry.
Hope the little one feels better.
Still haven't had a chance to look but in fairness you have given me a lot to go on.
Thanks Pino,

Here's a link to another packaged solution which I have on my holiday list.  The Linksys wireless internet camera with integrated motion detection:

http://www.linksys.com/products/product.asp?grid=33&scid=38&prid=650