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