示例#1
0
 public Tuple <TupleList, Image <int, T> > Run <T>(Image <double, T> image,
                                                   double scale                  = 0.8,
                                                   double sigmaScale             = 0.6,
                                                   double quantizationErrorBound = 2.0,
                                                   double angleThreshold         = 22.5,
                                                   double detectionThreshold     = 0.0,
                                                   double densityThreshold       = 0.7,
                                                   int numberOfBins              = 1024)
 {
     return(_errorHandler.Wrap(() =>
     {
         return _lineSegmentDetectorWrapper.Run(image, scale, sigmaScale, quantizationErrorBound, angleThreshold,
                                                detectionThreshold, densityThreshold, numberOfBins);
     }));
 }
        public void Run_SuccessfullyIdentifiesLineSegments()
        {
            var pgmImage = PgmService.Read(Resources.chairs);

            var result    = _lineSegmentDetector.Run(pgmImage);
            var lineImage = result.Item2;

            // Any non-zero value in the image is a line. Convert this to black and white
            // by simply setting the maximum value for all lines.
            var outputImage = new Image <double, int>(lineImage.Width, lineImage.Height, 1);

            for (var x = 0; x < outputImage.Width; x++)
            {
                for (var y = 0; y < outputImage.Height; y++)
                {
                    outputImage[x, y] = lineImage[x, y] > 0 ? 1 : 0;
                }
            }

            var newPgmImage = PgmService.Write(outputImage);
            var path        = Path.Combine(Directory.GetCurrentDirectory(), $"LineSegmentDetectionTest-{Guid.NewGuid()}.pgm");

            File.WriteAllBytes(path, newPgmImage);
        }