<commit_before>﻿using Bonsai;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Text;
using OpenCV.Net;
using System.ComponentModel;
using System.Drawing.Design;
using Cmt.Net;
using Bonsai.Vision;

namespace Bonsai.Cmt
{
    public class CmtTracker : Transform<IplImage, ConnectedComponent>
    {
        public bool EstimateRotation { get; set; }

        public bool EstimateScale { get; set; }

        [Description("The region of interest inside the input image.")]
        [Editor("Bonsai.Vision.Design.IplImageInputRectangleEditor, Bonsai.Vision.Design", typeof(UITypeEditor))]
        public Rect RegionOfInterest { get; set; }

        public override IObservable<ConnectedComponent> Process(IObservable<IplImage> source)
        {
            return Observable.Defer(() =>
            {
                var tracker = new TrackerCmt();
                var inputRoi = new Rect();
                var initialized = false;
                return source.Select(input =>
                {
                    tracker.EstimateRotation = EstimateRotation;
                    tracker.EstimateScale = EstimateScale;
                    if (inputRoi != RegionOfInterest)
                    {
                        inputRoi = RegionOfInterest;
                        tracker.Initialize(input, inputRoi);
                        initialized = true;
                    }

                    var component = new ConnectedComponent();
                    if (initialized)
                    {
                        tracker.ProcessFrame(input);
                        var boundingBox = tracker.BoundingBox;
                        component.Centroid = boundingBox.Center;
                        var boundingContour = new RectangleContour(boundingBox, input.Size);
                        if (!float.IsNaN(boundingBox.Center.X) &&
                            boundingContour.Rect.Width > 0 &&
                            boundingContour.Rect.Height > 0)
                        {
                            component.Area = boundingBox.Size.Width * boundingBox.Size.Height;
                            component.Orientation = boundingBox.Angle * Math.PI / 180f;
                            component.Contour = new RectangleContour(boundingBox, input.Size);
                            component.Patch = input.GetSubRect(component.Contour.Rect);
                            component.MajorAxisLength = 0;
                            component.MinorAxisLength = 0;
                        }
                        else component.Orientation = double.NaN;
                    }
                    return component;
                });
            });
        }
    }
}
<commit_msg>Added missing description metadata to tracker plugin.<commit_after>﻿using Bonsai;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Text;
using OpenCV.Net;
using System.ComponentModel;
using System.Drawing.Design;
using Cmt.Net;
using Bonsai.Vision;

namespace Bonsai.Cmt
{
    [Description("Tracks a specified object over time using the self-supervised CMT algorithm.")]
    public class CmtTracker : Transform<IplImage, ConnectedComponent>
    {
        [Description("Indicates whether to estimate the rotation of the object.")]
        public bool EstimateRotation { get; set; }

        [Description("Indicates whether to estimate the scale of the object.")]
        public bool EstimateScale { get; set; }

        [Description("The region of interest to track inside the input image.")]
        [Editor("Bonsai.Vision.Design.IplImageInputRectangleEditor, Bonsai.Vision.Design", typeof(UITypeEditor))]
        public Rect RegionOfInterest { get; set; }

        public override IObservable<ConnectedComponent> Process(IObservable<IplImage> source)
        {
            return Observable.Defer(() =>
            {
                var tracker = new TrackerCmt();
                var inputRoi = new Rect();
                var initialized = false;
                return source.Select(input =>
                {
                    tracker.EstimateRotation = EstimateRotation;
                    tracker.EstimateScale = EstimateScale;
                    if (inputRoi != RegionOfInterest)
                    {
                        inputRoi = RegionOfInterest;
                        tracker.Initialize(input, inputRoi);
                        initialized = true;
                    }

                    var component = new ConnectedComponent();
                    if (initialized)
                    {
                        tracker.ProcessFrame(input);
                        var boundingBox = tracker.BoundingBox;
                        component.Centroid = boundingBox.Center;
                        var boundingContour = new RectangleContour(boundingBox, input.Size);
                        if (!float.IsNaN(boundingBox.Center.X) &&
                            boundingContour.Rect.Width > 0 &&
                            boundingContour.Rect.Height > 0)
                        {
                            component.Area = boundingBox.Size.Width * boundingBox.Size.Height;
                            component.Orientation = boundingBox.Angle * Math.PI / 180f;
                            component.Contour = new RectangleContour(boundingBox, input.Size);
                            component.Patch = input.GetSubRect(component.Contour.Rect);
                            component.MajorAxisLength = 0;
                            component.MinorAxisLength = 0;
                        }
                        else component.Orientation = double.NaN;
                    }
                    return component;
                });
            });
        }
    }
}

{'fraction_non_alphanumeric': 0.07746721877156659, 'fraction_numerical': 0.0024154589371980675, 'mean_word_length': 1.4741784037558685, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5489925', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1328, 'n_words': 303}