Canada
Asked — Edited

Has Anyone Connected To Camera Using Visual Basic?

I was wondering if anyone has connected to the video camera using ez_B.dll from visual basic? I'd like to see a tutorial using the same method as was used in the tutorial for connecting to the servo via ez_B and Visual Basic.

Also, was wondering if anyone has tried to build a .BAS (visual basic module) for the ez_B functions so that the functions can be called from old versions of basic such as VB6?


ARC Pro

Upgrade to ARC Pro

Become a Synthiam ARC Pro subscriber to unleash the power of easy and powerful robot programming

PRO
Synthiam
#1  

You can easily convert the C# examples to VB. Here is the C# Example converted to a VB: VB-Tutorial03-Camera.zip

For example, here is what the C# looks like...


using System;
using System.Diagnostics;
using System.Windows.Forms;
using EZ_B;
using EZ_B.CameraDetection;

namespace Tutorial_11___Follow_Red_Object {

  public partial class Form1 : Form {

    Camera    _camera;

    public Form1() {

      InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e) {

      _camera = new Camera(ezB_Connect1.EZB);

      comboBox1.Items.Clear();
      comboBox1.Items.AddRange(Camera.GetVideoCaptureDeviceList());

      comboBox3.Items.Clear();
      foreach (ColorDetection.ColorEnum item in Enum.GetValues(typeof(ColorDetection.ColorEnum)))
        comboBox3.Items.Add(item);

      comboBox3.SelectedIndex = 0;

      timer1.Interval = 100;
      timer1.Enabled = true;
    }

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {

      string videoCaptureDeviceName = comboBox1.SelectedItem.ToString();

      _camera.StartCamera(videoCaptureDeviceName, panel1, panel2, 160, 120);

      Log("Video started: {0}", videoCaptureDeviceName);
    }

    private void Log(object txt, params object[] values) {

      tbLog.AppendText(string.Format(txt.ToString(), values));
      tbLog.AppendText(Environment.NewLine);
    }

    private void timer1_Tick(object sender, EventArgs e) {

      if (!_camera.IsActive)
        return;

      ObjectLocation objectLocation = _camera.CameraBasicColorDetection.GetObjectLocationByColor((ColorDetection.ColorEnum)comboBox3.SelectedItem, tbMinObjectSize.Value, (byte)tbBrightness.Value);
      //ObjectLocation objectLocation = _camera.CameraFaceDetection.GetFaceDetection();
      //ObjectLocation objectLocation = _camera.CameraMotionDetection.GetMotionDetection(30, 80);
      //ObjectLocation objectLocation = _camera.CameraShapeDetection.GetShapeDetection();

      _camera.UpdatePreview();

      if (!objectLocation.isFound)
        return;

      if (ezB_Connect1.EZB.IsConnected) {

        int position = ezB_Connect1.EZB.Servo.GetServoPosition(Servo.ServoPortEnum.D12);

        if (objectLocation.horizontalLocation == ObjectLocation.HorizontalLocationEnum.Left)
          position++;
        else if (objectLocation.horizontalLocation == ObjectLocation.HorizontalLocationEnum.Right)
          position--;

        ezB_Connect1.EZB.Servo.SetServoPosition(Servo.ServoPortEnum.D12, position);
      }

      Log("Object found at {0} {1}", objectLocation.horizontalLocation, objectLocation.verticalLocation);
    }
  }
}

And here is the project in VB


Imports EZ_B
Imports EZ_B.CameraDetection
Imports System

