예제 #1
0
        private async Task <List <RecognizedObject> > GetIdentifiedPlatesAsync(string base64, double latitude, double longitude)
        {
            PlateAPIResponse cloudResponse = await GetPlateAPIResponseAsync(base64);

            cloudResponse.UpdateMatchesPattern(AppSettings.Configuration.PlatePattern);
            List <PlateAPIResult>   matchingResults  = cloudResponse.Results.Where(result => result.MatchesPattern).ToList();
            List <RecognizedObject> identifiedPlates = new List <RecognizedObject>();

            matchingResults.ForEach(matching =>
            {
                Plate plate = _plateRepository.GetByPlateNumber(matching.Plate);
                if (plate != null)
                {
                    Timestamp timestamp = _timestampRepository.GetLatestModelTimestamp(plate.Id);
                    bool seenBefore     = true;
                    if (timestamp == null || timestamp.DateAndTime == null)
                    {
                        seenBefore = false;
                        timestamp  = new Timestamp()
                        {
                            DateAndTime    = DateTime.UtcNow.ToUTC2().GetFormattedDateAndTime(),
                            MissingModelId = plate.Id,
                            Latitude       = latitude,
                            Longitude      = longitude
                        };
                    }
                    RecognizedObject recognizedObject = new RecognizedObject()
                    {
                        Id        = plate.Id,
                        FirstName = plate.FirstName,
                        LastName  = plate.LastName,
                        Reason    = plate.Reason,
                        Type      = ModelType.Plate,
                        Message   = plate.NumberPlate,
                        LastSeen  = timestamp.DateTime.GetFormattedDateAndTime()
                    };
                    if (seenBefore && timestamp.DateTime > DateTime.UtcNow.ToUTC2().AddMinutes(-1))
                    {
                        timestamp.DateAndTime = DateTime.UtcNow.ToUTC2().GetFormattedDateAndTime();
                        _timestampRepository.Edit(timestamp);
                    }
                    else
                    {
                        _timestampRepository.Add(new Timestamp()
                        {
                            DateAndTime    = DateTime.UtcNow.ToUTC2().GetFormattedDateAndTime(),
                            MissingModelId = plate.Id,
                            Latitude       = latitude,
                            Longitude      = longitude
                        });
                    }
                    recognizedObject.TimestampId = _timestampRepository.GetLatestModelTimestamp(plate.Id).Id;
                    identifiedPlates.Add(recognizedObject);
                }
            });
            return(identifiedPlates);
        }
예제 #2
0
        public void Cache(RecognizedObjectResource recognizedResource)
        {
            var recognizedModel = new RecognizedObject()
            {
                Id        = recognizedResource.Id,
                Name      = recognizedResource.Name,
                ContentId = recognizedResource.Content.Id,
                Modified  = recognizedResource.Modified
            };
            var contentModel = new Content()
            {
                Id            = recognizedResource.Content.Id,
                Name          = recognizedResource.Content.Name,
                AssetBundleId = recognizedResource.Content.AssetBundle.Id,
                DllId         = recognizedResource.Content.Dll.Id,
                Modified      = recognizedResource.Content.Modified
            };

            if (recognizedResource.Content.Dll != null)
            {
                contentModel.DllId = recognizedResource.Content.Dll.Id;
            }
            var assetBundleModel = new AssetBundle()
            {
                Id       = recognizedResource.Content.AssetBundle.Id,
                Name     = recognizedResource.Content.AssetBundle.Name,
                Modified = recognizedResource.Content.AssetBundle.Modified
            };

            Dll dll = null;

            if (recognizedResource.Content?.Dll != null)
            {
                dll = new Dll()
                {
                    Id       = recognizedResource.Content.Dll.Id,
                    Name     = recognizedResource.Content.Dll.Name,
                    Modified = recognizedResource.Content.Dll.Modified
                };
            }

            using (var con = Connection)
            {
                con.Execute(recognizedObjectTable.InsertOrReplace(recognizedModel));
                con.Execute(contentTable.InsertOrReplace(contentModel));
                con.Execute(assetBundleTable.InsertOrReplace(assetBundleModel));

                if (dll != null)
                {
                    con.Execute(dllTable.InsertOrReplace(dll));
                }
            }
        }
예제 #3
0
        public async Task <List <RecognizedObject> > RecognizeAsync(string base64, double latitude, double longitude)
        {
            byte[] imgBytes;
            try
            {
                imgBytes = Convert.FromBase64String(base64);
            }
            catch
            {
                throw;
            }
            List <PersonWithSmile> result = await CallFaceAPIAsync(imgBytes);

            List <RecognizedObject> recognizedPersons = new List <RecognizedObject>();

            result.ForEach(personWithSmile =>
            {
                Timestamp timestamp = _timestampRepository.GetLatestModelTimestamp(personWithSmile.Person.Id);
                bool seenBefore     = true;
                if (timestamp == null || timestamp.DateAndTime == null)
                {
                    seenBefore = false;
                    timestamp  = new Timestamp()
                    {
                        DateAndTime    = DateTime.UtcNow.ToUTC2().GetFormattedDateAndTime(),
                        MissingModelId = personWithSmile.Person.Id,
                        Latitude       = latitude,
                        Longitude      = longitude,
                        Smile          = personWithSmile.Smile
                    };
                }
                RecognizedObject recognizedObject = new RecognizedObject()
                {
                    Id        = personWithSmile.Person.Id,
                    FirstName = personWithSmile.Person.FirstName,
                    LastName  = personWithSmile.Person.LastName,
                    Reason    = personWithSmile.Person.Reason,
                    Type      = ModelType.Person,
                    Message   = "",
                    Smile     = personWithSmile.Smile,
                    LastSeen  = timestamp.DateTime.GetFormattedDateAndTime()
                };
                if (seenBefore && timestamp.DateTime > DateTime.UtcNow.ToUTC2().AddMinutes(-1))
                {
                    timestamp.DateAndTime = DateTime.UtcNow.ToUTC2().GetFormattedDateAndTime();
                    timestamp.Latitude    = latitude;
                    timestamp.Longitude   = longitude;
                    timestamp.Smile       = personWithSmile.Smile;
                    _timestampRepository.Edit(timestamp);
                }
                else
                {
                    _timestampRepository.Add(new Timestamp()
                    {
                        DateAndTime    = DateTime.UtcNow.ToUTC2().GetFormattedDateAndTime(),
                        MissingModelId = personWithSmile.Person.Id,
                        Latitude       = latitude,
                        Longitude      = longitude,
                        Smile          = personWithSmile.Smile
                    });
                }
                recognizedObject.TimestampId = _timestampRepository.GetLatestModelTimestamp(personWithSmile.Person.Id).Id;
                recognizedPersons.Add(recognizedObject);
            });
            return(recognizedPersons);
        }