Item Item(YoloTrackingItem yoloTrackingItem)
        {
            Item item = new Item(yoloTrackingItem.X, yoloTrackingItem.Y, yoloTrackingItem.Width, yoloTrackingItem.Height,
                                 yoloTrackingItem.ObjId, yoloTrackingItem.Type, yoloTrackingItem.Confidence, 0, "");

            item.TrackId          = yoloTrackingItem.TrackId;
            item.Index            = yoloTrackingItem.Index;
            item.TaggedImageData  = yoloTrackingItem.TaggedImageData;
            item.CroppedImageData = yoloTrackingItem.CroppedImageData;

            return(item);
        }
Example #2
0
        public IEnumerable <YoloTrackingItem> Analyse(IEnumerable <YoloItem> items)
        {
            _processIndex++;

            if (_trackingItems.Count == 0)
            {
                foreach (var item in items)
                {
                    var trackingItem = new YoloTrackingItemExtended(item, GetObjectId());
                    _trackingItems.Add(trackingItem.ObjectId, trackingItem);
                }

                return(new YoloTrackingItem[0]);
            }

            var trackingItems = new List <YoloTrackingItem>();

            foreach (var item in items)
            {
                var bestMatch = _trackingItems.Values.Select(o => new
                {
                    Item = o,
                    DistancePercentage = DistancePercentage(o.Center(), item.Center()),
                    SizeDifference     = GetSizeDifferencePercentage(o, item)
                })
                                .Where(o => !trackingItems.Select(x => x.ObjectId).Contains(o.Item.ObjectId) && o.DistancePercentage <= 15 && o.SizeDifference < 30)
                                .OrderBy(o => o.DistancePercentage)
                                .FirstOrDefault();

                if (bestMatch == null || bestMatch.Item.ProcessIndex + 25 < _processIndex)
                {
                    var trackingItem1 = new YoloTrackingItemExtended(item, GetObjectId())
                    {
                        ProcessIndex = _processIndex
                    };

                    _trackingItems.Add(trackingItem1.ObjectId, trackingItem1);
                    continue;
                }

                bestMatch.Item.X            = item.X;
                bestMatch.Item.Y            = item.Y;
                bestMatch.Item.Width        = item.Width;
                bestMatch.Item.Height       = item.Height;
                bestMatch.Item.ProcessIndex = _processIndex;
                bestMatch.Item.IncreaseTrackingConfidence();

                if (bestMatch.Item.TrackingConfidence >= 60)
                {
                    var trackingItem = new YoloTrackingItem(item, bestMatch.Item.ObjectId);
                    trackingItems.Add(trackingItem);
                }
            }

            var itemsWithoutHits = _trackingItems.Values.Where(o => o.ProcessIndex != _processIndex);

            foreach (var item in itemsWithoutHits)
            {
                item.DecreaseTrackingConfidence();
            }

            return(trackingItems);
        }