Z-Clive / aforge

Automatically exported from code.google.com/p/aforge
Other
0 stars 0 forks source link

Check if we need to use motionZones or not after we used them before. #59

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. MotionDetection Example
2. Open the MotionRegionsForm
3a. Add rectangles, remove them press OK
3b. Press ok without doing anything

What is the expected output? What do you see instead?

In Vision.Motion.CountingMotionDetector we check if we need to use
motionZones or not.
This is being done by checking if motionZones == null.
motionZones are initialised with a null, BUT:
if we want to set our motionZones, we can only set them with a Rectangle[],
not with a null.
So if we want to check if we use motionZones, AFTER we set it with an empty
Rectangle[] (because we don't need any motionZones anymore) we have a problem.

Vision.Motion.CountingMotionDetector

ProcessFrame

Replace:
if ((motionZones != null)||(motionZones == null))
Width:
if (((motionZones != null) && (motionZones.Length == 0))||(motionZones ==
null))
Why:
We can only update the motionZones with an Rectangle[].
So if we previously DID have motionzones, and later end up with no
motionZones, motionZones will be an empty Rectangle[] and not null.
We can check for that by checking it's lenght.

CreateMotionZoneFrame

Replace:
if ((motionZones == null) && (zonesFrame != IntPtr.Zero))
With:
if ((motionZones.Length == 0) && (zonesFrame != IntPtr.Zero))
why:
In CreateMotionZoneFrame we don't care if motionZones == null since if it's
null we won't have to free any motion zones anyway.
We DO want to free zones if our motionZones are made up from an empty
Rectangle[].

Just check it out by running your own MotionDetection Example, once your
MotionRegionsForm returns an empty Rectangle[], you have a problem ; )
(Add rectangles, remove them, press OK) or (Press ok right away)

What version of the product are you using? On what operating system?
1.6.2

Original issue reported on code.google.com by gjvantr...@gmail.com on 25 Mar 2008 at 11:30

GoogleCodeExporter commented 9 years ago

Original comment by andrew.k...@gmail.com on 13 May 2008 at 6:41

GoogleCodeExporter commented 9 years ago
Actually you are wrong. The MotionZones property can be easily set to null and 
this 
is what should be done to remove motion zones. It is not required to set the 
property with empty array. Need a C# book? :)

Added more checks to handle the case when user passes motion zones array with 0 
elements.

Committed in revision 476. Will be released in version 1.6.3

Original comment by andrew.k...@gmail.com on 18 May 2008 at 9:32

GoogleCodeExporter commented 9 years ago

Original comment by andrew.k...@gmail.com on 19 May 2008 at 6:01

GoogleCodeExporter commented 9 years ago

Original comment by andrew.k...@gmail.com on 19 May 2008 at 6:06