thanks for you fast reply.I guess only by capturing and analizing the sensor-data.
It is easy to detect the location of a bright spot in a image using BitmapCreator.what moves indicates position variables x and y
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private cv As B4XCanvas
Private bc As BitmapCreator
End Sub
Public Sub Initialize
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
cv.Initialize(Root)
Dim cvRect As B4XRect
cvRect.Initialize(0, 0, Root.Width, Root.Height)
bc.Initialize(cvRect.Width, cvRect.Height)
cv.DrawRect(cvRect, xui.Color_RGB(180, 180, 255), True, 0)
'Dim position() As Int = Array As Int(cvRect.centerX, cvRect.centerY) 'try different positions
'Dim position() As Int = Array As Int(120, 300)
Dim position() As Int = Array As Int(413, 150)
For i = 25 To 5 Step - 1
cv.DrawCircle(position(0), position(1), i, xui.Color_RGB(255 - 5 * i, 0, 0), True, 0)
Next
Dim xy() As Int = whereIsDot
Log("Center is at " & TAB & cvRect.CenterX & TAB & cvRect.CenterY)
Log("Dot is at " & TAB & xy(0) & TAB & xy(1))
End Sub
'I tweaked the color threshold, but you need to do it also for your situation
Private Sub whereIsDot As Int()
'Find centroid of all points matching color
bc.CopyPixelsFromBitmap(cv.CreateBitmap)
Dim Sumx, Sumy, N As Float
Dim arg As ARGBColor
For i = 0 To bc.mWidth - 1
For j = 0 To bc.mHeight - 1
bc.GetARGB(i, j, arg)
If arg.g < 200 And arg.b < 200 And arg.r > 200 Then
Sumx = Sumx + i
Sumy = Sumy + j
N = N + 1
End If
Next
Next
If N = 0 Then Return Array As Int(-1, -1) Else Return Array As Int(Ceil(Sumx / N), Ceil(Sumy / N)) '-1 is unknown
End Sub
really niceIt is a stormy day here and I have time on my hands. I did some time trials.
It took 11 milliseconds to find the red dot on a 600x600 screen. For 50 dots it took about 550 milliseconds.
The blue dots mark the path of the red dot. Run the attached to see the animation.
In real life the image is much more complicated but I would think that it would be easy to define what a red laser dot is.
I Googled, and RGB(237, 47, 50) seems to be accepted. Also, the image is probably compressed, that means that the edges of the dot are messy.
Using the centroid corrects for that.
View attachment 143698
ohhhhhhhhhhhh?
find Area in Image
Hello, im searching for a solution to find a given Area in an Image. I want to make screenshots and simulate Mousclicks on specific areas when something is found. the Area bitmap is fix in my assets, and i need the coordinates where this little Area image is shown in the screenshot. this area...www.b4x.com
it only works if the image to find in a picture is an exact copy of an Image available. Size, colors.ohhhhhhhhhhhh
Yes, I already understood, but I really liked the codeit only works if the image to find in a picture is an exact copy of an Image available. Size, colors.
I guess it will not work with a camerapicture showing a pointer on a wall. The pointyou see must be an exact copy of an image. Guess it will not work if the dimensions are not exact.
For this special case, if the first red pixel is found then exit the loop and only find other pixels in a small area around the first found pixel could be faster.It took 11 milliseconds to find the red dot on a 600x600 screen. For 50 dots it took about 550 milliseconds.