Esempio n. 1
0
 private void FOLV_Masks_CellRightClick(object sender, BrightIdeasSoftware.CellRightClickEventArgs e)
 {
     if (e.Model != null)
     {
         this.contextMenuPosObj = (ObjectPosition)e.Model;
     }
 }
Esempio n. 2
0
        private void FormatRow(object Sender, BrightIdeasSoftware.FormatRowEventArgs e)
        {
            try
            {
                ObjectPosition OP = (ObjectPosition)e.Model;

                // If SPI IsNot Nothing Then
                if (OP.IsStatic && e.Item.ForeColor != Color.Blue)
                {
                    e.Item.ForeColor = Color.Blue;
                }
                else if (!OP.IsStatic && e.Item.ForeColor != Color.Black)
                {
                    e.Item.ForeColor = Color.Black;
                }
            }



            catch (Exception)
            {
            }
            // Log("Error: " & ExMsg(ex))
            finally
            {
            }
        }
Esempio n. 3
0
        //remove objects from history if they have not been detected in defined time (history_save_mins) and found counter < history_threshold_count
        public void CleanUpExpiredHistory(String cameraName)
        {
            try
            {
                List <ObjectPosition> historyList = last_positions_history;

                //Global.Log("### History objects summary for camera " + cameraName + " ###");

                if (historyList != null && historyList.Count > 0)
                {
                    //scan backward through the list and remove by index. Not as easy to read but the faster for removals
                    for (int x = historyList.Count - 1; x >= 0; x--)
                    {
                        ObjectPosition historyObject = historyList[x];
                        TimeSpan       ts            = DateTime.Now - historyObject.createDate;
                        int            minutes       = ts.Minutes;

                        //Global.Log("\t" + historyObject.ToString() + " existed for: " + ts.Minutes + " minutes");
                        if (minutes >= history_save_mins)
                        {
                            Global.Log("Removing expired history: " + historyObject.ToString() + " for camera " + cameraName + " which existed for " + ts.Minutes + " minutes.");
                            historyList.RemoveAt(x);
                        }
                    }
                }
                else if (historyList == null)
                {
                    Global.Log("Error: historyList is null?");
                }
            }
            catch (Exception ex)
            {
                Global.Log("Error: " + Global.ExMsg(ex));
            }
        }
Esempio n. 4
0
        public void CleanUpExpiredMasks(String cameraName)
        {
            List <ObjectPosition> maskedList = masked_positions;

            if (maskedList != null && maskedList.Count > 0)
            {
                //Global.Log("Searching for object masks to remove on Camera: " + cameraName);

                //scan backward through the list and remove by index. Not as easy to read as find by object but the faster for removals
                for (int x = maskedList.Count - 1; x >= 0; x--)
                {
                    ObjectPosition maskedObject = maskedList[x];
                    if (!maskedObject.isVisible && !maskedObject.isStatic)
                    {
                        Global.Log("Masked object NOT visible - " + maskedObject.ToString());
                        maskedObject.counter--;

                        if (maskedObject.counter <= 0)
                        {
                            Global.Log("Removing expired masked object: " + maskedObject.ToString() + " for camera " + cameraName);
                            maskedList.RemoveAt(x);
                        }
                    }
                    else
                    {
                        Global.Log("Masked object VISIBLE - " + maskedObject.ToString());
                        maskedObject.isVisible = false; //reset flag
                    }
                }
            }
        }
Esempio n. 5
0
 private void FOLV_MaskHistory_CellRightClick(object sender, BrightIdeasSoftware.CellRightClickEventArgs e)
 {
     if (e.Model != null)
     {
         this.contextMenuPosObj = (ObjectPosition)e.Model;
         this.cam = AITOOL.GetCamera(this.contextMenuPosObj.CameraName);
     }
 }
 private void removeMaskToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (contextMenuPosObj != null)
     {
         cam.maskManager.masked_positions.Remove(contextMenuPosObj);
         contextMenuPosObj = null;
         Refresh();
         AppSettings.Save();
     }
 }
 private void createStaticMaskToolStripMenuItem1_Click(object sender, EventArgs e)
 {
     if (contextMenuPosObj != null)
     {
         contextMenuPosObj.isStatic = true;
         contextMenuPosObj.counter  = 0;
         contextMenuPosObj          = null;
         Refresh();
         AppSettings.Save();
     }
 }