Public Class Form1

    Private _camera As Camera

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

        _camera = New Camera(EzB_Connect1.EZB)

        comboBox1.Items.Clear()
        comboBox1.Items.AddRange(Camera.GetVideoCaptureDeviceList())

        comboBox3.Items.Clear()
        For Each item As ColorDetection.ColorEnum In [Enum].GetValues(GetType(ColorDetection.ColorEnum))
            comboBox3.Items.Add(item)
        Next

        comboBox3.SelectedIndex = 0

        Timer1.Interval = 100
        Timer1.Enabled = True
    End Sub

    Private Sub comboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles comboBox1.SelectedIndexChanged

        Dim videoCaptureDeviceName As String = comboBox1.SelectedItem.ToString()

        _camera.StartCamera(videoCaptureDeviceName, panel1, panel2, 160, 120)

        Log("Video started: {0}", videoCaptureDeviceName)
    End Sub

    Private Sub Log(txt As Object, ParamArray values() As Object)

        tbLog.AppendText(String.Format(txt.ToString(), values))
        tbLog.AppendText(Environment.NewLine)
    End Sub


    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick

        If (_camera.IsActive = False) Then
            Return
        End If

        Dim objectLocation As ObjectLocation

        ' Uncomment the type of tracking you wish to use
        'objectLocation = _camera.CameraBasicColorDetection.GetObjectLocationByColor(comboBox3.SelectedItem, tbMinObjectSize.Value, tbBrightness.Value)
        objectLocation = _camera.CameraFaceDetection.GetFaceDetection()
        'objectLocation = _camera.CameraMotionDetection.GetMotionDetection(30, 80)
        'objectLocation = _camera.CameraShapeDetection.GetShapeDetection()

        _camera.UpdatePreview()

        If (ObjectLocation.isFound = False) Then
            Return
        End If

        If (EzB_Connect1.EZB.IsConnected) Then

            Dim position As Integer = EzB_Connect1.EZB.Servo.GetServoPosition(Servo.ServoPortEnum.D12)

            If (ObjectLocation.horizontalLocation = ObjectLocation.HorizontalLocationEnum.Left) Then
                position = position + 1
            ElseIf (ObjectLocation.horizontalLocation = ObjectLocation.HorizontalLocationEnum.Right) Then
                position = position - 1
            End If

            EzB_Connect1.EZB.Servo.SetServoPosition(Servo.ServoPortEnum.D12, position)
        End If

        Log("Object found at {0} {1}", objectLocation.horizontalLocation, objectLocation.verticalLocation)
    End Sub
End Class

Canada
#2  

Started New Project: Visual Studio Pro 2012: windows form application

1: I set the CPU to x86 (BUILD..configuration_manager.) 2: Added EZB.DLL 3: added 3 combo boxes,2 timers to form1 4:added ALL of the EZB controls to the form,including videoplayer Getting a bunch of errors..and mytoolbar disapeared

ERROR in following line of code: 5:_camera = New Camera(EzB_Connect1.EZB) ' _camera = New Camera(EzB_Connect1.EZB)

Error 1 Argument not specified for parameter 'captureHeight' of 'Public Sub New(ezb As EZ_B.EZB, captureWidth As Integer, captureHeight As Integer)'. C:\Users\ANDY\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb 13 19 WindowsApplication1

Error 2 Argument not specified for parameter 'captureWidth' of 'Public Sub New(ezb As EZ_B.EZB, captureWidth As Integer, captureHeight As Integer)'. C:\Users\ANDY\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb 13 19 WindowsApplication1

Error 3 Line continuation character '_' must be preceded by at least one white space and must be the last character on the line. C:\Users\ANDY\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb 16 69 WindowsApplication1

Error 4 'panel1' is not declared. It may be inaccessible due to its protection level. C:\Users\ANDY\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb 33 53 WindowsApplication1

Error 5 'panel2' is not declared. It may be inaccessible due to its protection level. C:\Users\ANDY\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb 33 61 WindowsApplication1

PRO
Synthiam
#3  

Please re-read my message. Download the VB example here: VB Tutorial 03 Camera

For more information on using Visual Basic, check for online tutorials and classes. You may also check your local schools for night courses on introduction to programming.

My suggestion is to use ARC, then you can migrate to Visual Studio development. By then, you will probably wish to use C# because it is much easier than Visual Basic actually:)

Canada
#4  

Hi DJ. Thanks for the speedy reply. I already am using ARC, I recently purchased VS 2012. I used to do a lot of VB6 enterprise programming using the API.(hobby) Did a lot of winsockDLL programming and also using ip/worksV4 which are activeX controls that will let you build a TCP/ip server(daemon)((up to 1000 connections) in about 30 mins. in VB and a tcp/ip client in 10 mins

I also used wsock.bas in my vb programs...

I'm planning of learning VB.net and then go on the VC#. I'm able to add all of the ip/works DLL's to VB2012 including Telnet.ocx,daemon.tcpclient,ftpserver and client,udp etc...

So, I'm experimenting : got the VB servos going, want to get the vb camera going...then maybe GPS...but one thing at a time.

I'd also like to try and build an app using vb6 and EZB.bas.avicap32.dll.

I really like it if you could add a step by step tutorial for VB camera as you did with the VB servo control.(that was great.)

Thanks

PRO
Synthiam
#5  

Bobot, sounds great!

Again - I really need you to read my replies:) I have included a link twice to download an entire example VB Camera project.:) exactly what you're asking for

Canada
#6  

Here's what going on..

1: Created new project in VB2012(vs2012).Windows form application. 2:select x86 CPU from BUILD-configuarton manager 3.Add EZB to toolbox.

4:ADD all of the EZB controls to form1 5:ADD 3 combo boxes and 2 timer controls to form1

getting errors when I run the app or build.

Canada
#7  

The controls aren't being loaded into the application...probably because when I unzip the tutorial the application looks for them somewhere other than where I unzipped them..