VideoCap Pro SDK ActiveX

VideoCap Pro SDK ActiveX 15.5

Platform : Windows 10, Windows 8, Vista, Windows 7, XP

For Windows Developers who need to view IP Camera, add video capture with overlay text, image, chroma key effect, face detection, motion detection with C++ , C#, VB.NET , VB, Delphi, Vfp, Ms Access, Labview.

VB.NET - How to motion detection for any object

Step 1: To install the VideoCap Pro ActiveX Control, begin by launching the setup file (http://www.viscomsoft.com/demo/videocapprosetup.exe). Select the desired installation folder for the VideoCap Pro ActiveX and continue with the installation on your development computer.

Step 2: Create New Visual Basic Project, select Windows Application. 

Step 3: The next step is to install VideoCap Pro ActiveX in ToolBox. Select Toolbox, select Components item, right click mouse button, select Choose Items...

Step 4: Select COM Components tab, select VideoCap Pro Control , click OK.

Step 5: Now you will see the VideoCap Pro ActiveX's icon on toolbox, drag it to form.

Step 6: Create the UI like the following screen. 3 combo box, one button , one listbox and 5 label control.

 

Step 7: In form load event, add the following code

       For i = 1 To 100

            cbosen.Items.Add(i.ToString())

        Next

        cbosen.SelectedIndex = 50

        For i = 0 To AxVideoCap1.GetDeviceCount - 1

            cbovideodevice.Items.Add(AxVideoCap1.GetDeviceName(i))

        Next

        If cbovideodevice.Items.Count > 0 Then

            cbovideodevice.SelectedIndex = 0

        End If


        For i = 0 To AxVideoCap1.GetVideoFormatCount - 1

            cbovideoformat.Items.Add(AxVideoCap1.GetVideoFormatName(i))

        Next

        If cbovideoformat.Items.Count > 0 Then

            cbovideoformat.SelectedIndex = 0

        End If

Step 8: In Start button click event , add the following code

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

        AxVideoCap1.Device = cbovideodevice.SelectedIndex

        AxVideoCap1.VideoFormat = cbovideoformat.SelectedIndex

        AxVideoCap1.EffectType = VIDEOCAPLib.MYVIDEOCAPEFFECTTYPE.MOTIONDETECTION

        AxVideoCap1.EffectMotionSensitivity = 50

        AxVideoCap1.Start()

 

End Sub

Step 9: declare public iCount integer variable 

Public Class Form1

    Dim iCount As Integer

Step 10: Select VideoCap Pro ActiveX on form, In Properties window, select Events, add MotionDetected event hander. In this handler add the following code.

  Private Sub AxVideoCap1_MotionDetected(sender As System.Object, e As AxVIDEOCAPLib._DVideoCapEvents_MotionDetectedEvent) Handles AxVideoCap1.MotionDetected

        ListBox1.Items.Add("Motion Detected at " e.iLeft.ToString " " e.iTop.ToString() " " e.iwidth.ToString() " " e.iheight.ToString() " Sensitivity " e.iSensitivity.ToString)

        If ListBox1.Items.Count > 0 Then

            lbleventcount.Text = ListBox1.Items.Count

            ListBox1.SelectedIndex = ListBox1.Items.Count - 1

            iCount = iCount 1

        End If

    End Sub

Step 11: Run the project, click the Start button, left click the mouse on preview video window, you may adjust the selection rectangle on your object.
In list box, you will see the selection rectangle size.

In this sample, the selection rectangle position is 352, 243, 155, 176

Step 12:  In Start button click event , update the following code , now it will selected the bear for motion detection

 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        AxVideoCap1.Device = cbovideodevice.SelectedIndex
        AxVideoCap1.VideoFormat = cbovideoformat.SelectedIndex
        AxVideoCap1.EffectType = VIDEOCAPLib.MYVIDEOCAPEFFECTTYPE.MOTIONDETECTION
        AxVideoCap1.EffectMotionSensitivity = 50
        AxVideoCap1.Start()
        AxVideoCap1.EffectMotionSetDetectedRect(352, 243, 155, 176)
    End Sub

Step 13: Now we want to snapshot the images when someone want to get the bear.  so you need declare public dir string variable
Public Class Form1

    Dim iCount As Integer

    Dim dir As String 

Step 14: In form load event, update the following code, we will create Motion Detection Sample folder and stored the image in this folder.

 Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        dir = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)

        dir = System.IO.Path.Combine(dir, "Motion Detection Sample")

        If Not System.IO.Directory.Exists(dir) Then

            System.IO.Directory.CreateDirectory(dir)

        End If

 

        iCount = 0

        For i = 1 To 100

            cbosen.Items.Add(i.ToString())

        Next

 

        cbosen.SelectedIndex = 50

        For i = 0 To AxVideoCap1.GetDeviceCount - 1

            cbovideodevice.Items.Add(AxVideoCap1.GetDeviceName(i))

        Next

        If cbovideodevice.Items.Count > 0 Then

            cbovideodevice.SelectedIndex = 0

        End If


        For i = 0 To AxVideoCap1.GetVideoFormatCount - 1

            cbovideoformat.Items.Add(AxVideoCap1.GetVideoFormatName(i))

        Next

        If cbovideoformat.Items.Count > 0 Then

            cbovideoformat.SelectedIndex = 0

        End If

 

    End Sub

Step 15: update the code in MotionDetected event hander. When motion detected, it will save to JPG file.

  Private Sub AxVideoCap1_MotionDetected(sender As System.Object, e As AxVIDEOCAPLib._DVideoCapEvents_MotionDetectedEvent) Handles AxVideoCap1.MotionDetected

        Dim strSnapshotFileName As String

        ListBox1.Items.Add("Motion Detected at " e.iLeft.ToString " " e.iTop.ToString() " " e.iwidth.ToString() " " e.iheight.ToString() " Sensitivity " e.iSensitivity.ToString)

        If ListBox1.Items.Count > 0 Then

            lbleventcount.Text = ListBox1.Items.Count

            ListBox1.SelectedIndex = ListBox1.Items.Count - 1

            strSnapshotFileName = dir "\" DateTime.Now.ToString("yyyy-MM-dd-HH-mm-0ss") ".jpg"

            AxVideoCap1.SnapShotJPEG(strSnapshotFileName, 99)

            iCount = iCount 1

        End If

 

    End Sub

Download the source code of the Motion Detection Sample