Motion Detector.NET - detects movement inside a webcam's field of view.
This program captures images from a webcam and determines the level of movement in the camera's field of view. When the level of movement exceeds a threshold specified by the user, it displays a message box.
The program works by comparing the most recently captured image with the previous one. The difference between the two images is used to determine the level of movement. Thanks to the LockBits/UnlockBits methods the GetPixel/SetPixel functions/methods are avoided which improves the program's performance.
This program should also be useful to find out how to use a webcam in general in Visual Basic.NET.
See the attached .zip file for the program.
This program is a .NET version of: Motion Viewer (Vb 6)
It does not (yet?) have an e-mail function though.
Re: Motion Detector.NET - detects movement inside a webcam's field of view.
Is this yours or a simple re release? I have not viewed the code fully but Three things that instantly jumped out.
CInt(0)
On Error Resume Next
End
Re: Motion Detector.NET - detects movement inside a webcam's field of view.
Hi, thanks for commenting on my program. To answer your questions:
1. CInt(0) - I always explicitly convert literal numerals to the required data type when doing API calls. A bit redundant perhaps...
2. On Error Resume Next - I only use it in the program's general error handling procedure. I'm not going to build another error handler for the very unlikely case that something goes wrong there. I know there are better ways to go about it and if I feel it's worth it to do more elegant error handling in a specific situation I wouldn't use something this crude.
3. End - As you can see it's only used when the user chooses to close the program when an error has occurred.
Some of my programming practices may be a bit crude, but this is just a free program that I wrote to demonstrate how one could use a webcam in vb.net because I enjoy writing stuff in vb.net. Not a business critical application that I was paid for.
Still I'm willing to learn, how would you fix the issues you mentioned?
EDIT:
And what you mean "Is this yours"? It's a remake in vb.net of one of my vb6 programs.
Re: Motion Detector.NET - detects movement inside a webcam's field of view.
1) Why would you convert a integer to an integer?
2) On error has no place in vb.net
3) End does not close an application. It crashes it. Should NEVER be used. In some cases can actually cause system damage. MSDN states this also.
Re: Motion Detector.NET - detects movement inside a webcam's field of view.
Quote:
Originally Posted by
Peter Swinkels
Still I'm willing to learn, how would you fix the issues you mentioned?
1. There is no need to convert one value into a value of the same type.
2. On Error Resume Next should only be used in those rare cases where you have a bug that appears out of nowhere even after 100 or more times running the code and no receiving an error. I think a try/catch would replace the need for this.
3. Use Application.Close() instead.
Re: Motion Detector.NET - detects movement inside a webcam's field of view.
Okay, I made some changes to the code. Thanks for the comments. If you find anything else...