Ejemplo n.º 1
0
        private void Find_Closest_Centroid(FoundObject o, Point c)
        {
            int goal_distance = (int)Math.Sqrt(Math.Pow(found_objects[0].centroid_frames.Last().X - c.X, 2) +
                                               Math.Pow(found_objects[0].centroid_frames.Last().Y - c.Y, 2));

            var closest_object = found_objects[0];

            foreach (var obj_j in found_objects)
            {
                int obj_distance = (int)Math.Sqrt(Math.Pow(obj_j.centroid_frames.Last().X - c.X, 2) +
                                                  Math.Pow(obj_j.centroid_frames.Last().Y - c.Y, 2));

                if (obj_distance < goal_distance)
                {
                    goal_distance  = obj_distance;
                    closest_object = obj_j;
                }
            }

            if (goal_distance <= centroid_thresh)
            {
                if (o.centroid_frames.Count >= trail_length)
                {
                    o.centroid_frames.RemoveAt(0);
                }
                o.centroid_frames.Add(c);

                found_objects.Remove(closest_object);
                found_objects.Add(o);
            }
            else if (!found_objects.Contains(o))
            {
                found_objects.Add(o);
            }
        }
Ejemplo n.º 2
0
        public void UpdateAllNodes(object Data)
        {
            lock (GridNodes)
            {
                if (Terrain != null)
                {
                    Vector3 TerrainPosition = Terrain.transform.position;
                    Vector3 TerrainSize     = Terrain.terrainData.size;

                    var ArrayData = Data as object[];
                    ForEach((int NodeIndex, GridNode Node) =>
                    {
                        Node.UpdateNode(Terrain, TerrainPosition, TerrainSize, NodeSize, ObstaclePadding, MaxSlope, CastExtends, TerrainLayer, ObstacleLayer, (GameObject FoundObject) =>
                        {
                            IDynamicObstacle Dynamic = FoundObject.GetComponent <IDynamicObstacle>(); // check if there is a dynamic obstacle
                            if (Dynamic != null)
                            {
                                return(!Dynamic.IsObstacle);
                            } // check if object is dynamic
                            return(false);
                        });
                    });
                }
                else
                {
                    UnityEngine.Debug.LogError("There is no terrain assigned to this grid!");
                }
            }
        }
Ejemplo n.º 3
0
        private static void HandleRomObjectUpdate(ReceivedChat message)
        {
            if (message.Message == "new")
            {
                _objectList.Clear();
            }
            else
            {
                string[] detail = message.Message.Split((char)2);
                detail[0] = (Math.Round(Convert.ToDouble(detail[0]), 0)).ToString();
                detail[1] = (Math.Round(Convert.ToDouble(detail[1]), 0)).ToString();
                detail[2] = (Math.Round(Convert.ToDouble(detail[2]), 0)).ToString();
                int id = Convert.ToInt32(detail[5].Trim());

                if (_objectList.Find(o => o.Id == id) == null)
                {
                    FoundObject obj = new FoundObject();
                    obj.Id          = id;
                    obj.Name        = detail[4].Trim();
                    obj.Coordinates = new Vector3((Math.Round(Convert.ToDouble(detail[0]), 0)),
                                                  (Math.Round(Convert.ToDouble(detail[2]), 0)),
                                                  (Math.Round(Convert.ToDouble(detail[1]), 0)));

                    obj.Attackable = (detail[6].Trim().ToUpper() == "TRUE");
                    _objectList.Add(obj);
                }
            }
            //foundObjectBindingSource.ResetBindings(false);
        }
Ejemplo n.º 4
0
 public NPCRecord(FoundObject o)
 {
     name   = o.Name;
     id     = o.Id;
     x      = (int)o.Coordinates.X;
     z      = (int)o.Coordinates.Z;
     y      = (int)o.Coordinates.Y;
     zoneid = o.ZoneId;
 }
Ejemplo n.º 5
0
    public void LoseObject(FoundObject target)
    {
        for (int i = 0;i < Intuition.Count;i++)
        {
            if(Intuition[i].objectName == target.objectName)
            {
                Intuition.RemoveAt(i);
            }

        }
    }
Ejemplo n.º 6
0
 public static void Add(FoundObject o)
 {
     _lock.EnterWriteLock();
     try
     {
         _queue.Enqueue(o);
     }
     finally
     {
         _lock.ExitWriteLock();
     }
 }
        //Отдельный метод для создания объекта
        public int CreateObject(string NameObject, string TypeObject, bool localType, bool TIOCHType, bool RefType)
        {
            FoundObject Obj = new FoundObject();

            Obj.NameObject = NameObject;
            Obj.TypeObject = TypeObject;
            Obj.local      = localType;
            Obj.RefType    = RefType;
            Obj.TIOCHType  = TIOCHType;
            Obj.T11ID      = CounterT11Id;
            CounterT11Id++;
            FoundObjectList.Add(Obj);

            return(FoundObjectList.Count - 1);
        }
