Ejemplo n.º 1
0
 public ObjectTrackedArgs(ObjectTracked ot)
 {
     obj = ot;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the tracked objects
        /// </summary>
        /// <returns>Objects</returns>
        public LinkedList<ObjectTracked> GetObjects()
        {
            LinkedList<ObjectTracked> retval = new LinkedList<ObjectTracked>();
            int count = 0; // wether we got anything or nothing
            foreach (Target t in _targets)
            {
                int best_score = 0;     // does this object have a target to belong to? well find out with these vars for later checking
                ObjectTracked best_scorer = null;
                int score;
                foreach (ObjectTracked obj in ObjectsTracked)
                {
                    score = obj.GetScore(t);
                    if (score > _min_score) // we will check if its more than the threshhold later
                    {
                        best_score = score;
                        best_scorer = obj;
                    }
                }
                if (best_score > _min_score)
                {
                    best_scorer.PositionWasFaked = false;
                    best_scorer.Position = new Point(t.X, t.Y);
                    best_scorer.Size = new Rectangle(t.SizeX, t.SizeY, 0, 0);
                    best_scorer.Score = best_score;
                    ObjectTrackedArgs args = new ObjectTrackedArgs(best_scorer);
                    UpdateTrackedObject(args);
                }
                else
                {
                    ObjectTracked new_obj = new ObjectTracked(_i++,
                        new Point(t.X, t.Y),
                        new Rectangle(t.SizeX, t.SizeY, 0, 0),
                        new Rectangle(0, 0, FrameSizeX, FrameSizeY)
                        );

                    ObjectsTracked.AddLast(new_obj);
                    if (NewObjectTracked != null)
                    {
                        ObjectTrackedArgs args = new ObjectTrackedArgs(new_obj);
                        NewObjectTracked(args);
                    }
                }
            }
            LinkedListNode<ObjectTracked> cur = ObjectsTracked.First;
            int bigest_id = 0;
            while (cur != null)
            {
                // check _i and make it as small as possible
                if (cur.Value.ID > bigest_id)
                    bigest_id = cur.Value.ID;

                int ms_ago = (int)(DateTime.Now - cur.Value.LastSeen).TotalMilliseconds;
                if (ms_ago <= _miliseconds_unseen_till_removed)
                {
                    retval.AddLast(cur.Value);
                    count++;
                }
                else
                {
                    if (LostTrackedObject != null)
                    {
                        ObjectTrackedArgs args = new ObjectTrackedArgs(cur.Value);
                        LostTrackedObject(args);
                    }

                    LinkedListNode<ObjectTracked> last = cur;
                    cur = cur.Next;
                    ObjectsTracked.Remove(last);
                }

                if (cur != null)
                {
                    cur = cur.Next;
                }
            }
            _i = bigest_id + 1;

            // Update positions / Velocity
            foreach (ObjectTracked obj in ObjectsTracked)
            {
                if ((DateTime.Now - obj.LastSeen).TotalMilliseconds > 50.0)
                {
                    obj.FakeUpdatePos();
                }
            }

            return retval;
        }
Ejemplo n.º 3
0
 public AnimationHandeler(ObjectTracked obj)
 {
     Obj = obj;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Draw a box around an object
 /// </summary>
 /// <param name="obj">Object to draw around</param>
 /// <param name="bmp">The bitmap to draw to</param>
 /// <param name="col">Color</param>
 public void DrawBox(ObjectTracked obj, ref Bitmap bmp, Color col)
 {
     DrawBox(obj.Position.X, obj.Position.Y, obj.Size.X, obj.Size.Y, ref bmp, col, false);
 }
Ejemplo n.º 5
0
        private Bitmap GetImage(ref Bitmap frame, ObjectTracked obj)
        {
            Bitmap img = new Bitmap(frame);
            DateTime now = DateTime.Now;
            string str = now.TimeOfDay.ToString();

            Graphics gfx = Graphics.FromImage(img);
            Font fnt = new Font(FontFamily.GenericMonospace, 10f);
            gfx.DrawString(str, fnt, Brushes.Red, new PointF(1f,
                    img.Height - fnt.Height - 2f
                ));

            int x, y, w, h;
            x = (int)(obj.PosX * img.Size.Width);
            y = (int)(obj.PosY * img.Size.Height);

            w = (int)(obj.SizeX * img.Size.Width);
            h = (int)(obj.SizeY * img.Size.Height);

            helper.DrawBox(x, y, w, h, ref img, Color.Red, false);

            return img;
        }
Ejemplo n.º 6
0
        private string GetFile(ObjectTracked obj)
        {
            string date = DateTime.Now.ToString();
            date = date.Replace("/", "-");
            date = date.Replace(" ", "\\"); // date and time are seperated by a space, this will newfolder them
            date = date.Replace(":", ".");

            string folderDate = Path.GetDirectoryName(date);
            string path = "C:\\Users\\C0BRA\\Documents\\My Dropbox\\Public\\Detection\\" + folderDate;
            date = date.Replace(folderDate, "");

            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);

            return path + date + " ID " + obj.ID.ToString() + ".gif";
        }