Exemplo n.º 1
0
 public void ShouldConvertToDouble()
 {
     Assert.AreEqual(1283.3, ImageStat.ToDouble("1,283.30kb"));
     Assert.AreEqual(283.3, ImageStat.ToDouble("283.30kb"));
     Assert.AreEqual(283.0, ImageStat.ToDouble("283kb"));
     Assert.AreEqual(1283.0, ImageStat.ToDouble("1,283kb"));
     Assert.AreEqual(0.0, ImageStat.ToDouble("0kb"));
 }
Exemplo n.º 2
0
 public void InsertImageStat(ImageStat imageStat)
 {
     _dbConnection.ExecuteAsync(
         "insert into ImageStat (rectangles, luminance, blue, red, green, cb,cr,y, pixels, imagePath, BlueMax,BlueMin,GreenMax,GreenMin,RedMax,RedMin, length) values (@rectangles, @luminance, @blue, @red, @green, @cb, @cr, @y, @pixels, @imagePath,@BlueMax,@BlueMin,@GreenMax,@GreenMin,@RedMax,@RedMin,@length)",
         imageStat);
 }
        public ImageStat GetImageStats(string fullPath, FormOptions options)
        {
            if (cancelAnalysis)
            {
                return(null);
            }

            Messaging.Talk($"{fullPath}");

            ImageStat res = null;

            try
            {
                res = new ImageStat();


                res.ImagePath = fullPath.Replace(options.ImagesSoureDirectory, string.Empty);
                res.Length    = _fileSystemService.GetFileLength(fullPath);

                // load file
                using (var image = _imageService.GetThumb(fullPath, _configService.TempBitmapHeight))
                {
                    // hsl
                    //Talk($"{fullPath} HSL... ");
                    var statsHSL = new ImageStatisticsHSL(image);
                    res.Luminance = (decimal)statsHSL.Luminance.Median;
                    res.Pixels    = statsHSL.PixelsCount;

                    // rgb
                    //Talk($"{fullPath} RGB... ");
                    var stats = new ImageStatistics(image);
                    res.Blue   = stats.Blue.Median;
                    res.Red    = stats.Red.Median;
                    res.Green  = stats.Green.Median;
                    res.Pixels = stats.PixelsCount;

                    res.BlueMax  = stats.Blue.Max;
                    res.RedMax   = stats.Red.Max;
                    res.GreenMax = stats.Green.Max;

                    res.BlueMin  = stats.Blue.Min;
                    res.RedMin   = stats.Red.Min;
                    res.GreenMin = stats.Green.Min;

                    // YCbCr
                    // Talk($"{fullPath} YCbCr... ");
                    var statsYCbCr = new ImageStatisticsYCbCr(image);
                    res.Cb = statsYCbCr.Cb.Mean;
                    res.Cr = statsYCbCr.Cr.Mean;
                    res.Y  = statsYCbCr.Y.Mean;
                }
            }
            catch (Exception e)
            {
                res = null;
                Messaging.Talk($"{fullPath} Error! {e.Message}... ");
                Messaging.RaiseProgress(null, new ProgressBarEventArgs {
                    EventKindOf = EventKind.IncrementError
                });
            }
            finally
            {
                Messaging.RaiseProgress(null, new ProgressBarEventArgs {
                    EventKindOf = EventKind.Increment
                });
            }

            return(res);
        }