Esempio n. 8
0
        public bool CreateDynamicMask(ObjectPosition currentObject)
        {
            bool maskExists = false;

            Global.Log("*** Starting new object mask processing ***");
            Global.Log("Current object detected: " + currentObject.ToString() + " on camera " + currentObject.cameraName);

            currentObject.thresholdPercent = thresholdPercent;

            if (last_positions_history.Contains(currentObject))
            {
                //get index to prevent another search for removal if needed
                int            indexLoc    = last_positions_history.IndexOf(currentObject);
                ObjectPosition foundObject = last_positions_history[indexLoc];

                Global.Log("Found in last_positions_history: " + foundObject.ToString() + " for camera: " + currentObject.cameraName);

                if (foundObject.counter < history_threshold_count)
                {
                    foundObject.counter++;
                }
                else
                {
                    Global.Log("History Threshold reached. Moving " + foundObject.ToString() + " to masked object list for camera: " + currentObject.cameraName);
                    last_positions_history.RemoveAt(indexLoc);
                    foundObject.isVisible = true;
                    foundObject.counter   = mask_counter_default;
                    masked_positions.Add(foundObject);
                }
            }
            else if (masked_positions.Contains(currentObject))
            {
                ObjectPosition maskedObject = (ObjectPosition)masked_positions[masked_positions.IndexOf(currentObject)];

                if (maskedObject.counter < mask_counter_default)
                {
                    maskedObject.counter++;
                }

                Global.Log("Found in masked_positions " + maskedObject.ToString() + " for camera " + currentObject.cameraName);

                maskedObject.isVisible = true;
                maskExists             = true;
            }
            else
            {
                Global.Log("+ New object found: " + currentObject.ToString() + ". Adding to last_positions_history for camera: " + currentObject.cameraName);
                last_positions_history.Add(currentObject);
            }

            return(maskExists);
        }
 private void createStaticMaskToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (contextMenuPosObj != null)
     {
         contextMenuPosObj.isStatic = true;
         contextMenuPosObj.counter  = 0;
         cam.maskManager.masked_positions.Add(contextMenuPosObj);
         cam.maskManager.last_positions_history.Remove(contextMenuPosObj);
         contextMenuPosObj = null;
         Refresh();
         AppSettings.Save();
     }
 }
Esempio n. 10
0
        private void FOLV_Masks_SelectionChanged(object sender, EventArgs e)
        {
            this.CurObjPosLst.Clear();

            if (FOLV_Masks.SelectedObjects != null && FOLV_Masks.SelectedObjects.Count > 0)
            {
                contextMenuPosObj = (ObjectPosition)FOLV_Masks.SelectedObject;
                ShowMaskImage();

                foreach (object obj in FOLV_Masks.SelectedObjects)
                {
                    CurObjPosLst.Add((ObjectPosition)obj);
                }
            }
            pictureBox1.Refresh();
        }
Esempio n. 11
0
        private void FOLV_MaskHistory_SelectionChanged(object sender, EventArgs e)
        {
            this.CurObjPosLst.Clear();

            if (this.FOLV_MaskHistory.SelectedObjects != null && this.FOLV_MaskHistory.SelectedObjects.Count > 0)
            {
                this.contextMenuPosObj = (ObjectPosition)this.FOLV_MaskHistory.SelectedObjects[0];
                this.cam = AITOOL.GetCamera(this.contextMenuPosObj.CameraName);

                this.ShowMaskImage();

                foreach (object obj in this.FOLV_MaskHistory.SelectedObjects)
                {
                    this.CurObjPosLst.Add((ObjectPosition)obj);
                }
            }
            this.pictureBox1.Refresh();
        }
Esempio n. 12
0
        private void createStaticMasksToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int cnt = 0;

            if (this.folv_ObjectDetail.SelectedObjects != null && this.folv_ObjectDetail.SelectedObjects.Count > 0)
            {
                foreach (ClsPrediction CP in this.folv_ObjectDetail.SelectedObjects)
                {
                    if (string.IsNullOrEmpty(CP.Camera))
                    {
                        Log("Error: Can only add newer history prediction items that include cameraname, imagewidth, imageheight.");
                    }
                    else
                    {
                        ObjectPosition OP  = new ObjectPosition(CP.XMin, CP.XMax, CP.YMin, CP.YMax, CP.Label, CP.ImageHeight, CP.ImageWidth, CP.Camera, CP.Filename);
                        Camera         cam = GetCamera(CP.Camera);
                        cam.maskManager.CreateDynamicMask(OP, true);
                        cnt++;
                    }
                }
            }
            Log($"Added/updated {cnt} masks.");
        }
