예제 #1
0
        public void op_BitwiseAnd_IplImageScalar_ReturnsBitwiseConjunctionOfIplImageAndScalar()
        {
            var image  = CreateEye(depth: IplDepth.S32);
            var scalar = Scalar.All(ScalarValue);

            Assert.AreEqual(EyeValue, (image & scalar).GetReal(0, 0));
        }
예제 #2
0
        public void op_BitwiseOr_ScalarIplImage_ReturnsBitwiseDisjunctionOfIplImageAndScalar()
        {
            var scalar = Scalar.All(ScalarValue);
            var image  = CreateEye(depth: IplDepth.S32);

            Assert.AreEqual(ScalarValue, (scalar | image).GetReal(0, 0));
        }
예제 #3
0
        public void op_Subtraction_ScalarIplImage_ReturnsSubtractionOfIplImageAndScalar()
        {
            var scalar = Scalar.All(ScalarValue);
            var image  = CreateEye();

            Assert.AreEqual(ScalarValue - EyeValue, (scalar - image).GetReal(0, 0));
        }
예제 #4
0
        public void op_ExclusiveOr_ScalarIplImage_ReturnsExclusiveOrOnIplImageAndScalar()
        {
            var scalar = Scalar.All(ScalarValue);
            var image  = CreateEye(depth: IplDepth.S32);

            Assert.AreEqual((int)EyeValue ^ (int)ScalarValue, (scalar ^ image).GetReal(0, 0));
        }
예제 #5
0
        IplImage CreateEye(int size = 3, double value = EyeValue, IplDepth depth = IplDepth.F64)
        {
            var eye = new IplImage(new Size(size, size), depth, 1);

            CV.SetIdentity(eye, Scalar.All(value));
            return(eye);
        }
예제 #6
0
        public void op_Addition_ScalarIplImage_ReturnsAdditionOfIplImageAndScalar()
        {
            var scalar = Scalar.All(ScalarValue);
            var image  = CreateEye();

            Assert.AreEqual(EyeValue + ScalarValue, (scalar + image).GetReal(0, 0));
        }
예제 #7
0
        public void ExtractAnchors(string sourceFileName,
                                   GradientOperator gradientOperator, int gradientThreshold,
                                   int anchorScanInterval, int anchorThreshold)
        {
            // Arrange
            var source    = LoadImage(sourceFileName);
            var rows      = source.Size.Height;
            var columns   = source.Size.Width;
            var gradients = new Gradients(rows, columns);

            gradients.ComputeGradient(source, gradientOperator, gradientThreshold);

            // Act
            var anchors = gradients.ExtractAnchors(anchorScanInterval, anchorThreshold);

            // Assert
            var anchorMap = new Mat(rows, columns, Depth.U8, 1);

            anchorMap.Set(Scalar.All(0));
            foreach (var anchor in anchors)
            {
                anchorMap.SetReal(anchor.Y, anchor.X, 255);
            }
            var resultFileName = Path.Combine("Output", "ExtractAnchors", $"{Path.GetFileNameWithoutExtension(sourceFileName)}_{gradientOperator}_{gradientThreshold}_{anchorScanInterval}_{anchorThreshold}.png");

            SaveImage(anchorMap, resultFileName);
        }
예제 #8
0
        public static unsafe Mat GetAccMax(Mat matAcc)
        {
            int   nsurf    = matAcc.Size(0);
            int   nrow     = matAcc.Size(1);
            int   ncol     = matAcc.Size(2);
            long  stepSurf = matAcc.Step(0);
            long  stepRow  = matAcc.Step(1);
            byte *buf      = (byte *)matAcc.Data;

            var   matAccMax = new Mat(nrow, ncol, matAcc.Type(), Scalar.All(0));
            byte *bufAccMax = matAccMax.DataPointer;

            for (int isurf = 0; isurf < nsurf; isurf++)
            {
                for (int irow = 0; irow < nrow; irow++)
                {
                    ushort *pt    = (ushort *)&buf[stepSurf * isurf + stepRow * irow];
                    ushort *ptMax = (ushort *)&bufAccMax[stepRow * irow];
                    for (int icol = 0; icol < ncol; icol++, pt++, ptMax++)
                    {
                        if (*pt > *ptMax)
                        {
                            *ptMax = *pt;
                        }
                    }
                }
            }
            return(matAccMax);
        }
