#Region Project Attributes
#ApplicationLabel: OCV VideoCapture
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: landscape
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim t As Timer
Dim VIDEO_SRC As String = "myvideo9.avi" 'Has to be MJPEG encoded.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim ocl As OCVOpenCVLoader
Dim mCore As OCVCore
Dim mImgProc As OCVImgproc
Dim MyMatBGR As OCVMat
Dim mVideoCapture As OCVVideoCapture
Dim myVideoCaptureMat As OCVMat
Dim myVideoCaptureBitmap As Bitmap
Dim capturing As Boolean=False
Dim P As Panel
Dim btnStartStop As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
' As it is a demo, set everything to 640X480, since we know the video has that size
P.Initialize("")
Dim HH As Int = 80%Y
Dim WW As Int = HH*640/480 'Keep aspect ratio for this example.
Activity.AddView(P,(100%X-WW)/2,(100%Y-HH)/2,WW,HH) ' Center screen
myVideoCaptureBitmap.InitializeMutable(640,480)
P.SetBackgroundImage(myVideoCaptureBitmap)
'Control Button
btnStartStop.Initialize("btnStartStop")
btnStartStop.Text="Start"
Activity.AddView(btnStartStop,20dip,20dip,80dip,40dip)
t.Initialize("t",500)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
capturing=False
mVideoCapture.release
t.Enabled=False
Activity.Finish
End Sub
Sub btnStartStop_Click
If Not(capturing) Then
InitVideoCapture
Else
mVideoCapture.release
btnStartStop.text="Start"
t.Enabled=False
capturing=False
End If
End Sub
Sub t_tick
If Not(t.Enabled) Then Return 'just in case it was a pending event
If Not(capturing) Then Return
Log("Tick")
If mVideoCapture.isOpened Then
If (mVideoCapture.read(myVideoCaptureMat)) Then
If Not(myVideoCaptureMat.empty) Then 'really needed? should test
'From https://github.com/opencv/opencv/issues/4974
'// get some meta data about frame.
'double fps = capture.get(Videoio.CAP_PROP_FPS);
'double frameCount = capture.get(Videoio.CAP_PROP_FRAME_COUNT);
'double h = capture.get(Videoio.CAP_PROP_FRAME_HEIGHT);
'double w = capture.get(Videoio.CAP_PROP_FRAME_WIDTH);
'double posFrames = capture.get(Videoio.CAP_PROP_POS_FRAMES);
'double posMsec = capture.get(Videoio.CAP_PROP_POS_MSEC);
'double speed = capture.get(Videoio.CAP_PROP_SPEED);
Log("mVideoCapture has read!" & myVideoCaptureMat.rows &" "&myVideoCaptureMat.cols)
Dim mUtils As OCVUtils
mUtils.matToBitmap(myVideoCaptureMat, myVideoCaptureBitmap,False)
P.Invalidate
End If
End If
Else
Log("mVideoCapture is not open")
End If
End Sub
Sub InitVideoCapture
mVideoCapture.Initialize1(File.Combine(File.DirRootExternal,VIDEO_SRC),0)
If mVideoCapture.isOpened Then
Log("VideoCapture file correctly opened")
t.Enabled=True
capturing=True
btnStartStop.Text = "Stop"
Else
ToastMessageShow("VideoCapture failed to open.",True)
capturing=False
btnStartStop.Enabled = False
End If
End Sub