Esempio n. 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);
        }
Esempio n. 2
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);
        }