예제 #9
0
        /// <summary>
        /// Applies an affine transformation to an image.
        /// </summary>
        /// <param name="src">Source image. CV_8U , CV_16U , CV_32S , or CV_32F depth and 1, 3, or 4 channels are
        /// supported.</param>
        /// <param name="dst">Destination image with the same type as src . The size is dsize .</param>
        /// <param name="m">*2x3* transformation matrix.</param>
        /// <param name="dsize">Size of the destination image.</param>
        /// <param name="flags">Combination of interpolation methods (see resize) and the optional flag
        /// WARP_INVERSE_MAP specifying that M is an inverse transformation(dst=\>src ). Only
        /// INTER_NEAREST, INTER_LINEAR, and INTER_CUBIC interpolation methods are supported.</param>
        /// <param name="borderMode">pixel extrapolation method; when borderMode=BORDER_TRANSPARENT,
        /// it means that the pixels in the destination image corresponding to the "outliers"
        /// in the source image are not modified by the function.</param>
        /// <param name="borderValue">value used in case of a constant border; by default, it is 0.</param>
        /// <param name="stream">Stream for the asynchronous version.</param>
        public static void warpAffine(
            InputArray src, OutputArray dst, InputArray m, Size dsize,
            InterpolationFlags flags = InterpolationFlags.Linear,
            BorderTypes borderMode   = BorderTypes.Constant, Scalar?borderValue = null, Stream stream = null)
        {
            if (src == null)
            {
                throw new ArgumentNullException(nameof(src));
            }
            if (dst == null)
            {
                throw new ArgumentNullException(nameof(dst));
            }
            if (m == null)
            {
                throw new ArgumentNullException(nameof(m));
            }
            src.ThrowIfDisposed();
            dst.ThrowIfDisposed();
            m.ThrowIfDisposed();
            Scalar borderValue0 = borderValue.GetValueOrDefault(Scalar.All(0));

            NativeMethods.cuda_warping_warpAffine(src.CvPtr, dst.CvPtr, m.CvPtr, dsize, (int)flags, (int)borderMode, borderValue0, stream?.CvPtr ?? Stream.Null.CvPtr);
            GC.KeepAlive(src);
            GC.KeepAlive(dst);
            GC.KeepAlive(m);
            dst.Fix();
        }
예제 #10
0
        public static void teste()
        {
            using (var src = new Mat(new Size(128, 128), MatType.CV_8U, Scalar.All(255)))
                using (var dst = new Mat())
                {
                    for (var y = 0; y < src.Height; y++)
                    {
                        for (var x = 0; x < src.Width; x++)
                        {
                            var color = src.Get <Vec3b>(y, x);
                            var temp  = color.Item0;
                            color.Item0 = color.Item2; // B <- R
                            color.Item2 = temp;        // R <- B
                            src.Set(y, x, color);
                        }
                    }

                    src.CopyTo(dst);

                    using (var window = new Window("window", image: dst, flags: WindowMode.AutoSize))
                    {
                        Cv2.WaitKey();
                    }
                }
        }
예제 #11
0
        public void CalcHist()
        {
            using var src = new Mat(@"_data/image/mandrill.png", ImreadModes.Grayscale);

            using var hist = new Mat();
            Cv2.CalcHist(
                images: new[] { src },
                channels: new[] { 0 },
                mask: null,
                hist: hist,
                dims: 1,
                histSize: new[] { 256 },
                ranges: new[] { new Rangef(0, 256) });

            if (Debugger.IsAttached)
            {
                const int histW = 512;
                const int histH = 400;
                var       binW  = Math.Round((double)histW / 256);
                using var histImage = new Mat(histH, histW, MatType.CV_8UC3, Scalar.All(0));
                Cv2.Normalize(hist, hist, 0, histImage.Rows, NormTypes.MinMax, -1);

                for (int i = 0; i < 256; i++)
                {
                    var pt1 = new Point2d(binW * (i - 1), histH - Math.Round(hist.At <float>(i - 1)));
                    var pt2 = new Point2d(binW * (i), histH - Math.Round(hist.At <float>(i)));
                    Cv2.Line(
                        histImage, (Point)pt1, (Point)pt2,
                        Scalar.Red, 1, LineTypes.Link8);
                }

                Window.ShowImages(src, histImage);
            }
        }