Ejemplo n.º 8
0
    public void FindObject(FoundObject target)
    {
        if (Intuition.Count == 0)
        {
            Intuition.Add(target);
        }
        else
        {
            for (int i = 0; i < Intuition.Count; i++)
            {
                if (Intuition[i].objectType == target.objectType)
                {
                    break;
                }

                if (i == Intuition.Count)
                {
                    Intuition.Add(target);
                }
            }
        }
    }
Ejemplo n.º 9
0
 public void SourceFound(FoundObject foundObject)
 {
     timesFound++;
     objects.Add(foundObject);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Process pending requests and call the callback specified in the startup config.
        /// </summary>
        private void ProcessPendingQueriesAsync()
        {
            MLThreadDispatch.ScheduleWork(() =>
            {
                try
                {
                    if (_instance.pendingQueries.Count > 0)
                    {
                        // Process each individual pending query to get updated status.
                        foreach (ulong handle in _instance.pendingQueries.Keys)
                        {
                            // Request the update.
                            MLResult.Code resultCode = NativeBindings.MLFoundObjectGetResultCount(_instance.handle, handle, out uint resultCount);

                            if (MLResult.IsOK(resultCode))
                            {
                                FoundObject[] foundObjects = new FoundObject[resultCount];

                                // For each found object in the query, get it's reference and property values from the API.
                                for (uint objectIndex = 0; objectIndex < resultCount; objectIndex++)
                                {
                                    NativeBindings.FoundObjectNative nativeFoundObject = new NativeBindings.FoundObjectNative();

                                    // Get the object reference from the API.
                                    resultCode = NativeBindings.MLFoundObjectGetResult(_instance.handle, handle, objectIndex, ref nativeFoundObject);

                                    if (MLResult.IsOK(resultCode))
                                    {
                                        Dictionary <string, string> properties = new Dictionary <string, string>();

                                        // Get the object's properties from the API.
                                        if (nativeFoundObject.PropertyCount > 0)
                                        {
                                            NativeBindings.PropertyNative objectProperty = new NativeBindings.PropertyNative();
                                            for (uint propertyIndex = 0; propertyIndex < nativeFoundObject.PropertyCount; propertyIndex++)
                                            {
                                                resultCode = NativeBindings.MLFoundObjectGetProperty(_instance.handle, nativeFoundObject.Id, propertyIndex, ref objectProperty);

                                                if (MLResult.IsOK(resultCode))
                                                {
                                                    properties.Add(new string(objectProperty.Key).Replace("\0", string.Empty).ToLower(), new string(objectProperty.Value).Replace("\0", string.Empty));
                                                }
                                                else
                                                {
                                                    MLPluginLog.ErrorFormat("MLFoundObjects.ProcessPendingQueries failed to get found object property. Reason: {0}", MLResult.CodeToString(resultCode));
                                                }
                                            }
                                        }

                                        FoundObject foundObject = nativeFoundObject.Data;

                                        // Currently the only valid object properties are: label, score
                                        foundObject.Label         = properties.ContainsKey("label") ? properties["label"] : string.Empty;
                                        foundObject.Confidence    = properties.ContainsKey("score") ? Convert.ToSingle(properties["score"]) : 0f;
                                        foundObjects[objectIndex] = foundObject;
                                    }
                                    else
                                    {
                                        MLPluginLog.ErrorFormat("MLFoundObjects.ProcessPendingQueries failed to get found object. Reason: {0}", MLResult.CodeToString(resultCode));
                                        _instance.errorQueries.Add(handle);
                                    }
                                }

                                if (!_instance.completedQueries.Contains(handle))
                                {
                                    _instance.completedQueries.Add(handle);
                                }

                                Query query = _instance.pendingQueries[handle];

                                // Dispatch list of found objects back to main.
                                MLThreadDispatch.ScheduleMain(() =>
                                {
                                    query.Callback(MLResult.Create(resultCode), foundObjects);
                                });
                            }
                            else
                            {
                                MLPluginLog.ErrorFormat("MLFoundObjects.ProcessPendingQueries failed to query found objects. Reason: {0}", MLResult.CodeToString(resultCode));
                                _instance.errorQueries.Add(handle);
                            }
                        }

                        foreach (ulong handle in _instance.errorQueries)
                        {
                            _instance.pendingQueries.TryRemove(handle, out Query q);
                        }

                        _instance.errorQueries.Clear();

                        foreach (ulong handle in _instance.completedQueries)
                        {
                            _instance.pendingQueries.TryRemove(handle, out Query q);
                        }

                        _instance.completedQueries.Clear();
                    }
                }
                catch (System.EntryPointNotFoundException)
                {
                    MLPluginLog.Error("MLFoundObjects.ProcessPendingQueries failed. Reason: API symbols not found");
                }

                return(true);
            });
        }
Ejemplo n.º 11
0
        private void Find_Objects()
        {
            frame_objects.Clear();
            frame_centroids.Clear();
            var         processed_frame = data[current_line];
            FoundObject fo               = new FoundObject();
            FoundObject comparableFo     = new FoundObject();
            bool        isInComparableFo = false;

            for (int i = 1; i < processed_frame.Count; i++)
            {
                if (Math.Abs(processed_frame[i] - processed_frame[i - 1]) >= 100)
                {
                    if (isInComparableFo)
                    {
                        if (comparableFo.points.Count > min_points)
                        {
                            frame_objects.Add(comparableFo);
                        }

                        if (fo.values.Count > 0 && Math.Abs(processed_frame[i] - fo.values.Last()) <= 20)
                        {
                            fo.points.Add(frame_points[i]);
                            fo.values.Add(processed_frame[i]);
                        }
                        else
                        {
                            if (fo.points.Count > min_points)
                            {
                                frame_objects.Add(fo);
                            }

                            fo = new FoundObject(processed_frame[i], frame_points[i]);
                        }

                        isInComparableFo = false;
                    }
                    else
                    {
                        comparableFo     = new FoundObject(processed_frame[i], frame_points[i]);
                        isInComparableFo = true;
                    }
                }
                else
                {
                    if (!isInComparableFo)
                    {
                        if (fo.points.Count >= (int)num_max_points.Value)
                        {
                            if (fo.points.Count > min_points)
                            {
                                frame_objects.Add(fo);
                            }

                            fo = new FoundObject(processed_frame[i], frame_points[i]);
                        }
                        else
                        {
                            fo.points.Add(frame_points[i]);
                            fo.values.Add(processed_frame[i]);
                        }
                    }
                    else
                    {
                        if (comparableFo.points.Count >= (int)num_max_points.Value)
                        {
                            if (comparableFo.points.Count > min_points)
                            {
                                frame_objects.Add(comparableFo);
                            }

                            comparableFo = new FoundObject(processed_frame[i], frame_points[i]);
                        }
                        else
                        {
                            comparableFo.points.Add(frame_points[i]);
                            comparableFo.values.Add(processed_frame[i]);
                        }
                    }
                }
            }

            frame = new Bitmap(frame);
            this.objects_grid.Rows.Clear();

            frame_objects.RemoveAll(o => o.points.Count(p => (Math.Abs(p.X - o.points[0].X) < 3) || (Math.Abs(p.Y - o.points[0].Y) < 3)) > o.points.Count * 5 / 6);

            if (found_objects.Count == 0)
            {
                frame_objects.ForEach(o => found_objects.Add(o));
            }

            foreach (var obj in frame_objects)
            {
                int min_x      = obj.points.Min(p => p.X),
                         min_y = obj.points.Min(p => p.Y),
                         max_x = obj.points.Max(p => p.X),
                         max_y = obj.points.Max(p => p.Y);

                Point centroid   = new Point((min_x + max_x) / 2, (min_y + max_y) / 2),
                      endpoint   = obj.points.Last(),
                      startpoint = obj.points.First();

                frame_centroids.Add(centroid);

                if (obj.centroid_frames.Count >= trail_length)
                {
                    obj.centroid_frames.RemoveAt(0);
                }
                obj.centroid_frames.Add(centroid);

                using (Graphics g = Graphics.FromImage(frame))
                {
                    if (startpoint.X == endpoint.X)
                    {
                        startpoint = obj.points.Last(p => p.X == min_x);
                        endpoint   = obj.points.Last(p => p.X == max_x);
                        g.DrawLine(new Pen(Color.Blue, 4), startpoint, endpoint);
                    }
                    else
                    {
                        double slope       = (startpoint.Y - endpoint.Y) / (double)(startpoint.X - endpoint.X);
                        double y_intersect = -slope * startpoint.X + startpoint.Y;

                        if (obj.points.Count(p => Math.Abs(p.Y - (slope * p.X) - y_intersect) <= 5) >= obj.points.Count * 5 / 6)
                        {
                            g.DrawLine(new Pen(Color.Blue, 4), startpoint, endpoint);
                        }
                        else
                        {
                            g.DrawRectangle(Pens.Fuchsia, min_x, min_y, max_x - min_x, max_y - min_y);
                            Find_Closest_Centroid(obj, centroid);

                            this.objects_grid.Rows.Add(new object[] {
                                time[current_line],
                                frame_objects.IndexOf(obj),
                                obj.centroid_frames.Last()
                            });

                            g.FillEllipse(Brushes.Red, centroid.X, centroid.Y, 5, 5);

                            found_objects.ForEach(o =>
                            {
                                if (o.centroid_frames.Count > 1)
                                {
                                    g.DrawLines(new Pen(Color.Green, 2), o.centroid_frames.ToArray());
                                }
                            });
                        }
                    }
                }
            }

            found_objects.RemoveAll(foo => !frame_centroids.Contains(foo.centroid_frames.Last()));

            this.frame_box.Image = frame;
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Returns a hash code for this instance.
 /// </summary>
 /// <returns>
 /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
 /// </returns>
 public override int GetHashCode()
 {
     return(DistanceMm.GetHashCode() ^ FoundObject.GetHashCode() ^ IsLiftInFov.GetHashCode() ^ Unobstructed.GetHashCode()
            ^ SignalQuality.GetHashCode());
 }
Ejemplo n.º 13
0
 public Barchart(IImageMatrix<IRGB> sampleImage)
 {
     this.sampleImage = sampleImage;
     this.foundObject = new FoundObject();
 }