示例#1
0
        public ClsPrediction(ObjectType defaultObjType, Camera cam, ClsDeepstackDetection AiDetectionObject, ClsImageQueueItem curImg, ClsURLItem curURL)
        {
            this._defaultObjType = defaultObjType;
            this._cam            = cam;
            this._curimg         = curImg;
            this._cururl         = curURL;

            //this._imageObject = AiDetectionObject;
            this.Camera      = cam.Name;
            this.ImageHeight = curImg.Height;
            this.ImageWidth  = curImg.Width;

            if (AiDetectionObject == null || cam == null || string.IsNullOrWhiteSpace(AiDetectionObject.label))
            {
                Log("Error: Prediction or Camera was null?", "", this._cam.Name);
                this.Result = ResultType.Error;
                return;
            }

            //force first letter to always be capitalized
            this.Label      = Global.UpperFirst(AiDetectionObject.label);
            this.XMax       = AiDetectionObject.x_max;
            this.YMax       = AiDetectionObject.y_max;
            this.XMin       = AiDetectionObject.x_min;
            this.YMin       = AiDetectionObject.y_min;
            this.Confidence = AiDetectionObject.confidence * 100;  //store as whole number percent
            this.Filename   = curImg.image_path;
            this.RectHeight = this.XMax - this.YMin;
            this.RectWidth  = this.XMax - this.XMin;

            this.GetObjectType();
        }
示例#2
0
        public static string GetImageForAIServerList(object row)
        {
            string RetKey = "";

            try
            {
                string png = ".png";  //make empty string to avoid using the png version of the images

                ClsURLItem url = (ClsURLItem)row;
                if (url.Type == URLTypeEnum.AWSRekognition_Objects || url.Type == URLTypeEnum.AWSRekognition_Faces)
                {
                    RetKey = "AWSRekognition" + png;
                }
                else if (url.Type == URLTypeEnum.DeepStack || url.Type == URLTypeEnum.DeepStack_Faces || url.Type == URLTypeEnum.DeepStack_Custom || url.Type == URLTypeEnum.DeepStack_Scene)
                {
                    RetKey = "Deepstack" + png;
                }
                else if (url.Type == URLTypeEnum.DOODS)
                {
                    RetKey = "DOODS" + png;
                }
                else if (url.Type == URLTypeEnum.SightHound_Person || url.Type == URLTypeEnum.SightHound_Vehicle)
                {
                    RetKey = "SightHound" + png;
                }
            }
            catch (Exception)
            {
            }

            return(RetKey);
        }
示例#3
0
        public ClsPrediction(ObjectType defaultObjType, Camera cam, ClsDoodsDetection AiDetectionObject, ClsImageQueueItem curImg, ClsURLItem curURL)
        {
            this._defaultObjType = defaultObjType;
            this._cam            = cam;
            this._curimg         = curImg;
            this._cururl         = curURL;

            //this._imageObject = AiDetectionObject;
            this.Camera      = cam.Name;
            this.ImageHeight = curImg.Height;
            this.ImageWidth  = curImg.Width;

            if (AiDetectionObject == null || cam == null || string.IsNullOrWhiteSpace(AiDetectionObject.Label))
            {
                Log("Error: Prediction or Camera was null?", "", this._cam.Name);
                this.Result = ResultType.Error;
                return;
            }

            //force first letter to always be capitalized
            this.Label = Global.UpperFirst(AiDetectionObject.Label);

            //{
            //         "top":0.09833781,
            //         "left":0.62415826,
            //         "bottom":0.14295554,
            //         "right":0.7029755,
            //         "label":"car",
            //         "confidence":63.28125
            //      }

            // convert percentage values from doods to pixels

            //System.Drawing.Rectangle rect = new System.Drawing.Rectangle(xmin, ymin, xmax - xmin, ymax - ymin);
            //System.Drawing.Rectangle rect = new System.Drawing.Rectangle(x,    y,    width,       height);

            //x,    y    = - coordinate of the UPPER LEFT corner of the rectangle
            //xmin, ymin

            double right = curImg.Width * AiDetectionObject.Right;
            double left  = curImg.Width * AiDetectionObject.Left;

            double top    = curImg.Height * AiDetectionObject.Top;
            double bottom = curImg.Height * AiDetectionObject.Bottom;

            this.XMin = Convert.ToInt32(Math.Round(left));
            this.YMin = Convert.ToInt32(Math.Round(top));

            this.XMax = Convert.ToInt32(Math.Round(right));
            this.YMax = Convert.ToInt32(Math.Round(bottom));

            this.RectHeight = this.XMax - this.YMin;
            this.RectWidth  = this.XMax - this.XMin;

            this.Confidence = Convert.ToSingle(AiDetectionObject.Confidence);
            this.Filename   = curImg.image_path;

            this.GetObjectType();
        }
        private void deepstackToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ClsURLItem url = new ClsURLItem("", AppSettings.Settings.AIURLList.Count + 1, URLTypeEnum.DeepStack);

            this.CurURL = url;
            AppSettings.Settings.AIURLList.Add(url);
            Global_GUI.UpdateFOLV(FOLV_AIServers, AppSettings.Settings.AIURLList, UseSelected: true, SelectObject: this.CurURL, FullRefresh: true);
            UpdateButtons();
        }