예제 #12
0
        // Function calculates PSD(Power spectrum density) by fft with two flags
        // flag = 0 means to return PSD
        // flag = 1 means to return log(PSD)
        public static void calcPSD(ref Mat inputImg, ref Mat outputImg, bool flag = false)
        {
            Mat[] planes   = { new Mat <float>(inputImg.Clone()), Mat.Zeros(inputImg.Size(), MatType.CV_32F) };
            Mat   complexI = new Mat();

            Cv2.Merge(planes, complexI);
            Cv2.Dft(complexI, complexI);
            Cv2.Split(complexI, out planes);            // planes[0] = Re(DFT(I)), planes[1] = Im(DFT(I))
            planes[0].Set <float>(0, 0);
            planes[1].Set <float>(0, 0);
            // compute the PSD = sqrt(Re(DFT(I))^2 + Im(DFT(I))^2)^2
            Mat imgPSD = new Mat();

            Cv2.Magnitude(planes[0], planes[1], imgPSD);        //imgPSD = sqrt(Power spectrum density)
            Cv2.Pow(imgPSD, 2, imgPSD);                         //it needs ^2 in order to get PSD
            outputImg = imgPSD;
            // logPSD = log(1 + PSD)
            if (flag)
            {
                Mat imglogPSD = new Mat();
                imglogPSD = imgPSD + Scalar.All(1);
                Cv2.Log(imglogPSD, imglogPSD);
                outputImg = imglogPSD;
            }
        }
예제 #13
0
        public void RowMatCopyTo()
        {
            using var lenna = Image("lenna.png", ImreadModes.Grayscale);
            using var mat   = new Mat(lenna.Rows, lenna.Cols, MatType.CV_8UC1, Scalar.All(0));

            using var lenna10 = lenna.Row(10);
            using var mat10   = mat.Row(10);

            /*
             * testOutputHelper.WriteLine("Data={0}, DataStart={1}, DataEnd={2}", lenna.Data, lenna.DataStart, lenna.DataEnd);
             * testOutputHelper.WriteLine("Data={0}, DataStart={1}, DataEnd={2}", lenna10.Data, lenna10.DataStart, lenna10.DataEnd);
             * testOutputHelper.WriteLine("Data={0}, DataStart={1}, DataEnd={2}", mat.Data, mat.DataStart, mat.DataEnd);
             * testOutputHelper.WriteLine("Data={0}, DataStart={1}, DataEnd={2}", mat10.Data, mat10.DataStart, mat10.DataEnd);
             * //*/
            lenna10.CopyTo(mat10);

            for (int r = 0; r < mat.Rows; r++)
            {
                for (int c = 0; c < mat.Cols; c++)
                {
                    var exp = (r == 10) ? lenna.Get <byte>(r, c) : 0;
                    Assert.Equal(exp, mat.Get <byte>(r, c));
                }
            }
        }
예제 #14
0
        private void button5_Click(object sender, EventArgs e)
        {
            Mat    src = new Mat(fileName);
            int    Width = 260, Height = pictureBox5.Height;
            double minVal, maxVal;
            Mat    hist = new Mat();

            int[]    hdims  = { 256 };
            Rangef[] ranges = { new Rangef(0, 256), };

            src = src.CvtColor(ColorConversionCodes.BGR2GRAY);
            Cv2.EqualizeHist(src, src);
            Mat render = new Mat(new OpenCvSharp.Size(Width, Height), MatType.CV_8UC3, Scalar.All(255));

            Cv2.CalcHist(new Mat[] { src }, new int[] { 0 }, null, hist, 1, hdims, ranges);
            Scalar color = Scalar.All(2);

            Cv2.MinMaxLoc(hist, out minVal, out maxVal);

            hist = hist * (maxVal != 0 ? Height / maxVal : 0.0);
            for (int j = 0; j < hdims[0]; ++j)
            {
                render.Rectangle(
                    new OpenCvSharp.Point(j * (int)((double)Width / hdims[0]), render.Rows - (int)(hist.Get <float>(j))),
                    new OpenCvSharp.Point((j + 1) * (int)((double)Width / hdims[0]), render.Rows),
                    color,
                    -1);
            }

            src = src.CvtColor(ColorConversionCodes.GRAY2BGR);
            Bitmap bp = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(render);

            pictureBox5.Image = bp;
            showFilter(src, "gray equalize");
        }
