Exemplo n.º 1
0
        private void IdentifyBorders()
        {
            var img = OpenCvSharp.Mat.FromImageData(originalImage);

            ColorToHSV(screenColorPicker.Color, out double pixelHue, out double pixelSaturation, out double pixelValue);

            // normalize image
            var hsv_img = img.CvtColor(OpenCvSharp.ColorConversionCodes.BGR2HSV);

            var precision = (byte)trackBarPrecision.Value;
            
            var pixel_low = new OpenCvSharp.Scalar(pixelHue - (precision * (179.0 / 100.0 / 2.0)), pixelSaturation - (precision * (255.0 / 100.0 / 2.0)), pixelValue - (precision * (255.0 / 100.0 / 2.0)));
            var pixel_high = new OpenCvSharp.Scalar(pixelHue + (precision * (179.0 / 100.0 / 2.0)), pixelSaturation + (precision * (255.0 / 100.0 / 2.0)), pixelValue + (precision * (255.0 / 100.0 / 2.0)));

            var curr_mask = hsv_img.InRange(pixel_low, pixel_high);

            var hsv_img_masked = hsv_img.SetTo(OpenCvSharp.InputArray.Create(new byte[] { 70, 255, 255 }), curr_mask);
            var img_rgb = hsv_img_masked.CvtColor(OpenCvSharp.ColorConversionCodes.HSV2RGB);            

            var output = new Bitmap(new MemoryStream(img_rgb.ToBytes()));
            pictureBoxChanged.Image = output;
            pictureBoxChanged.Refresh();
        }
Exemplo n.º 2
0
 public static Scalar ToScalar(this OpenCvSharp.Scalar s)
 {
     return(new Scalar(s.Val0, s.Val1, s.Val2, s.Val3));
 }