Make an ARC Skill

Example: Camera Custom Tracking Type

As you've seen in the previous tutorial step about detecting and attaching to the camera, there are a bunch of events that you can use. One of the events allows you to create a custom tracking type as a plugin, which is real cool!

Uses for creating a custom tracking type is if you want to experiment with OpenCV or any other vision libraries. Because ARC leverages .Net, we recommend the x86 nuget install of EMGUCV (https://github.com/emgucv/emgucv). Installing from NUGET is the easiest and most convenient.

The camera events that we'll use for creating a custom tracking type are...


        // assign an event that raises when the camera wants to initialize tracking types
        _camera.Camera.OnInitCustomTracking += Camera_OnInitCustomTracking;

        // assign an event that raises with a new frame that you can use for tracking
        _camera.OnCustomDetection += Camera_OnCustomDetection;

Once inside the OnCustomDetection() event, you have access to a bunch of different bitmaps throughout the flow of the detection process. They are...


// **********************
// From the EZ_B.Camera class
// **********************

    /// 
    /// This is a temporary bitmap that we can use to draw on but is lost per tracking type
    /// 
    public volatile Bitmap _WorkerBitmap;

    /// 
    /// This is the resized original bitmap that is never drawn on. Each tracking type uses this as the main source image for tracking, and then draws on the _OutputBitmap for tracking details
    /// 
    public volatile AForge.Imaging.UnmanagedImage _OriginalBitmap; // resized image that we process

    /// 
    /// Image that is outputted to the display. We draw on this bitmap with the tracking details
    /// 
    public volatile AForge.Imaging.UnmanagedImage _OutputBitmap;

    /// 
    /// Raw image unsized directly from the input device
    /// 
    public volatile AForge.Imaging.UnmanagedImage _RawUnsizedBitmap;

    /// 
    /// Last image for the GetCurrentImage 
    /// 
    public volatile AForge.Imaging.UnmanagedImage _RawUnsizedLastBitmap;

Understanding the images available, the ones we care about for creating a tracking type of our own are...


    /// 
    /// This is the resized original bitmap that is never drawn on. Each tracking type uses this as the main source image for tracking, and then draws on the _OutputBitmap for tracking details
    /// 
    public volatile AForge.Imaging.UnmanagedImage _OriginalBitmap; // resized image that we process

    /// 
    /// Image that is outputted to the display. We draw on this bitmap with the tracking details
    /// 
    public volatile AForge.Imaging.UnmanagedImage _OutputBitmap;

This is because we can use the _OriginalBitmap for our detection, and then draw on the _OutputBitmap where our detection was.

Example This is an example that fakes detection by drawing a rectangle on the _OutputBitmap that bounces around the screen. It moves with every frame in the CustomDetection event.


    // faking an object being tracked
    int _xPos = 0;
    int _yPos = 0;
    bool _xDir = true;
    bool _yDir = true;

    private EZ_B.ObjectLocation[] Camera_OnCustomDetection(EZ_Builder.UCForms.FormCameraDevice sender) {

      if (_isClosing)
        return new ObjectLocation[] { };

      if (!_camera.Camera.IsActive)
        return new ObjectLocation[] { };

      List objectLocations = new List();

      try {

        // This is demonstrating how you can return if an object has been detected and draw where it is
        // The camera control will start tracking when more than one ObjectLocation is returned
        // We're just putting fake bouncing rectable of a detected rect which will be displayed as a tracked object on the screen in the camera device

        if (_xDir)
          _xPos += 10;
        else
          _xPos -= 10;

        if (_yDir)
          _yPos += 10;
        else
          _yPos -= 10;

        var r = new Rectangle(_xPos, _yPos, 50, 50);

        if (r.Right > _camera.Camera._OutputBitmap.Width)
          _xDir = false;
        else if (r.Left  _camera.Camera._OutputBitmap.Height)
          _yDir = false;
        else if (r.Top <= 0)
          _yDir = true;

        var objectLocation = new ObjectLocation(ObjectLocation.TrackingTypeEnum.Custom);
        objectLocation.Rect = r;
        objectLocation.HorizontalLocation = _camera.Camera.GetHorizontalLocation(objectLocation.CenterX);
        objectLocation.VerticalLocation = _camera.Camera.GetVerticalLocation(objectLocation.CenterY);
        objectLocations.Add(objectLocation);

        AForge.Imaging.Drawing.Rectangle(_camera.Camera._OutputBitmap, r, Color.MediumSeaGreen);
      } catch (Exception ex) {

        EZ_Builder.EZBManager.Log(ex);
      }

      return objectLocations.ToArray();
    }


ARC Pro

Upgrade to ARC Pro

Subscribe to ARC Pro, and your robot will become a canvas for your imagination, limited only by your creativity.

#17  

The error cannot read the COM file, I downloaded it and when I follow the instructions, I get an error, while other files read normally. .

User-inserted image

#18   — Edited

sorry for me but i tried many different ways but still show the error,I couldn't find EZ_B.dll file even though I downloaded it

PRO
Synthiam
#19  

None of the required references are in your list. Please follow the tutorial. It explains exactly how to click the browse button and navigate to the folder and select the files.

#20  

Sorry, but the reason I can't reference is because there is no file in the EZ_B folder and there is an error : this folder is empty , I am trying to solve it. I would like to thank DJ sure for answering my superfluous questions and I'm sorry for bothering you

Australia
#21   — Edited

I need to playback 5 Serial Bus servos in sequence.

PRO
Synthiam
#22   — Edited

What protocol is it? A "serial bus" is a generic term for anything using a UART that's chained together sharing the same RX line. Also, why did you add a photo with the question text added in your response?

Are you planning on making a skill control to do this? You wrote the question in the skill control thread in a comment - I'd like to make sure your question is in the right place to help you out.

To begin, I would recommend starting with servo Script control so you can make the serial bus protocol work - then consider making a skill control only if you're planning on distributing the effort to others: https://synthiam.com/Products/Controls/Scripting/Servo-Script-19068

#23  

He seems rather demanding as well.  I guess he needs the benefit of the doubt as English may not be his native language....

#24   — Edited

I have installed all the software dependencies and still ARC does not detect that I have Visual Studio installed. OS is Windows 10, .NET 4.8 or newer, Visual Studio Community 2019.