예제 #15
0
        public void OnCameraViewStarted(int width, int height)
        {
            mIntermediateMat = new Mat();
            mSize0           = new Size();
            mChannels        = new MatOfInt[] { new MatOfInt(0), new MatOfInt(1), new MatOfInt(2) };
            mBuff            = new float[mHistSizeNum];
            mHistSize        = new MatOfInt(mHistSizeNum);
            mRanges          = new MatOfFloat(0f, 256f);
            mMat0            = new Mat();
            mColorsRGB       = new Scalar[] { new Scalar(200, 0, 0, 255), new Scalar(0, 200, 0, 255), new Scalar(0, 0, 200, 255) };
            mColorsHue       = new Scalar[] {
                new Scalar(255, 0, 0, 255), new Scalar(255, 60, 0, 255), new Scalar(255, 120, 0, 255), new Scalar(255, 180, 0, 255), new Scalar(255, 240, 0, 255),
                new Scalar(215, 213, 0, 255), new Scalar(150, 255, 0, 255), new Scalar(85, 255, 0, 255), new Scalar(20, 255, 0, 255), new Scalar(0, 255, 30, 255),
                new Scalar(0, 255, 85, 255), new Scalar(0, 255, 150, 255), new Scalar(0, 255, 215, 255), new Scalar(0, 234, 255, 255), new Scalar(0, 170, 255, 255),
                new Scalar(0, 120, 255, 255), new Scalar(0, 60, 255, 255), new Scalar(0, 0, 255, 255), new Scalar(64, 0, 255, 255), new Scalar(120, 0, 255, 255),
                new Scalar(180, 0, 255, 255), new Scalar(255, 0, 255, 255), new Scalar(255, 0, 215, 255), new Scalar(255, 0, 85, 255), new Scalar(255, 0, 0, 255)
            };
            mWhilte = Scalar.All(255);
            mP1     = new Point();
            mP2     = new Point();

            // Fill sepia kernel
            mSepiaKernel = new Mat(4, 4, CvType.Cv32f);
            mSepiaKernel.Put(0, 0, /* R */ 0.189f, 0.769f, 0.393f, 0f);
            mSepiaKernel.Put(1, 0, /* G */ 0.168f, 0.686f, 0.349f, 0f);
            mSepiaKernel.Put(2, 0, /* B */ 0.131f, 0.534f, 0.272f, 0f);
            mSepiaKernel.Put(3, 0, /* A */ 0.000f, 0.000f, 0.000f, 1f);
        }
예제 #16
0
 public Rectangle()
 {
     Thickness = 1;
     Color     = Scalar.All(255);
     LineType  = LineFlags.Connected8;
     Shift     = 0;
 }
예제 #17
0
        public void FindContours()
        {
            using var src = Image("markers_6x6_250.png", ImreadModes.Grayscale);
            Cv2.BitwiseNot(src, src);
            Cv2.FindContours(
                src,
                out var contours,
                out var hierarchy,
                RetrievalModes.External,
                ContourApproximationModes.ApproxSimple);

            Assert.NotEmpty(contours);
            Assert.NotEmpty(hierarchy);

            Assert.All(contours, contour =>
            {
                Assert.Equal(4, contour.Length);
            });

            if (Debugger.IsAttached)
            {
                using var view = new Mat(src.Size(), MatType.CV_8UC3, Scalar.All(0));
                Cv2.DrawContours(view, contours, -1, Scalar.Red);
                Window.ShowImages(src, view);
            }
        }
        //(practice)
        static public Mat Enlarge(this Mat Uimg, double alphaX, double alphaY)
        {
            Size sz = Uimg.Size();
            int  W = sz.Width, H = sz.Height, h2 = H / 2;
            Mat  UimgD = new Mat(sz, MatType.CV_8UC1, Scalar.All(255));

            unsafe {
                byte *S = Uimg.DataPointer;
                byte *D = UimgD.DataPointer;
                for (int y = 0; y < H; y++)
                {
                    int yy = (int)((y - h2) / alphaY + 0.5 + h2);
                    if (yy < 0 || yy >= H)
                    {
                        continue;
                    }
                    for (int x = 0; x < W; x++)
                    {
                        int xx = (int)(x / alphaX + 0.5);
                        if (xx < 0 || xx >= W - 1)
                        {
                            continue;
                        }
                        D[y * W + x] = S[yy * W + xx];
                    }
                }
            }

            return(UimgD);
        }
