private void UpdateDevice(BlobData blob, Marker marker = null)
        {
            var device = Devices.Single(d => d.BlobId == blob.Id);
            var center = new Point(blob.Center.X, blob.Center.Y);
            device.Key = blob.Key;
            //device.BlobId = blob.Id;
            device.Center = center;
            device.State = blob.State;
            device.Shape = blob.Polygon;
            device.Area = blob.Area;

            if (marker != null)
            {
                device.DeviceId = marker.Id;
                device.IsIdentified = true;
                device.Angle = marker.Angle;
                device.RgbImageToDisplayRatio = marker.RgbImageToDisplayRatio;
            }
            else
            {
                var deltaAngle = blob.Angle - device.LastBlobAngle;

                // this is a hack but it works pretty good
                //if (deltaAngle > 45)
                //{
                //    deltaAngle -= 90;
                //    //return;
                //}
                //else if (deltaAngle < -45)
                //{
                //    deltaAngle += 90;
                //}

                //Console.WriteLine("Delta Angle {0}", deltaAngle);

                device.LastBlobAngle = blob.Angle;
                device.Angle += deltaAngle;
            }
        }
        private bool DeviceExists(BlobData blob, Func<Device, bool> whereFunc = null)
        {
            if (whereFunc != null)
                return Devices.Where(whereFunc).Any(d => d.BlobId == blob.Id);

            return Devices.Any(d => d.BlobId == blob.Id);
        }
 private void CreateDevice(BlobData blob)
 {
     var center = new Point(blob.Center.X, blob.Center.Y);
     var device = new Device(this, blob.OriginalId, "unknown")
     {
         BlobId = blob.Id,
         IsIdentified = false,
         Center = center,
         State = blob.State,
         LastBlobAngle = blob.Angle,
         Shape = blob.Polygon,
         Area = blob.Area,
     };
     AddDevice(device);
 }
        private static Marker GetClosestMarker(IEnumerable<Marker> markers, BlobData blob, out double retDistance)
        {
            Marker candidate = null;
            var leastDistance = double.MaxValue;
            foreach (var marker in markers)
            {
                var distance = (marker.Center - blob.Center).Length;

                if (leastDistance < distance) continue;

                candidate = marker;
                leastDistance = distance;
            }

            retDistance = leastDistance;
            return candidate;
        }
예제 #5
0
 private bool IsInTolerance(BlobData blob1, BlobData blob2, double tolerance)
 {
     var delta = blob1.Center - blob2.Center;
     //var dAngle = Math.Abs(blob1.Angle - blob2.Angle);
     return delta.X < tolerance && delta.Y < tolerance;
 }
예제 #6
0
        public override IData Copy()
        {
            var blob = new BlobData(Source, OriginalId, Key)
            {
                Id = Id,
                Center = Center,
                State = State,
                Angle = Angle,
                Area = Area,
                Shape = Shape,
                Polygon = Polygon
            };

            return blob;
        }