Hi all,
I wanted to do something like this : https://sites.google.com/site/todddanko/home/webcam_laser_ranger
I have thus added a small red laser under my phone and started to code an app.
Basically it works (or starts to work) but it is very very slow...
I am using the excellent @JordiCP camera NV21utils library to sample images, and this works quite fast.
The difficult task is to determine the dot position into the image.
The code is here :
It is based on getpixel function + "RGBToHSV"
And this is slow...
I attach to this thread the whole project.
It compiles and runs but slowly.
Any idea to access in a fast way to a rectagle into an image and to perform some RGB comparisons on pixels values ?
Thanks
I wanted to do something like this : https://sites.google.com/site/todddanko/home/webcam_laser_ranger
I have thus added a small red laser under my phone and started to code an app.
Basically it works (or starts to work) but it is very very slow...
I am using the excellent @JordiCP camera NV21utils library to sample images, and this works quite fast.
The difficult task is to determine the dot position into the image.
The code is here :
B4X:
Sub ComputeImage
Processing = True
Dim p() As Int
Dim r As Reflector
Dim h, s, v As Float
Dim HSV(3) As Float = Array As Float(h, s, v)
Dim found As Boolean = False
Dim i, j As Int
found = False
Try
For j = Ylaser -10 To Ylaser+10
Log("ligne " & j)
DoEvents
'
p = getPixels(myBitmap, 0, 0, myBitmap.Width/2, j , myBitmap.Width/2, 1)
For i = 0 To myBitmap.Width/2-1
MyColor = GetARGB(p(i))
If (MyColor(1) > 250) Then
r.RunStaticMethod("android.graphics.Color", "RGBToHSV", Array As Object(MyColor(1), MyColor(2), MyColor(3), HSV), Array As String("java.lang.int", "java.lang.int", "java.lang.int", "[F"))
If (HSV(0) > 320) Then 'And (HSV(2) > 60)Then
LbFps.Text = i & HSV(0) & " " & HSV(2)
LbFps.Color = p(i)
found = True
Log("found")
End If
End If
If found = True Then Exit
Next
If found = True Then Exit
'DoEvents
Next
Catch
Log("error " & LastException.Message)
End Try
Processing = False
End Sub
It is based on getpixel function + "RGBToHSV"
B4X:
Sub getPixels(bmp As Bitmap, offset As Int, stride As Int, x As Int, y As Int, width As Int, height As Int) As Int()
Try
Dim jo = bmp As JavaObject
Dim pixels(width * height) As Int
jo.RunMethod("getPixels", Array As Object(pixels, offset, width, x, y, width, height))
Return pixels
Catch
Return Null
End Try
End Sub
And this is slow...
I attach to this thread the whole project.
It compiles and runs but slowly.
Any idea to access in a fast way to a rectagle into an image and to perform some RGB comparisons on pixels values ?
Thanks
Attachments
Last edited: