|
-
Jul 29th, 2009, 06:17 AM
#1
Thread Starter
Lively Member
Exit a sub problem
Hi again, 
i have a sub that every time it detects a motion a beep sounds. Because is a pixel to pixel comparison i didn`t find a way to stop the sub at the very first motion detection so i can prompt just one msgbox.
If i type the msgbox just like that in the sub every time it detects motion it prompts a new msgbox filling the screen.
Any suggestions?
Thanks
-
Jul 29th, 2009, 06:22 AM
#2
Re: Exit a sub problem
You havent really given enough detail but can you not just do this when you find that a pixel has changed?
or if you are comparing the pixels in a FOR loop of some sort then:
If thats not helpful then you need to explain what exactly you are doing with this pixel by pixel comparison
-
Jul 29th, 2009, 09:14 AM
#3
Thread Starter
Lively Member
Re: Exit a sub problem
Basically i`m comparing the three basic colors (RGB). Now i want for the first time of motion detection to exit this loop so i can prompt an msgbox!
If FirstFrame.GetPixel(x, y).R >= SecondFrame.GetPixel(x, y).R - Sensitivity And FirstFrame.GetPixel(x, y).R <= SecondFrame.GetPixel(x, y).R + Sensitivity Then
If FirstFrame.GetPixel(x, y).G >= SecondFrame.GetPixel(x, y).G - Sensitivity And FirstFrame.GetPixel(x, y).G <= SecondFrame.GetPixel(x, y).G + Sensitivity Then
If FirstFrame.GetPixel(x, y).B >= SecondFrame.GetPixel(x, y).B - Sensitivity And FirstFrame.GetPixel(x, y).B <= SecondFrame.GetPixel(x, y).B + Sensitivity Then
' well erm do nothing
Else
are_identical = False
End If
Else
are_identical = False
End If
Else
are_identical = False
-
Jul 29th, 2009, 09:38 AM
#4
Re: Exit a sub problem
The first thing to note is the inefficiency of that code. GetPixel is slow and you're calling GetPixel on the same two cootdinates six times each. That's not good. You should be calling GetPixel once for each frame. You then just need one If block, not three:
vb.net Code:
Dim firstColour As Color = firstFrame.GetPixel(x, y) Dim secondColour As Color = secondFrame.GetPixel(x, y) If firstColour.R < secondColour.R - sensitivity OrElse _ firstColour.R > secondColour.R + sensitivity OrElse _ firstColour.G < secondColour.G - sensitivity OrElse _ firstColour.G > secondColour.G + sensitivity OrElse _ firstColour.B < secondColour.B - sensitivity OrElse _ firstColour.B > secondColour.B + sensitivity Then areIdentical = False End If
In fact, you don't need any If blocks at all:
vb.net Code:
Dim firstColour As Color = firstFrame.GetPixel(x, y) Dim secondColour As Color = secondFrame.GetPixel(x, y) areIdentical = firstColour.R >= secondColour.R - sensitivity AndAlso _ firstColour.R <= secondColour.R + sensitivity AndAlso _ firstColour.G >= secondColour.G - sensitivity AndAlso _ firstColour.G <= secondColour.G + sensitivity AndAlso _ firstColour.B >= secondColour.B - sensitivity AndAlso _ firstColour.B <= secondColour.B + sensitivity
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
|