示例#5
0
        public ClsPrediction(ObjectType defaultObjType, Camera cam, ClsDeepstackDetection AiDetectionObject, ClsImageQueueItem curImg, ClsURLItem curURL)
        {
            this._defaultObjType = defaultObjType;
            this._cam            = cam;
            this._curimg         = curImg;
            this._cururl         = curURL;
            this.Server          = curURL.CurSrv;
            this.Time            = DateTime.Now;


            //this._imageObject = AiDetectionObject;
            this.Camera      = cam.Name;
            this.BICamName   = cam.BICamName;
            this.ImageHeight = curImg.Height;
            this.ImageWidth  = curImg.Width;
            this.Filename    = curImg.image_path;

            if (AiDetectionObject == null || cam == null || (string.IsNullOrWhiteSpace(AiDetectionObject.label) && string.IsNullOrWhiteSpace(AiDetectionObject.UserID)))
            {
                Log("Error: Prediction or Camera was null?", "", this._cam.Name);
                this.Result = ResultType.Error;
                return;
            }

            //if running face detection:
            if (!string.IsNullOrWhiteSpace(AiDetectionObject.UserID))
            {
                if (string.IsNullOrWhiteSpace(AiDetectionObject.label))
                {
                    AiDetectionObject.label = "Face";
                }

                this.Label  = AiDetectionObject.label.Trim();
                this.Detail = Global.UpperFirst(AiDetectionObject.UserID);
            }
            else
            {
                //force first letter to always be capitalized
                this.Label = Global.UpperFirst(AiDetectionObject.label);
            }

            if (!string.IsNullOrEmpty(AiDetectionObject.Detail))
            {
                this.Detail = Global.UpperFirst(AiDetectionObject.Detail);
            }

            this.XMax       = AiDetectionObject.x_max;
            this.YMax       = AiDetectionObject.y_max;
            this.XMin       = AiDetectionObject.x_min;
            this.YMin       = AiDetectionObject.y_min;
            this.Confidence = AiDetectionObject.confidence * 100;  //store as whole number percent
            this.Filename   = curImg.image_path;
            this.RectHeight = this.XMax - this.YMin;
            this.RectWidth  = this.XMax - this.XMin;

            this.GetObjectType();
        }
示例#6
0
        public ClsPrediction(ObjectType defaultObjType, Camera cam, Amazon.Rekognition.Model.Label AiDetectionObject, int InstanceIdx, ClsImageQueueItem curImg, ClsURLItem curURL)
        {
            this._defaultObjType = defaultObjType;
            this._cam            = cam;
            this._cururl         = curURL;
            this._curimg         = curImg;
            this.Camera          = cam.Name;
            this.ImageHeight     = curImg.Height;
            this.ImageWidth      = curImg.Width;

            if (AiDetectionObject == null || cam == null || string.IsNullOrWhiteSpace(AiDetectionObject.Name))
            {
                Log("Error: Prediction or Camera was null?", "", this._cam.Name);
                this.Result = ResultType.Error;
                return;
            }
            //"Name": "Car",
            //            "Confidence": 98.87621307373047,
            //            "Instances": [
            //                {
            //                    "BoundingBox": {
            //                        "Width": 0.10527367144823074,
            //                        "Height": 0.18472492694854736,
            //                        "Left": 0.0042892382480204105,
            //                        "Top": 0.5051581859588623
            //                    },
            //                    "Confidence": 98.87621307373047
            //                },

            //Rectangle(xmin, ymin, xmax - xmin, ymax - ymin)
            //          x,    y     Width,       Height

            this.RectHeight = Convert.ToInt32(Math.Round(curImg.Height * AiDetectionObject.Instances[InstanceIdx].BoundingBox.Height));
            this.RectWidth  = Convert.ToInt32(Math.Round(curImg.Width * AiDetectionObject.Instances[InstanceIdx].BoundingBox.Width));

            double right = (curImg.Width * AiDetectionObject.Instances[InstanceIdx].BoundingBox.Left) + this.RectWidth;
            double left  = curImg.Width * AiDetectionObject.Instances[InstanceIdx].BoundingBox.Left;

            double top    = curImg.Height * AiDetectionObject.Instances[InstanceIdx].BoundingBox.Top;
            double bottom = (curImg.Height * AiDetectionObject.Instances[InstanceIdx].BoundingBox.Top) + this.RectHeight;

            this.XMin = Convert.ToInt32(Math.Round(left));
            this.YMin = Convert.ToInt32(Math.Round(top));

            this.XMax = Convert.ToInt32(Math.Round(right));
            this.YMax = Convert.ToInt32(Math.Round(bottom));

            //force first letter to always be capitalized
            this.Label = Global.UpperFirst(AiDetectionObject.Name);

            this.Confidence = AiDetectionObject.Instances[InstanceIdx].Confidence;
            this.Filename   = curImg.image_path;

            this.GetObjectType();
        }