Esempio n. 13
0
        public void AnalyzePrediction()
        {
            using var Trace = new Trace();  //This c# 8.0 using feature will auto dispose when the function is done.

            MaskResultInfo result = new MaskResultInfo();

            try
            {
                if (this._cam.enabled)
                {
                    if (!string.IsNullOrWhiteSpace(this._cam.triggering_objects_as_string))
                    {
                        if (this._cam.IsRelevant(this.Label))
                        {
                            // -> OBJECT IS RELEVANT

                            //if confidence limits are satisfied
                            bool OverrideThreshold = this._cururl != null && (this._cururl.Threshold_Lower > 0 || (this._cururl.Threshold_Upper > 0 && this._cururl.Threshold_Upper < 100));

                            if ((!OverrideThreshold && this.Confidence >= this._cam.threshold_lower && this.Confidence <= this._cam.threshold_upper) ||
                                (OverrideThreshold && this.Confidence >= this._cururl.Threshold_Lower && this.Confidence <= this._cururl.Threshold_Upper))
                            {
                                // -> OBJECT IS WITHIN CONFIDENCE LIMITS

                                //only if the object is outside of the masked area
                                result                      = AITOOL.Outsidemask(this._cam, this.XMin, this.XMax, this.YMin, this.YMax, this._curimg.Width, this._curimg.Height);
                                this.ImgMaskResult          = result.Result;
                                this.ImgMaskType            = result.MaskType;
                                this.ImagePointsOutsideMask = result.ImagePointsOutsideMask;

                                if (!result.IsMasked)
                                {
                                    this.Result = ResultType.Relevant;
                                }
                                else if (result.MaskType == MaskType.None) //if the object is in a masked area
                                {
                                    this.Result = ResultType.NoMask;
                                }
                                else if (result.MaskType == MaskType.Image) //if the object is in a masked area
                                {
                                    this.Result = ResultType.ImageMasked;
                                }

                                //check the mask manager if the image mask didnt flag anything
                                if (!result.IsMasked)
                                {
                                    //check the dynamic or static masks
                                    if (this._cam.maskManager.MaskingEnabled)
                                    {
                                        ObjectPosition currentObject = new ObjectPosition(this.XMin, this.XMax, this.YMin, this.YMax, this.Label,
                                                                                          this._curimg.Width, this._curimg.Height, this._cam.Name, this._curimg.image_path);
                                        //creates history and masked lists for objects returned
                                        result                     = this._cam.maskManager.CreateDynamicMask(currentObject);
                                        this.DynMaskResult         = result.Result;
                                        this.DynMaskType           = result.MaskType;
                                        this.DynamicThresholdCount = result.DynamicThresholdCount;
                                        this.PercentMatch          = result.PercentMatch;

                                        //there is a dynamic or static mask
                                        if (result.MaskType == MaskType.Dynamic)
                                        {
                                            this.Result = ResultType.DynamicMasked;
                                        }
                                        else if (result.MaskType == MaskType.Static)
                                        {
                                            this.Result = ResultType.StaticMasked;
                                        }
                                    }
                                }

                                if (result.Result == MaskResult.Error || result.Result == MaskResult.Unknown)
                                {
                                    this.Result = ResultType.Error;
                                    Log($"Error: Masking error? '{this._cam.Name}' ('{this.Label}') - DynMaskResult={this.DynMaskResult}, ImgMaskResult={this.ImgMaskResult}", "", this._cam.Name, this._curimg.image_path);
                                }
                            }
                            else //if confidence limits are not satisfied
                            {
                                this.Result = ResultType.NoConfidence;
                            }
                        }
                        else
                        {
                            this.Result = ResultType.UnwantedObject;
                        }
                    }
                    else
                    {
                        Log($"Error: Camera does not have any objects enabled '{this._cam.Name}' ('{this.Label}')", "", this._cam.Name, this._curimg.image_path);
                        this.Result = ResultType.Error;
                    }
                }
                else
                {
                    Log($"Debug: Camera not enabled '{this._cam.Name}' ('{this.Label}')", "", this._cam.Name, this._curimg.image_path);
                    this.Result = ResultType.CameraNotEnabled;
                }
            }
            catch (Exception ex)
            {
                Log($"Error: Label '{this.Label}', Camera '{this._cam.Name}': {Global.ExMsg(ex)}", "", this._cam.Name, this._curimg.image_path);
                this.Result = ResultType.Error;
            }
        }