Example #1
0
 public SkiVideoProcessor(string videoUrl)
 {
     _sourceVideoUrl   = videoUrl;
     _storage          = new Storage();
     _factory          = new CoursePassFactory();
     _processedNotifer = new VideoProcessedNotifier();
 }
Example #2
0
        private static string CreateImage(string jsonPath, double clOffset, double rope,
                                          CourseCoordinates coords)
        {
            CoursePass        pass;
            CoursePassFactory factory = new CoursePassFactory();

            factory.CenterLineDegreeOffset = clOffset;
            factory.RopeLengthOff          = rope;
            factory.Course55Coordinates    = coords;

            if (jsonPath.StartsWith("http"))
            {
                pass = factory.FromUrl(jsonPath);
            }
            else
            {
                pass = factory.FromFile(jsonPath);
            }

            if (pass == null)
            {
                throw new ApplicationException($"Unable to create a pass for {jsonPath}");
            }

            string          imagePath = GetImagePath(jsonPath);
            CoursePassImage image     = new CoursePassImage(pass);
            Bitmap          bitmap    = image.Draw();

            bitmap.Save(imagePath, ImageFormat.Png);

            Logger.Log(string.Format("Gate precision == {0} for {1}", pass.GetGatePrecision(), jsonPath));
            Logger.Log("Wrote image to: " + imagePath);

            return(imagePath);
        }
Example #3
0
        private static CoursePass GetBestCoursePass(CoursePass pass)
        {
            CoursePass bestPass = CoursePassFactory.FitPass(pass.Measurements, pass.Course, pass.Rope);

            Console.WriteLine("Best pass is {0} CL offset.", bestPass.CenterLineDegreeOffset);
            return(bestPass);
        }
Example #4
0
        private Bitmap GetImage(string jsonUrl, double clOffset, double rope)
        {
            Storage storage = new Storage();
            string  http    = storage.BlobStorageUri.Replace("https:", "http:");
            string  https   = storage.BlobStorageUri;

            if (!(jsonUrl.StartsWith(http) || jsonUrl.StartsWith(https)))
            {
                if (jsonUrl.StartsWith("/"))
                {
                    jsonUrl = jsonUrl.TrimStart('/');
                }
                jsonUrl = storage.BlobStorageUri + "ski/" + jsonUrl;
            }

            CoursePassFactory factory = new CoursePassFactory()
            {
                CenterLineDegreeOffset = clOffset,
                RopeLengthOff          = rope,
                Course = GetCourseFromMetadata(storage, jsonUrl)
            };
            CoursePass pass = factory.FromUrl(jsonUrl);

            if (pass == null)
            {
                throw new ApplicationException($"Unable to create a pass for {jsonUrl}");
            }

            CoursePassImage image  = new CoursePassImage(pass);
            Bitmap          bitmap = image.Draw();

            return(bitmap);
        }
Example #5
0
        public void AddMetadataTest()
        {
            CoursePassFactory factory = new CoursePassFactory();
            string            json    = File.ReadAllText("./Video/GOPR0565.json");
            CoursePass        pass    = factory.FromJson(json);
            SkiVideoEntity    entity  = new SkiVideoEntity(URL, new DateTime(2018, 08, 24));

            Storage storage = new Storage();

            storage.AddMetadata(entity, json);
        }
Example #6
0
        private static string DownloadAndCreateImage(string url)
        {
            string          localPath = Storage.DownloadVideo(url);
            string          json      = Extract.ExtractMetadata(localPath);
            CoursePass      pass      = CoursePassFactory.FromJson(json);
            CoursePassImage image     = new CoursePassImage(pass);
            Bitmap          bitmap    = image.Draw();
            string          imagePath = localPath.Replace(".MP4", ".png");

            bitmap.Save(imagePath, ImageFormat.Png);
            return(imagePath);
        }
Example #7
0
        public IActionResult Get(string jsonUrl)
        {
            double centerLineOffset = 0;

            try
            {
                CoursePassFactory factory = new CoursePassFactory();
                centerLineOffset = factory.FitPass(jsonUrl);
                return(Content(centerLineOffset.ToString()));
            }
            catch (Exception e)
            {
                _logger.LogError("Unable to fit pass: " + e.Message);
                return(StatusCode(500));
            }
        }
Example #8
0
        private static string DownloadAndCreateImage(string url)
        {
            string     localPath = Storage.DownloadVideo(url);
            string     json      = Extract.ExtractMetadata(localPath);
            CoursePass pass      = new CoursePassFactory().FromJson(json);

            if (pass == null)
            {
                throw new ApplicationException($"Unable to create a pass for {url}");
            }

            CoursePassImage image     = new CoursePassImage(pass);
            Bitmap          bitmap    = image.Draw();
            string          imagePath = localPath.Replace(".MP4", ".png");

            bitmap.Save(imagePath, ImageFormat.Png);
            return(imagePath);
        }
        private Measurement GetMeasurement(SkiVideoEntity entity, double seconds)
        {
            List <Measurement> measurements = null;

            if (!string.IsNullOrWhiteSpace(entity.CourseName))
            {
                CoursePassFactory factory = new CoursePassFactory();
                CoursePass        pass    = factory.FromSkiVideo(entity);
                measurements = pass.Measurements;
            }
            else
            {
                WebClient client = new WebClient();
                string    json   = client.DownloadString(entity.JsonUrl);
                measurements = Measurement.DeserializeMeasurements(json);
            }

            Measurement measurement = measurements.
                                      FindHandleAtSeconds(seconds + entity.EntryTime);

            return(measurement);
        }
Example #10
0
        private static void OutputHandleSpeed(string jsonPath, double rope)
        {
            if (!jsonPath.StartsWith("http"))
            {
                throw new ApplicationException("Must pass http path to jsonUrl.");
            }

            CoursePassFactory factory = new CoursePassFactory();

            factory.RopeLengthOff = rope;
            CoursePass pass = factory.FromUrl(jsonPath);

            if (pass == null)
            {
                throw new ApplicationException($"Unable to create a pass for {jsonPath}");
            }

            foreach (var m in pass.Measurements)
            {
                Console.WriteLine($"{m.Timestamp.ToString("ss.fff")}, {m.HandleSpeedMps}");
            }
        }
Example #11
0
        private static string CreateImage(string jsonPath, double clOffset, double rope)
        {
            CoursePass pass;

            if (jsonPath.StartsWith("http"))
            {
                pass = CoursePassFactory.FromUrl(jsonPath, clOffset, rope);
            }
            else
            {
                pass = CoursePassFactory.FromFile(jsonPath, clOffset, Rope.Off(rope));
            }

            string          imagePath = GetImagePath(jsonPath);
            CoursePassImage image     = new CoursePassImage(pass);
            Bitmap          bitmap    = image.Draw();

            bitmap.Save(imagePath, ImageFormat.Png);

            Console.WriteLine("Gate precision == {0} for {1}", pass.GetGatePrecision(), jsonPath);

            return(imagePath);
        }
Example #12
0
        public IActionResult Get(string jsonUrl, double cl = 0, double rope = 15)
        {
            try
            {
                if (cl == 0)
                {
                    _logger.LogInformation("Attempting CenterLineOffset fit.");
                    CoursePassFactory factory = new CoursePassFactory();
                    cl = factory.FitPass(jsonUrl);
                }

                Bitmap image = GetImage(jsonUrl, cl, rope);
                using (var ms = new MemoryStream())
                {
                    image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    return(File(ms.ToArray(), "image/png"));
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Unable to get image. " + e.Message);
                return(StatusCode(500));
            }
        }