示例#7
0
        public static ClsURLItem GetURL(string url = "", URLTypeEnum type = URLTypeEnum.Unknown)
        {
            ClsURLItem ret = null;

            foreach (var cu in Settings.AIURLList)
            {
                if (string.Equals(cu.url, url, StringComparison.OrdinalIgnoreCase) || cu.Type == type)
                {
                    return(cu);
                }
            }
            return(ret);
        }
 private void Edit()
 {
     using (Frm_AIServerDeepstackEdit frm = new Frm_AIServerDeepstackEdit())
     {
         frm.CurURL = this.CurURL;
         if (frm.ShowDialog() == DialogResult.OK)
         {
             this.CurURL = frm.CurURL;  //this should update the list item by ref - prob not needed but makes me feel warm and fuzzy
             Global_GUI.UpdateFOLV(FOLV_AIServers, AppSettings.Settings.AIURLList, UseSelected: true, SelectObject: this.CurURL, FullRefresh: true);
         }
     }
     UpdateButtons();
 }
        private void addDoodsServerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ClsURLItem url = new ClsURLItem("", AppSettings.Settings.AIURLList.Count + 1, URLTypeEnum.DOODS);

            if (!AppSettings.Settings.AIURLList.Contains(url))
            {
                this.CurURL = url;
                AppSettings.Settings.AIURLList.Add(url);
                Global_GUI.UpdateFOLV(FOLV_AIServers, AppSettings.Settings.AIURLList, UseSelected: true, SelectObject: this.CurURL, FullRefresh: true);
            }
            else
            {
                MessageBox.Show("Already exists");
            }
            UpdateButtons();
        }
示例#10
0
        private void FormatURLRow(object Sender, BrightIdeasSoftware.FormatRowEventArgs e)
        {
            try
            {
                ClsURLItem url = (ClsURLItem)e.Model;

                // If SPI IsNot Nothing Then
                if (url.Enabled.ReadFullFence() && url.CurErrCount.ReadFullFence() == 0 && !url.UseAsRefinementServer && !url.UseOnlyAsLinkedServer)
                {
                    e.Item.ForeColor = Color.Green;
                }

                else if (url.Enabled.ReadFullFence() && url.CurErrCount.ReadFullFence() == 0 && url.UseAsRefinementServer)
                {
                    e.Item.ForeColor = Color.DarkOrange;
                }

                else if (url.Enabled.ReadFullFence() && url.CurErrCount.ReadFullFence() == 0 && url.UseOnlyAsLinkedServer)
                {
                    e.Item.ForeColor = Color.DarkCyan;
                }

                else if (url.Enabled.ReadFullFence() && url.CurErrCount.ReadFullFence() > 0)
                {
                    e.Item.ForeColor = Color.Black;
                    e.Item.BackColor = Color.Red;
                }
                else if (!url.Enabled.ReadFullFence())
                {
                    e.Item.ForeColor = Color.Gray;
                }
                else
                {
                    e.Item.ForeColor = Color.Black;
                }
            }


            catch (Exception)
            {
            }
            // Log("Error: " & ex.Msg())
            finally
            {
            }
        }
示例#11
0
        private void FOLV_AIServers_SelectionChanged(object sender, EventArgs e)
        {
            try
            {
                if (this.FOLV_AIServers.SelectedObjects != null && this.FOLV_AIServers.SelectedObjects.Count > 0)
                {
                    this.CurURL = (ClsURLItem)this.FOLV_AIServers.SelectedObjects[0];
                }
                else
                {
                    this.CurURL = null;
                }
            }
            catch (Exception ex)
            {
                AITOOL.Log($"Error: {ex.Msg()}");
            }

            UpdateButtons();
        }
示例#12
0
        public ClsPrediction(ObjectType defaultObjType, Camera cam, SightHoundPersonObject AiDetectionObject, ClsImageQueueItem curImg, ClsURLItem curURL, SightHoundImage SHImg)
        {
            this._defaultObjType = defaultObjType;
            this._cam            = cam;
            this._cururl         = curURL;
            this._curimg         = curImg;
            this.Camera          = cam.Name;

            if (AiDetectionObject == null || cam == null || string.IsNullOrWhiteSpace(AiDetectionObject.Type))
            {
                Log("Error: Prediction or Camera was null?", "", this._cam.Name);
                this.Result = ResultType.Error;
                return;
            }

            this.ImageHeight = SHImg.Height;   //curImg.Height;
            this.ImageWidth  = SHImg.Width;    //curImg.Width;

            if (curImg.Height != SHImg.Height)
            {
                Log($"Debug: Original image Height does not match returned height: Original={curImg.Height}, Returned={SHImg.Height}");
            }
            if (curImg.Width != SHImg.Width)
            {
                Log($"Debug: Original image Width does not match returned Width: Original={curImg.Width}, Returned={SHImg.Width}");
            }

            //{
            //    "image": {
            //        "width": 1280,
            //        "height": 960,
            //        "orientation": 1
            //    },

            //    "objects": [

            //        {
            //            "type": "person",
            //            "boundingBox": {
            //                "x": 363,
            //                "y": 182,
            //                "height": 778,
            //                "width": 723
            //            }
            //        },

            //        {
            //            "type": "face",
            //            "boundingBox": {
            //                "x": 508,
            //                "y": 305,
            //                "height": 406,
            //                "width": 406
            //            },
            //            "attributes": {
            //                "gender": "male",
            //                "genderConfidence": 0.9883,
            //                "age":25,
            //                "ageConfidence": 0.2599,
            //                "emotion": "happiness",
            //                "emotionConfidence": 0.9943,
            //                "emotionsAll": {
            //                    "neutral": 0.0018,
            //                    "sadness": 0.0009,
            //                    "disgust": 0.0002,
            //                    "anger": 0.0003,
            //                    "surprise": 0,
            //                    "fear": 0.0022,
            //                    "happiness": 0.9943
            //                },
            //                "pose":{
            //                    "pitch":-18.4849,
            //                    "roll":0.854,
            //                    "yaw":-4.2123
            //                },
            //                "frontal": true
            //            },
            //            "landmarks": {
            //                "faceContour": [[515,447],[517,491]...[872,436]],
            //                "noseBridge": [[710,419],[711,441]...[712,487]],
            //                "noseBall": [[680,519],[696,522]...[742,518]],
            //                "eyebrowRight": [[736,387],[768,376]...[854,394]],
            //                "eyebrowLeft": [[555,413],[578,391]...[679,391]],
            //                "eyeRight": [[753,428],[774,414]...[777,432]],
            //                "eyeRightCenter": [[786,423]],
            //                "eyeLeft": [[597,435],[617,423]...[619,442]],
            //                "eyeLeftCenter": [[630,432]],
            //                "mouthOuter": [[650,590],[674,572]...[675,600]],
            //                "mouthInner": [[661,587],[697,580]...[697,584]]
            //            }
            //        }
            //    ]
            //}


            //Rectangle(xmin, ymin, xmax - xmin, ymax - ymin)
            //          x,    y     Width,       Height


            //boundingBox (object): An object containing x, y, width, and height values
            //defining the location of the object in the image. The top left pixel of
            //the image represents coordinate (0,0).

            this.RectHeight = AiDetectionObject.BoundingBox.Height;
            this.RectWidth  = AiDetectionObject.BoundingBox.Width;

            double right = AiDetectionObject.BoundingBox.X + this.RectWidth;
            double left  = AiDetectionObject.BoundingBox.X;

            double top    = AiDetectionObject.BoundingBox.Y;
            double bottom = AiDetectionObject.BoundingBox.Y + this.RectHeight;

            this.XMin = Convert.ToInt32(Math.Round(left));
            this.YMin = Convert.ToInt32(Math.Round(top));

            this.XMax = Convert.ToInt32(Math.Round(right));
            this.YMax = Convert.ToInt32(Math.Round(bottom));

            //force first letter to always be capitalized
            this.Label = Global.UpperFirst(AiDetectionObject.Type);

            if (AiDetectionObject.Attributes != null && !string.IsNullOrEmpty(AiDetectionObject.Attributes.Gender))
            {
                this.Label += $" [{Global.UpperFirst(AiDetectionObject.Attributes.Gender)}, {AiDetectionObject.Attributes.Age}, {Global.UpperFirst(AiDetectionObject.Attributes.Emotion)}]";

                //this isnt exactly right, but sighthound doesnt give confidence for person/face, only gender, age
                this.Confidence = AiDetectionObject.Attributes.GenderConfidence * 100;
            }
            else
            {
                this.Confidence = 100;
            }

            this.Filename = curImg.image_path;

            this.GetObjectType();
        }
示例#13
0
        public ClsPrediction(ObjectType defaultObjType, Camera cam, SightHoundVehicleObject AiDetectionObject, ClsImageQueueItem curImg, ClsURLItem curURL, SightHoundImage SHImg)
        {
            //https://docs.sighthound.com/cloud/recognition/

            this._defaultObjType = defaultObjType;
            this._cam            = cam;
            this._cururl         = curURL;
            this._curimg         = curImg;
            this.Camera          = cam.Name;

            if (AiDetectionObject == null || cam == null || string.IsNullOrWhiteSpace(AiDetectionObject.ObjectType))
            {
                Log("Error: Prediction or Camera was null?", "", this._cam.Name);
                this.Result = ResultType.Error;
                return;
            }

            this.ImageHeight = SHImg.Height; //curImg.Height;
            this.ImageWidth  = SHImg.Width;  //curImg.Width;

            if (curImg.Height != SHImg.Height)
            {
                Log($"Debug: Original image Height does not match returned height: Original={curImg.Height}, Returned={SHImg.Height}");
            }
            if (curImg.Width != SHImg.Width)
            {
                Log($"Debug: Original image Width does not match returned Width: Original={curImg.Width}, Returned={SHImg.Width}");
            }

            //{
            //    "image": {
            //    "width":2016,
            //    "orientation":1,
            //    "height":1512
            //},
            //"objects":[
            //    {
            //        "vehicleAnnotation":{
            //            "bounding":{
            //                "vertices":[
            //                    {  "x":430, "y":286 },
            //                    {  "x":835, "y":286 },
            //                    {  "x":835, "y":559 },
            //                    {  "x":430, "y":559 }
            //                ]
            //            },
            //            "attributes":{
            //            "system":{
            //                "color":{
            //                    "confidence":0.9968,
            //                    "name":"silver/grey"
            //                },
            //                "make":{
            //                    "confidence":0.8508,
            //                    "name":"BMW"
            //                },
            //                "model":{
            //                    "confidence":0.8508,
            //                    "name":"3 Series"
            //                },
            //                "vehicleType":"car"
            //            }
            //            },
            //            "recognitionConfidence":0.8508
            //            "licenseplate":{
            //                "bounding":{
            //                    "vertices":[
            //                        { "x":617, "y":452 },
            //                        { "x":743, "y":452 },
            //                        { "x":743, "y":482 },
            //                        { "x":617, "y":482 }
            //                    ]
            //                },
            //                "attributes":{
            //                    "system":{
            //                        "region":{
            //                            "name":"Florida",
            //                            "confidence":0.9994
            //                        },
            //                        "string":{
            //                            "name":"RTB2",
            //                            "confidence":0.999
            //                        },
            //                        "characters":[
            //                            {
            //                                "bounding":{
            //                                    "vertices":[
            //                                        { "y":455, "x":637 },
            //                                        { "y":455, "x":649 },
            //                                        { "y":473, "x":649 },
            //                                        { "y":473, "x":637 }
            //                                    ]
            //                                },
            //                                "index":0,
            //                                "confidence":0.9999,
            //                                "character":"R"
            //                            },
            //                            {
            //                                "bounding":{
            //                                    "vertices":[
            //                                        { "y":455, "x":648 },
            //                                        { "y":455, "x":661 },
            //                                        { "y":473, "x":661 },
            //                                        { "y":473, "x":648 }
            //                                    ]
            //                                },
            //                                "index":1,
            //                                "confidence":0.9999,
            //                                "character":"T"
            //                            },
            //                            {
            //                                "bounding":{
            //                                    "vertices":[
            //                                        { "y":455, "x":671 },
            //                                        { "y":455, "x":684 },
            //                                        { "y":474, "x":684 },
            //                                        { "y":474, "x":671 }
            //                                    ]
            //                                },
            //                                "index":2,
            //                                "confidence":0.9996,
            //                                "character":"B"
            //                            },
            //                            {
            //                                "bounding":{
            //                                    "vertices":[
            //                                        { "y":456, "x":683 },
            //                                        { "y":456, "x":696 },
            //                                        { "y":474, "x":696 },
            //                                        { "y":474, "x":683 }
            //                                    ]
            //                                },
            //                                "index":3,
            //                                "confidence":0.9995,
            //                                "character":"2"
            //                            }
            //                        ]
            //                    }
            //                }
            //            },
            //        },
            //        "objectId":"_vehicle_f3c3d26b-c568-4d98-b6db-b96659fd7766",
            //        "objectType":"vehicle"
            //    }
            //],
            //"requestId":"d25b5e5d22f6431498065e9a25134d59"
            //}



            //Rectangle(xmin, ymin, xmax - xmin, ymax - ymin)
            //          x,    y     Width,       Height


            //
            //    vertices (array): A list of objects that define coordinates of the vertices that surround the Object
            //        x (integer): Horizontal pixel position of the vertex
            //        y (integer): Vertical pixel position of the vertex


            // get the bounding box from vertices
            List <System.Drawing.Point> pts = new List <System.Drawing.Point>();

            foreach (var pt in AiDetectionObject.VehicleAnnotation.Bounding.Vertices)
            {
                pts.Add(new System.Drawing.Point(pt.X, pt.Y));
            }

            Rectangle rect = Global.RectFromVertices(pts);

            this.RectHeight = rect.Height;
            this.RectWidth  = rect.Width;

            double right = rect.X + this.RectWidth;
            double left  = rect.X;

            double top    = rect.Y;
            double bottom = rect.Y + this.RectHeight;

            this.XMin = Convert.ToInt32(Math.Round(left));
            this.YMin = Convert.ToInt32(Math.Round(top));

            this.XMax = Convert.ToInt32(Math.Round(right));
            this.YMax = Convert.ToInt32(Math.Round(bottom));

            if (AiDetectionObject.VehicleAnnotation != null && !string.IsNullOrEmpty(AiDetectionObject.VehicleAnnotation.Attributes.System.VehicleType))
            {
                string type  = Global.UpperFirst(AiDetectionObject.VehicleAnnotation.Attributes.System.VehicleType);
                string color = Global.UpperFirst(AiDetectionObject.VehicleAnnotation.Attributes.System.Color.Name);
                string make  = Global.UpperFirst(AiDetectionObject.VehicleAnnotation.Attributes.System.Make.Name);
                string model = Global.UpperFirst(AiDetectionObject.VehicleAnnotation.Attributes.System.Model.Name);

                string plate = "Unknown";
                if (AiDetectionObject.VehicleAnnotation.Licenseplate != null && !string.IsNullOrEmpty(AiDetectionObject.VehicleAnnotation.Licenseplate.Attributes.System.String.Name))
                {
                    plate = $"{AiDetectionObject.VehicleAnnotation.Licenseplate.Attributes.System.Region.Name} {AiDetectionObject.VehicleAnnotation.Licenseplate.Attributes.System.String.Name}";
                }

                this.Label += $"{type} [{color}, {make}, {model}, Plate={plate}]";

                //this isnt exactly right, but sighthound doesnt give confidence for person/face, only gender, age
                this.Confidence = AiDetectionObject.VehicleAnnotation.RecognitionConfidence * 100;
            }
            else
            {
                this.Confidence = 100;
            }

            this.Filename = curImg.image_path;

            this.GetObjectType();
        }
示例#14
0
        public bool StartDeepstack(bool ForceRestart = false)
        {
            //This error happens when you run out of video memory:
            //stderr.txt
            //  File "C://DeepStack\windows_packages\torch\cuda\__init__.py", line 480, in _lazy_new
            //    return super(_CudaBase, cls).__new__(cls, *args, **kwargs)
            //RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 2.00 GiB total capacity; 35.77 MiB already allocated; 0 bytes free; 38.00 MiB reserved in total by PyTorch)

            //this error happens after sending an image to deepstack - I believe it is still running out of video memory:
            //  File "C:\DeepStack\intelligencelayer\shared\detection.py", line 138, in objectdetection
            //    os.remove(img_path)
            //FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\Users\\Vorlon\\AppData\\Local\\Temp\\DeepStack\\83e9c5b0-d698-44f3-a8df-d19655d9f7da'



            if (this.Starting.ReadFullFence())
            {
                Log("Already starting?");
                return(false);
            }

            this.Starting.WriteFullFence(true);

            using var Trace = new Trace();  //This c# 8.0 using feature will auto dispose when the function is done.

            bool Ret = false;

            try
            {
                if (!this.IsInstalled)
                {
                    Log("Error: Cannot start because not installed.");
                    this.IsStarted = false;
                    return(Ret);
                }
                else
                {
                    if (this.IsStarted)
                    {
                        if (this.StopBeforeStart || ForceRestart)
                        {
                            Log("Debug: Stopping already running DeepStack instance...");
                            this.StopDeepstack();
                            Thread.Sleep(250);
                        }
                        else
                        {
                            Log("Debug: Deepstack is already running, not re-starting due to 'deepstack_stopbeforestart' setting = false in aitool.settings.json file.");
                            return(Ret);
                        }
                    }

                    Log("Starting DeepStack...");
                }

                Stopwatch SW = Stopwatch.StartNew();
                this.URLS = "";

                if (this.IsNewVersion)
                {
                    List <string> ports = Global.Split(this.Port, ",|");
                    this.Count = ports.Count;

                    this.CommandLine = "";
                    int pcnt = 0;
                    foreach (string CurPort in ports)
                    {
                        if (Global.IsLocalPortInUse(Convert.ToInt32(CurPort)))
                        {
                            Log($"Error: Port {CurPort} is already open, so cannot start deepstack.exe using that port.");
                            continue;
                        }


                        Global.ClsProcess prc = new Global.ClsProcess();
                        prc.process.StartInfo.FileName         = this.DeepStackEXE;
                        prc.process.StartInfo.WorkingDirectory = Path.GetDirectoryName(this.DeepStackEXE);
                        if (this.CustomModelEnabled)
                        {
                            prc.process.StartInfo.Arguments = $"--MODELSTORE-DETECTION \"{this.CustomModelPath}\" --PORT {CurPort}";
                        }
                        else
                        {
                            string face   = "";
                            string scene  = "";
                            string detect = "";
                            string admin  = "";
                            string api    = "";
                            string mode   = "";

                            if (this.FaceAPIEnabled)
                            {
                                face = $"--VISION-FACE {this.FaceAPIEnabled} ";
                            }
                            if (this.SceneAPIEnabled)
                            {
                                scene = $"--VISION-SCENE {this.SceneAPIEnabled} ";
                            }
                            if (this.DetectionAPIEnabled)
                            {
                                detect = $"--VISION-DETECTION {this.DetectionAPIEnabled} ";
                            }
                            if (!string.IsNullOrEmpty(this.AdminKey))
                            {
                                admin = $"--ADMIN-KEY {this.AdminKey} ";
                            }
                            if (!string.IsNullOrEmpty(this.APIKey))
                            {
                                api = $"--API-KEY {this.APIKey} ";
                            }

                            if (!string.IsNullOrEmpty(this.Mode) && !this.DisplayVersion.Contains("2020"))
                            {
                                mode = $"--MODE {this.Mode} ";
                            }

                            prc.process.StartInfo.Arguments = $"{face}{scene}{detect}{admin}{api}{mode}--PORT {CurPort}";
                        }
                        if (!AppSettings.Settings.deepstack_debug)
                        {
                            prc.process.StartInfo.CreateNoWindow         = true;
                            prc.process.StartInfo.UseShellExecute        = false;
                            prc.process.StartInfo.RedirectStandardOutput = true;
                            prc.process.StartInfo.RedirectStandardError  = true;
                            prc.process.EnableRaisingEvents = true;
                            prc.process.OutputDataReceived += this.DSHandleServerProcMSG;
                            prc.process.ErrorDataReceived  += this.DSHandleServerProcERROR;
                        }
                        else
                        {
                            prc.process.StartInfo.UseShellExecute = false;
                        }

                        if (this.DisplayVersion.Contains("2020") && !string.Equals(this.Mode, "medium", StringComparison.OrdinalIgnoreCase))
                        {
                            prc.process.StartInfo.EnvironmentVariables["MODE"] = this.Mode;
                        }

                        prc.process.Exited += (sender, e) => this.DSProcess_Exited(sender, e, "deepstack.exe"); //new EventHandler(myProcess_Exited);
                        prc.FileName        = this.DeepStackEXE;
                        prc.CommandLine     = prc.process.StartInfo.Arguments;

                        pcnt++;
                        Log($"Starting {pcnt} of {ports.Count}: {prc.process.StartInfo.FileName} {prc.process.StartInfo.Arguments}...");
                        prc.process.Start();

                        Global.WaitForProcessToStart(prc.process, 3000, this.DeepStackEXE);

                        if (AppSettings.Settings.deepstack_highpriority)
                        {
                            prc.process.PriorityClass = ProcessPriorityClass.High;
                        }

                        if (!AppSettings.Settings.deepstack_debug)
                        {
                            prc.process.BeginOutputReadLine();
                            prc.process.BeginErrorReadLine();
                        }

                        this.ServerProc.Add(prc);

                        ClsURLItem url = new ClsURLItem($"http://127.0.0.1:{CurPort}/v1/vision/detection", AppSettings.Settings.AIURLList.Count + 1, URLTypeEnum.DeepStack);

                        this.CommandLine += $"{prc.FileName} {prc.CommandLine}\r\n";

                        this.URLS += $"{url.ToString()}\r\n";


                        if (!AppSettings.Settings.AIURLList.Contains(url))
                        {
                            Log("Automatically adding local Windows Deepstack URL: " + url.ToString());
                            AppSettings.Settings.AIURLList.Add(url);
                        }

                        Thread.Sleep(250);
                    }

                    this.Count = pcnt;

                    this.IsStarted = true;
                    this.HasError  = false;
                    Ret            = true;

                    //Lets wait for the rest of the python.exe processes to spawn and set their priority too (otherwise they are normal)

                    int PythonCnt         = 0;
                    int cc                = 0;
                    int ExpectedPythonCnt = 0;
                    if (this.FaceAPIEnabled)
                    {
                        ExpectedPythonCnt = this.Count * 5;  //face runs 5 copies of python.exe
                    }
                    else
                    {
                        ExpectedPythonCnt = this.Count * 2;  //normal detection runs 2 copies
                    }
                    do
                    {
                        List <Global.ClsProcess> montys = Global.GetProcessesByPath(this.PythonEXE);
                        PythonCnt = montys.Count;


                        if (montys.Count >= ExpectedPythonCnt)
                        {
                            //when deepstack is running normaly there will be 2 python.exe processes running for each deepstack.exe
                            //Set priority for each this way since we didnt start them in the first place...
                            if (AppSettings.Settings.deepstack_highpriority)
                            {
                                foreach (Global.ClsProcess prc in montys)
                                {
                                    cc++;
                                    if (Global.ProcessValid(prc))
                                    {
                                        try
                                        {
                                            prc.process.PriorityClass                    = ProcessPriorityClass.High;
                                            prc.process.StartInfo.UseShellExecute        = false;
                                            prc.process.StartInfo.RedirectStandardOutput = true;
                                            prc.process.StartInfo.RedirectStandardError  = true;
                                            prc.process.EnableRaisingEvents              = true;
                                            prc.process.OutputDataReceived              += this.DSHandlePythonProcMSG;
                                            prc.process.ErrorDataReceived               += this.DSHandlePythonProcERROR;
                                            prc.process.Exited += (sender, e) => this.DSProcess_Exited(sender, e, "python.exe"); //new EventHandler(myProcess_Exited);
                                        }
                                        catch { }
                                    }
                                }
                            }

                            this.PythonProc = montys;

                            break;
                        }
                        else
                        {
                            Log($"Debug: ...Waiting for {ExpectedPythonCnt} copies of {this.PythonEXE} to start (now={montys.Count})...");
                            Thread.Sleep(250);
                        }
                    } while (SW.ElapsedMilliseconds < 30000);  //wait 30 seconds max

                    this.RedisProc = Global.GetProcessesByPath(this.RedisEXE);

                    if (Global.ProcessValid(this.RedisProc))
                    {
                        if (AppSettings.Settings.deepstack_highpriority)
                        {
                            this.RedisProc[0].process.PriorityClass = ProcessPriorityClass.High;
                        }
                    }
                    else
                    {
                        this.HasError = true;
                        Log($"Error: 1 'redis-server.exe' processes did not start within " + SW.ElapsedMilliseconds + "ms");
                    }

                    if (PythonCnt >= ExpectedPythonCnt)
                    {
                        Log("Started in " + SW.ElapsedMilliseconds + "ms");
                    }
                    else
                    {
                        this.HasError = true;
                        Log($"Error: {ExpectedPythonCnt} 'python.exe' processes did not start within " + SW.ElapsedMilliseconds + "ms");
                    }

                    if (!this.HasError)
                    {
                        this.IsActivated = true;
                        this.IsStarted   = true;
                    }
                }
                else
                {
                    Log("Error: DeepStack for Windows v2020 or higher is not installed. https://github.com/johnolafenwa/DeepStack/releases");
                }
            }
            catch (Exception ex)
            {
                this.IsStarted = false;
                this.HasError  = true;
                Log("Error: Cannot start: " + Global.ExMsg(ex));
            }
            finally
            {
                this.Starting.WriteFullFence(false);
                //this.PrintDeepStackError();
            }

            Global.SendMessage(MessageType.UpdateDeepstackStatus, "Manual start");


            return(Ret);
        }
示例#15
0
        public ClsPrediction(ObjectType defaultObjType, Camera cam, Amazon.Rekognition.Model.FaceDetail AiDetectionObject, ClsImageQueueItem curImg, ClsURLItem curURL)
        {
            this._defaultObjType = defaultObjType;
            this._cam            = cam;
            this._cururl         = curURL;
            this._curimg         = curImg;
            this.Camera          = cam.Name;
            this.BICamName       = cam.BICamName;
            this.ImageHeight     = curImg.Height;
            this.ImageWidth      = curImg.Width;
            this.Server          = curURL.CurSrv;
            this.Time            = DateTime.Now;
            this.Filename        = curImg.image_path;

            if (AiDetectionObject == null || cam == null)
            {
                Log("Error: Prediction or Camera was null?", "", this._cam.Name);
                this.Result = ResultType.Error;
                return;
            }

            this.RectHeight = Convert.ToInt32(Math.Round(curImg.Height * AiDetectionObject.BoundingBox.Height));
            this.RectWidth  = Convert.ToInt32(Math.Round(curImg.Width * AiDetectionObject.BoundingBox.Width));

            double right = (curImg.Width * AiDetectionObject.BoundingBox.Left) + this.RectWidth;
            double left  = curImg.Width * AiDetectionObject.BoundingBox.Left;

            double top    = curImg.Height * AiDetectionObject.BoundingBox.Top;
            double bottom = (curImg.Height * AiDetectionObject.BoundingBox.Top) + this.RectHeight;

            this.XMin = Convert.ToInt32(Math.Round(left));
            this.YMin = Convert.ToInt32(Math.Round(top));

            this.XMax = Convert.ToInt32(Math.Round(right));
            this.YMax = Convert.ToInt32(Math.Round(bottom));

            //[{Global.UpperFirst(AiDetectionObject.Attributes.Gender)}, {AiDetectionObject.Attributes.Age}, {Global.UpperFirst(AiDetectionObject.Attributes.Emotion)}]
            string         emotions     = "";
            List <Emotion> emotionslist = new List <Emotion>();

            if (AiDetectionObject.Emotions != null && AiDetectionObject.Emotions.Count > 0)
            {
                foreach (Emotion em in AiDetectionObject.Emotions)
                {
                    if (em.Confidence >= 25)
                    {
                        emotionslist.Add(em);
                    }
                }
                if (emotionslist.Count > 0)
                {
                    //sort so highest conf is first
                    emotionslist = emotionslist.OrderByDescending(a => a.Confidence).ToList();
                    emotions     = ", ";
                    int cnt = 0;
                    foreach (Emotion em in emotionslist)
                    {
                        emotions += $"{Global.UpperFirst(em.Type.ToString().ToLower())};";
                        cnt++;
                        if (cnt > 3)
                        {
                            break;
                        }
                    }
                    emotions = emotions.Trim(" ;".ToCharArray());
                }
            }

            string gender = "";

            if (AiDetectionObject.Gender != null)
            {
                gender = $", {AiDetectionObject.Gender.Value}";
            }

            string age = "";

            if (AiDetectionObject.AgeRange != null)
            {
                age = $", {AiDetectionObject.AgeRange.Low}-{AiDetectionObject.AgeRange.High}";
            }

            string smile = "";

            if (AiDetectionObject.Smile.Value)
            {
                smile = ", Smile";
            }

            string eyeglasses = "";

            if (AiDetectionObject.Eyeglasses.Value)
            {
                eyeglasses = ", Eyeglasses";
            }

            string sunglasses = "";

            if (AiDetectionObject.Sunglasses.Value)
            {
                sunglasses = ", Sunglasses";
            }

            string beard = "";

            if (AiDetectionObject.Beard.Value)
            {
                beard = ", Beard";
            }

            string mustache = "";

            if (AiDetectionObject.Mustache.Value)
            {
                mustache = ", Mustache";
            }

            string mouthopen = "";

            if (AiDetectionObject.MouthOpen.Value)
            {
                mouthopen = ", MouthOpen";
            }


            this.Label = "Face";

            this.Detail = $"{gender}{age}{emotions}{smile}{eyeglasses}{sunglasses}{beard}{mustache}{mouthopen}".Trim(", ".ToCharArray());

            this.Confidence = AiDetectionObject.Confidence;

            this.GetObjectType();
        }