|
-
Aug 12th, 2014, 07:25 AM
#1
Thread Starter
Frenzied Member
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.
Last edited by Peter Swinkels; Mar 2nd, 2015 at 09:57 AM.
-
Aug 14th, 2014, 02:45 PM
#2
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
-
Aug 15th, 2014, 07:06 AM
#3
Thread Starter
Frenzied Member
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.
Last edited by Peter Swinkels; Feb 13th, 2015 at 04:52 AM.
-
Aug 15th, 2014, 08:19 AM
#4
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.
-
Aug 15th, 2014, 08:47 AM
#5
Re: Motion Detector.NET - detects movement inside a webcam's field of view.
 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.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Aug 15th, 2014, 01:28 PM
#6
Thread Starter
Frenzied Member
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...
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|