예제 #19
0
        /// <summary>
        /// Applies a generic geometrical transformation to an image.
        /// </summary>
        /// <param name="src">Source image.</param>
        /// <param name="dst">Destination image with the size the same as xmap and the type the same as src .</param>
        /// <param name="map1">X values. Only CV_32FC1 type is supported.</param>
        /// <param name="map2">Y values. Only CV_32FC1 type is supported.</param>
        /// <param name="interpolation">Interpolation method (see resize ). INTER_NEAREST , INTER_LINEAR and
        /// INTER_CUBIC are supported for now.</param>
        /// <param name="borderMode">Pixel extrapolation method (see borderInterpolate ). BORDER_REFLECT101 ,
        /// BORDER_REPLICATE , BORDER_CONSTANT , BORDER_REFLECT and BORDER_WRAP are supported for now.</param>
        /// <param name="borderValue">Value used in case of a constant border. By default, it is 0.</param>
        /// <param name="stream">Stream for the asynchronous version.</param>
        public static void remap(
            InputArray src, OutputArray dst, InputArray map1, InputArray map2,
            InterpolationFlags interpolation = InterpolationFlags.Linear,
            BorderTypes borderMode           = BorderTypes.Constant, Scalar?borderValue = null, Stream stream = null)
        {
            if (src == null)
            {
                throw new ArgumentNullException(nameof(src));
            }
            if (dst == null)
            {
                throw new ArgumentNullException(nameof(dst));
            }
            if (map1 == null)
            {
                throw new ArgumentNullException(nameof(map1));
            }
            if (map2 == null)
            {
                throw new ArgumentNullException(nameof(map2));
            }
            src.ThrowIfDisposed();
            dst.ThrowIfNotReady();
            map1.ThrowIfDisposed();
            map2.ThrowIfDisposed();
            Scalar borderValue0 = borderValue.GetValueOrDefault(Scalar.All(0));

            NativeMethods.cuda_warping_remap(src.CvPtr, dst.CvPtr, map1.CvPtr, map2.CvPtr, (int)interpolation, (int)borderMode
                                             , borderValue0, stream?.CvPtr ?? Stream.Null.CvPtr);
            GC.KeepAlive(src);
            GC.KeepAlive(dst);
            dst.Fix();
            GC.KeepAlive(map1);
            GC.KeepAlive(map2);
        }
예제 #20
0
        public void MatIndexerByte()
        {
            byte value = 123;

            using var img  = new Mat(new Size(10, 10), MatType.CV_8UC1, Scalar.All(value));
            using var imgB = new Mat <byte>(img);
            var indexer              = imgB.GetIndexer();
            var genericIndexer       = img.GetGenericIndexer <byte>();
            var unsafeGenericIndexer = img.GetUnsafeGenericIndexer <byte>();

            Assert.Equal(value, indexer[0, 0]);
            Assert.Equal(value, genericIndexer[0, 0]);
            Assert.Equal(value, unsafeGenericIndexer[0, 0]);

            Assert.Equal(value, indexer[5, 7]);
            Assert.Equal(value, genericIndexer[5, 7]);
            Assert.Equal(value, unsafeGenericIndexer[5, 7]);

            indexer[3, 4] = 1;
            Assert.Equal(1, img.Get <byte>(3, 4));
            genericIndexer[3, 4] = 2;
            Assert.Equal(2, img.Get <byte>(3, 4));
            unsafeGenericIndexer[3, 4] = 3;
            Assert.Equal(3, img.Get <byte>(3, 4));
        }
예제 #21
0
        public Mat Detect(Mat input)
        {
            var canny  = input.Blur(new Size(3, 3)).Canny(Threshold, Threshold * Ratio);
            var output = new Mat(canny.Size(), canny.Type(), Scalar.All(0));

            input.CopyTo(output, canny);
            return(output);
        }
예제 #22
0
파일: Ellipse.cs 프로젝트: aalmada/bonsai
 public Ellipse()
 {
     EndAngle  = 360;
     Thickness = 1;
     Color     = Scalar.All(255);
     LineType  = LineFlags.Connected8;
     Shift     = 0;
 }
예제 #23
0
        public override void Apply(Mat input)
        {
            _start = DateTime.Now;
            Input  = input;
            Mat hsv         = new Mat();
            Mat ycrcb       = new Mat();
            Mat hsv_mask    = new Mat(input.Size(), MatType.CV_8UC1, Scalar.All(0));
            Mat ycrcb_mask  = new Mat(input.Size(), MatType.CV_8UC1, Scalar.All(0));
            Mat global_mask = new Mat(input.Size(), MatType.CV_8UC1, Scalar.All(0));


            //Cv2.CvtColor(hsv, hsv, ColorConversionCodes.BGR2HSV);
            //Cv2.CvtColor(ycrcb, ycrcb, ColorConversionCodes.BGR2HSV);
            if (_config.HSVThresholdConfig.IsActive)
            {
                Cv2.CopyTo(input, hsv);
                HSVFilter         hsvFilter    = new HSVFilter();
                HSVThresoldFilter hsvThreshold = new HSVThresoldFilter(_config.HSVThresholdConfig);
                hsvFilter.Apply(hsv);
                hsvThreshold.Apply(hsvFilter.Output);
                Cv2.CopyTo(hsvThreshold.Output, hsv_mask);
            }
            else
            {
                hsv_mask = new Mat(input.Size(), MatType.CV_8UC1, Scalar.All(255));
            }
            if (_config.YCrCbThresholdConfig.IsActive)
            {
                Cv2.CopyTo(input, ycrcb);
                YCrCbFilter    ycrcbFilter    = new YCrCbFilter();
                YCrCbThreshold ycrcbthreshold = new YCrCbThreshold(_config.YCrCbThresholdConfig);
                ycrcbFilter.Apply(ycrcb);
                ycrcbthreshold.Apply(ycrcbFilter.Output);
                Cv2.CopyTo(ycrcbthreshold.Output, ycrcb_mask);
            }
            else
            {
                ycrcb_mask = new Mat(input.Size(), MatType.CV_8UC1, Scalar.All(255));
            }


            Cv2.BitwiseAnd(hsv_mask, ycrcb_mask, global_mask);


            Cv2.CopyTo(global_mask, Output);
            //Cv2.CopyTo(input, Output, global_mask);


            //if (IsActive)
            //{
            //OpenCvSharp.Cv2.InRange(input, new OpenCvSharp.Scalar(_config.HSVThresholdConfig.H.Min, _config.HSVThresholdConfig.S.Min, _config.HSVThresholdConfig.V.Min), new OpenCvSharp.Scalar(_config.HSVThresholdConfig.H.Max, _config.HSVThresholdConfig.S.Max, _config.HSVThresholdConfig.V.Max), Output);
            //}
            //else
            //{
            //    OpenCvSharp.Cv2.CopyTo(input, Output);
            //}
            base.Apply(input);
        }
예제 #24
0
        public Mat Test(byte[] file, string tipo)
        {
            var src = Mat.FromImageData(file, ImreadModes.Color);
            // Histogram view
            const int Width = 260, Height = 200;
            var       render = new Mat(new Size(Width, Height), MatType.CV_8UC3, Scalar.All(255));

            // Calculate histogram
            var hist = new Mat();

            int[]    hdims  = { 256 };                 // Histogram size for each dimension
            Rangef[] ranges = { new Rangef(0, 256), }; // min/max
            Cv2.CalcHist(
                new Mat[] { src },
                new int[] { 0 },
                null,
                hist,
                1,
                hdims,
                ranges);

            // Get the max value of histogram
            double minVal, maxVal;

            Cv2.MinMaxLoc(hist, out minVal, out maxVal);

            var color = Scalar.All(100);

            // Scales and draws histogram
            hist = hist * (maxVal != 0 ? Height / maxVal : 0.0);

            var data = new List <Graph>();

            for (int j = 0; j < hdims[0]; ++j)
            {
                int binW = (int)((double)Width / hdims[0]);

                var x = j * binW;
                var y = render.Rows - (int)(hist.Get <float>(j));
                //using (var con = new BaseRepository())
                //    con.Execute($"INSERT INTO Valores  VALUEs ({x}, {y}, '{tipo}')");

                //    CreateTextFile($"{x} - {y}");

                render.Rectangle(
                    new Point(j * binW, render.Rows - (int)(hist.Get <float>(j))),
                    new Point((j + 1) * binW, render.Rows),
                    color, -1);
            }

            //using (new Window("Image", WindowMode.AutoSize | WindowMode.FreeRatio, src))
            //using (new Window("Histogram", WindowMode.AutoSize | WindowMode.FreeRatio, render))
            //{
            //    Cv2.WaitKey();
            //}

            return(hist);
        }
