public static IEnumerable <PhotoData> Connect(ImageFolder f, List <MovementPoint> pointsList, int timeStepMilliseconds) { var pointsDates = pointsList.Select(p => p.Date); var firstPhotoDate = pointsDates.Min(); var lastPhotoDate = pointsDates.Max(); List <Photo> photos = new List <Photo>(); for (int i = 0; i < f.GetCount(); i++) { photos.Add(new Photo { Number = i, FileName = f.GetImg(i) }); } return(photos.Select(photo => { var photoDateTime = firstPhotoDate.AddMilliseconds(photo.Number * timeStepMilliseconds); var maxTimeRangeDiff = timeStepMilliseconds / 2; var closestPointInRange = pointsList .Where(point => Math.Abs((point.Date - photoDateTime).TotalMilliseconds) < maxTimeRangeDiff) .OrderBy(point => Math.Abs((point.Date - photoDateTime).TotalMilliseconds)) .FirstOrDefault(); if (closestPointInRange == null) { return null; } return new PhotoData { MovementPoint = closestPointInRange, Photo = photo }; }) .Where(pd => pd != null)); }
public string[] RecognizeAll(ImageFolder imf) { int count = imf.GetCount(); string[] result = new string[count]; for (int i = 0; i < count; i++) { var image = new Image <Gray, byte>(imf.GetImg(i)).Bytes; if (image.Length != 32 * 32) { result[0] = "wrong image size"; return(result); } if (net.Layers.Count == 0) { this.CreateCNN(); LoadCNN(path); } var dataShape = new Shape(32, 32, 1, 1); var data = new double[dataShape.TotalLength]; var dataVolume = BuilderInstance.Volume.From(data, dataShape); var j = 0; for (var y = 0; y < net.Layers[0].InputHeight; y++) { for (var x = 0; x < net.Layers[0].InputWidth; x++) { dataVolume.Set(x, y, 0, 0, image[j++]); } } net.Forward(dataVolume); var prediction = net.GetPrediction(); result[i] = GetClassNameFromNumber(prediction[0]); } return(result); }