Sub OpenCamera (front As Boolean)
'Camera Version: 1.30
rp.CheckAndRequest(rp.PERMISSION_CAMERA)
Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
If Result = False Then
ToastMessageShow("No permission!", True)
Return
End If
Wait For (cam.OpenCamera(front)) Complete (TaskIndex As Int)
If TaskIndex > 0 Then
MyTaskIndex = TaskIndex 'hold this index. It will be required in later calls.
Wait For(PrepareSurface) Complete (Success As Boolean)
If Success = True Then
t.Enabled = True
End If
End If
Log("Start success: " & Success)
If Success = False Then
ToastMessageShow("Failed to open camera", True)
End If
End Sub
Sub t_tick
Dim mbm As Bitmap
Dim myMat,imgmat As OCVMat
mbm = cam.GetPreviewBitmap(480,640)
' Log(cam.PreviewSize.Height& " " & cam.PreviewSize.Width)
mbm.InitializeMutable(480,640)
mUtils.bitmapToMat(mbm,imgmat,True)
myMat = imgmat.clone
Dim cs As OCVScalar
cs.Initialize3(0,0,255)
Dim w As Int = myMat.width
Dim h As Int = myMat.height
Dim start As OCVPoint
start.Set(Array As Double(w * 1 / 3, h * 1 / 3))
Dim finish As OCVPoint
finish.Set(Array As Double(w * 2 / 3, h * 2 / 3 ))
mImgProc.rectangle1(myMat,start, finish,cs,5)
End Sub