예제 #25
0
        public void RectangleShift()
        {
            using var mat = new Mat(300, 300, MatType.CV_8UC3, Scalar.All(0));
            Cv2.Rectangle(mat, new Rect(10, 20, 100, 200), Scalar.Red, -1, LineTypes.Link8, 0);
            Cv2.Rectangle(mat, new Rect(10, 20, 100, 200), Scalar.Green, -1, LineTypes.Link8, 1);
            Cv2.Rectangle(mat, new Rect(10, 20, 100, 200), Scalar.Blue, -1, LineTypes.Link8, 2);

            ShowImagesWhenDebugMode(mat);
        }
예제 #26
0
 public void ConvertScaleAbs_DestinationArrHasCorrectlyScaledElements()
 {
     arr[0, 0] = Scalar.All(1);
     using (var arr2 = CreateArr(1, Depth.U8))
     {
         CV.ConvertScaleAbs(arr, arr2, 5, 1);
         Assert.AreEqual(6, arr2[0, 0].Val0);
     }
 }
예제 #27
0
        public void Sort_DestinationArrHasSortedElements()
        {
            arr[0, 0] = Scalar.All(2);
            arr[0, 1] = Scalar.All(1);
            var arr2 = CreateArr();

            CV.Sort(arr, arr2);
            Assert.AreEqual(1, arr2[0, 0].Val0);
            Assert.AreEqual(2, arr2[0, 1].Val0);
        }
예제 #28
0
파일: Program.cs 프로젝트: wikibook/opencv4
        static void Main(string[] args)
        {
            Scalar s1 = new Scalar(255, 127);
            Scalar s2 = Scalar.Yellow;
            Scalar s3 = Scalar.All(99);

            Console.WriteLine(s1);
            Console.WriteLine(s2);
            Console.WriteLine(s3);
        }
예제 #29
0
        public override void Show(object value)
        {
            var contours = (Contours)value;
            var image    = visualizer.VisualizerImage;

            if (image != null && contours.FirstContour != null)
            {
                CV.DrawContours(image, contours.FirstContour, Scalar.All(255), Scalar.All(128), 2);
            }
        }
예제 #30
0
        public void Run()
        {
            Mat src = Cv2.ImRead(FilePath.Image.Lenna, ImreadModes.GrayScale);

            // Histogram view
            const int Width = 260, Height = 200;
            Mat       render = new Mat(new Size(Width, Height), MatType.CV_8UC3, Scalar.All(255));

            // Calculate histogram
            Mat hist = new Mat();

            int[]    hdims  = { 256 };                 // Histogram size for each dimension
            Rangef[] ranges = { new Rangef(0, 256), }; // min/max
            Cv2.CalcHist(
                new Mat[] { src },
                new int[] { 0 },
                null,
                hist,
                1,
                hdims,
                ranges);

            // Get the max value of histogram
            double minVal, maxVal;

            Cv2.MinMaxLoc(hist, out minVal, out maxVal);

            Scalar color = Scalar.All(100);

            // Scales and draws histogram
            hist = hist * (maxVal != 0 ? Height / maxVal : 0.0);
            for (int j = 0; j < hdims[0]; ++j)
            {
                int binW = (int)((double)Width / hdims[0]);
                render.Rectangle(
                    new Point(j * binW, render.Rows),
                    new Point((j + 1) * binW, render.Rows - (int)(hist.Get <float>(j))),
                    color,
                    -1);


                // render.Rectangle(
                //new Point(j * binW, render.Rows),
                //new Point((j + 1) * binW, render.Rows),
                //color,
                //-1);
            }

            using (new Window("Image", WindowMode.AutoSize | WindowMode.FreeRatio, src))
                using (new Window("Histogram", WindowMode.AutoSize | WindowMode.FreeRatio, render))
                {
                    Cv2.WaitKey();
                }
        }