Ejemplo n.º 1
0
        public static void QrCodeTest()
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

            var matGray = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2GRAY);

            Glb.DrawMatAndHist1(matGray);

            QRCodeDetector detector = new QRCodeDetector();

            Point2f[] points;
            string    text = detector.DetectAndDecode(matGray, out points);

            Console.WriteLine("points : " + string.Join(",", points.Select(pt => pt.ToString())));
            Console.WriteLine(text);

            var matRet = matGray.CvtColor(ColorConversionCodes.GRAY2BGR);
            var pts    = points.Select(pt => new OpenCvSharp.Point(pt.X, pt.Y));
            var ptss   = Enumerable.Repeat(pts, 1);

            matRet.Polylines(ptss, true, Scalar.Lime);
            Glb.DrawMatAndHist2(matRet);

            matGray.Dispose();
            matRet.Dispose();
        }
Ejemplo n.º 2
0
        public static void Blob_Ipp()
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

            var matThr = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2GRAY).Threshold(128, 255, ThresholdTypes.Otsu);

            MyBlobs blobs = new MyBlobs();

            Stopwatch sw = Stopwatch.StartNew();

            blobs.LabelIpp(matThr.Data, matThr.Width, matThr.Height, (int)matThr.Step());
            sw.Stop();
            Console.WriteLine("=> Label Time: {0}ms", sw.ElapsedMilliseconds);

            var matDst = new Mat(Glb.matSrc.Rows, Glb.matSrc.Cols, MatType.CV_8UC3);

            matDst.SetTo(Scalar.Black);
            Glb.TimerStart();
            MyBlobRenderer.RenderBlobs(blobs, matDst);
            Console.WriteLine("=> Render Time: {0}ms", Glb.TimerStop());

            Console.WriteLine("=> Blob Count: {0}", blobs.Blobs.Count);

            Glb.DrawMatAndHist1(matThr);
            Glb.DrawMatAndHist2(matDst);

            matThr.Dispose();
            matDst.Dispose();
        }
Ejemplo n.º 3
0
        public static void DistanceTransform(bool negative = false, DistanceTypes distanceType = DistanceTypes.L2, DistanceMaskSize distanceMaskSize = DistanceMaskSize.Mask3)
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

            var matThr = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2GRAY).Threshold(128, 255, ThresholdTypes.Otsu);

            if (negative)
            {
                Cv2.BitwiseNot(matThr, matThr);
            }
            Glb.DrawMatAndHist1(matThr);

            var    matDist      = matThr.DistanceTransform(distanceType, distanceMaskSize);
            var    x1           = matDist.Min();
            var    x2           = matDist.Max();
            float  y1           = 0;
            float  y2           = 255;
            double scale        = (y2 - y1) / (x2 - x1);
            double offset       = (x2 * y1 - x1 * y2) / (x2 - x1);
            var    matDistColor = new Mat();

            matDist.ConvertTo(matDistColor, MatType.CV_8UC1, scale, offset);
            Glb.DrawMatAndHist2(matDistColor);

            matThr.Dispose();
            matDist.Dispose();
            matDistColor.Dispose();
        }
Ejemplo n.º 4
0
        public static void DistanceTransformMy(bool negative = false)
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

            var matThr = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2GRAY).Threshold(128, 255, ThresholdTypes.Otsu);

            if (negative)
            {
                Cv2.BitwiseNot(matThr, matThr);
            }
            Glb.DrawMatAndHist1(matThr);

            var matDist = new Mat <float>(matThr.Size());

            IpUnsafe.DistanceTransform(matThr.Data, matThr.Width, matThr.Height, matDist.Data);
            var    x1           = matDist.Min();
            var    x2           = matDist.Max();
            float  y1           = 0;
            float  y2           = 255;
            double scale        = (y2 - y1) / (x2 - x1);
            double offset       = (x2 * y1 - x1 * y2) / (x2 - x1);
            var    matDistColor = new Mat();

            matDist.ConvertTo(matDistColor, MatType.CV_8UC1, scale, offset);
            Glb.DrawMatAndHist2(matDistColor);

            matThr.Dispose();
            matDist.Dispose();
            matDistColor.Dispose();
        }
Ejemplo n.º 5
0
        public static void MorpologyChamfer(int kernelSize = 31, int iteration = 1)
        {
            var matGray = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2GRAY);

            Glb.DrawMatAndHist0(matGray);

            var element = new Mat(kernelSize, kernelSize, MatType.CV_8UC1);
            int r       = kernelSize / 2;
            int cx      = r;
            int cy      = r;
            int rsq     = r * r;

            for (int y = 0; y < kernelSize; y++)
            {
                for (int x = 0; x < kernelSize; x++)
                {
                    int  dx       = x - cx;
                    int  dy       = y - cy;
                    bool inCircle = dx * dx + dy * dy <= rsq;
                    element.Set(y, x, inCircle);
                }
            }

            var matMorpology1 = matGray.MorphologyEx(MorphTypes.Open, element, iterations: iteration);

            Glb.DrawMatAndHist1(matMorpology1);

            var matMorpology2 = matMorpology1.MorphologyEx(MorphTypes.Close, element, iterations: iteration);

            Glb.DrawMatAndHist2(matMorpology2);

            matGray.Dispose();
            matMorpology1.Dispose();
            matMorpology2.Dispose();
        }
Ejemplo n.º 6
0
        public static void Kernel(
            float w00      = 1, float w01 = 1, float w02 = 1,
            float w10      = 1, float w11 = 1, float w12 = 1,
            float w20      = 1, float w21 = 1, float w22 = 1,
            bool normalize = true)
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

            float[] data = new float[] {
                w00, w01, w02,
                w10, w11, w12,
                w20, w21, w22
            };
            var kernel = new Mat(3, 3, MatType.CV_32FC1, data);

            if (normalize)
            {
                kernel = kernel.Normalize(normType: NormTypes.L1);
            }

            var matGray = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2GRAY);

            Glb.DrawMatAndHist1(matGray);

            var matDst = matGray.Filter2D(MatType.CV_8UC1, kernel, borderType: BorderTypes.Replicate);

            kernel.Dispose();
            Glb.DrawMatAndHist2(matDst);

            matGray.Dispose();
            matDst.Dispose();
        }
Ejemplo n.º 7
0
        public static void EqualizeHistHsv()
        {
            Glb.DrawMatAndHist0(Glb.matSrc);
            Glb.DrawMat0(Glb.matSrc);

            // BGR to HSV변환
            var matHsv = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2HSV);

            Glb.DrawHist0(matHsv, true);

            // 채널 분리
            var hsvChannels = matHsv.Split();

            // 변환
            hsvChannels[2] = hsvChannels[2].EqualizeHist();
            // 채널 병합
            var matDst = new Mat();

            Cv2.Merge(hsvChannels, matDst);
            Glb.DrawHist1(matDst, true);

            // HSV to BGR변환
            matDst = matDst.CvtColor(ColorConversionCodes.HSV2BGR);

            Glb.DrawMat1(matDst);

            Glb.DrawMatAndHist2(null);

            matHsv.Dispose();
            matDst.Dispose();
        }
Ejemplo n.º 8
0
        public static void Blob_CvBlobs(int filterArea = 0)
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

            var matThr = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2GRAY).Threshold(128, 255, ThresholdTypes.Otsu);

            var blobs = new CvBlobs();

            Glb.TimerStart();
            int cnt = blobs.Label(matThr);

            Console.WriteLine("=> Label Time: {0}ms", Glb.TimerStop());

            blobs.FilterByArea(filterArea, int.MaxValue);

            var matDsp = new Mat(Glb.matSrc.Rows, Glb.matSrc.Cols, MatType.CV_8UC3);

            matDsp.SetTo(Scalar.Black);

            Glb.TimerStart();
            MyBlobRenderer.RenderBlobs(blobs, matDsp);
            Console.WriteLine("=> Render Time: {0}ms", Glb.TimerStop());

            Console.WriteLine("=> Blob Count: {0}", blobs.Count);

            Glb.DrawMatAndHist1(matThr);
            Glb.DrawMatAndHist2(matDsp);

            matThr.Dispose();
            matDsp.Dispose();
        }
Ejemplo n.º 9
0
        //public static void GenerateHoleTest(
        //        int bufWidth = 1000, int bufHeight = 1000, byte bufColor = 35,
        //        int circleX = 500, int circleY = 500, int circleRadius = 30, byte circleColor = 255,
        //        double blurKsize = 61, double blurSigma = 0,
        //        int resizeX = 100, int resizeY = 100) {
        //    var matImage = new Mat(bufHeight, bufWidth, MatType.CV_8UC1);
        //    matImage.FloodFill(new Point(0, 0), bufColor);
        //    matImage.Circle(circleX, circleY, circleRadius, circleColor);
        //    matImage.FloodFill(new Point(circleX, circleY), circleColor);
        //    Glb.DrawMatAndHist0(matImage);

        //    var matBlur = matImage.GaussianBlur(new Size(blurKsize, blurKsize), blurSigma, blurSigma, BorderTypes.Replicate);
        //    Glb.DrawMatAndHist1(matBlur);

        //    var matResize = matBlur.Resize(new Size(resizeX, resizeY));
        //    Glb.DrawMatAndHist2(matResize);

        //    matResize.Dispose();
        //    matBlur.Dispose();
        //    matImage.Dispose();
        //}

        //public static void GenerateHoleLocationSaveTest(
        //        int bufWidth = 1000, int bufHeight = 1000, byte bufColor = 35,
        //        int circleX = 500, int circleY = 500, int circleRadius = 30, byte circleColor = 255,
        //        double blurKsize = 61, double blurSigma = 0,
        //        int resizeX = 100, int resizeY = 100) {
        //    for (int y = circleY; y < circleY + 10; y++) {
        //        for (int x = circleX; x < circleX + 10; x++) {
        //            var matImage = new Mat(bufHeight, bufWidth, MatType.CV_8UC1);
        //            matImage.FloodFill(new Point(0, 0), bufColor);
        //            matImage.Circle(x, y, circleRadius, circleColor);
        //            matImage.FloodFill(new Point(x, y), circleColor);
        //            Glb.DrawMatAndHist0(matImage);

        //            var matBlur = matImage.GaussianBlur(new Size(blurKsize, blurKsize), blurSigma, blurSigma, BorderTypes.Replicate);
        //            Glb.DrawMatAndHist1(matBlur);

        //            var matResize = matBlur.Resize(new Size(resizeX, resizeY));
        //            Glb.DrawMatAndHist2(matResize);
        //            string imageFilePath = $@"C:\test\ContactHole_Location\HolePos_({x},{y}).bmp";
        //            bool r = matResize.SaveImage(imageFilePath);
        //            Console.WriteLine($"Save Image File : {imageFilePath} => {r}");
        //            matResize.Dispose();
        //            matBlur.Dispose();
        //            matImage.Dispose();
        //        }
        //    }
        //}

        //public static void GenerateHoleSizeSaveTest(
        //        int bufWidth = 1000, int bufHeight = 1000, byte bufColor = 35,
        //        int circleX = 500, int circleY = 500, int circleRadius = 30, byte circleColor = 255,
        //        double blurKsize = 61, double blurSigma = 0,
        //        int resize = 100) {
        //    for (int i = - 20; i <= 20; i += 4) {
        //        var matImage = new Mat(bufHeight, bufWidth, MatType.CV_8UC1);
        //        matImage.FloodFill(new Point(0, 0), bufColor);
        //        matImage.Circle(circleX, circleY, circleRadius, circleColor);
        //        matImage.FloodFill(new Point(circleX, circleY), circleColor);
        //        Glb.DrawMatAndHist0(matImage);

        //        var matBlur = matImage.GaussianBlur(new Size(blurKsize, blurKsize), blurSigma, blurSigma, BorderTypes.Replicate);
        //        Glb.DrawMatAndHist1(matBlur);

        //        int roiSize = 60;
        //        int resize2 = resize + i;
        //        var matResizeHole = matBlur.Resize(new Size(resize2, resize2));
        //        var matResizeHoleRoi = new Mat(matResizeHole, new Rect((resize2-roiSize)/2, (resize2-roiSize)/2, roiSize, roiSize));

        //        var matResizeOri = matImage.Resize(new Size(resize, resize));
        //        var matResizeOriRoi = new Mat(matResizeOri, new Rect((resize-roiSize)/2, (resize-roiSize)/2, roiSize, roiSize));

        //        matResizeHoleRoi.CopyTo(matResizeOriRoi);
        //        string imageFilePath = $@"C:\test\ContactHole_Size\HoleSize_({resize2:000}).bmp";
        //        bool r = matResizeOri.SaveImage(imageFilePath);
        //        Console.WriteLine($"Save Image File : {imageFilePath} => {r}");

        //        matResizeHole.Dispose();
        //        matBlur.Dispose();
        //        matImage.Dispose();
        //    }
        //}

        public static void HSVControl(double hscale = 1.0, double hoffset = 0.0, double sscale = 1.0, double soffset = 0.0, double vscale = 1.0, double voffset = 0.0)
        {
            Glb.DrawMat0(Glb.matSrc);

            // BGR to HSV변환
            var matHsv = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2HSV);

            Glb.DrawHist0(matHsv, true);

            // 채널 분리
            var hsvChannels = matHsv.Split();

            // 변환
            hsvChannels[0].ConvertTo(hsvChannels[0], MatType.CV_8UC1, hscale, hoffset);
            hsvChannels[1].ConvertTo(hsvChannels[1], MatType.CV_8UC1, sscale, soffset);
            hsvChannels[2].ConvertTo(hsvChannels[2], MatType.CV_8UC1, vscale, voffset);

            // 채널 병합
            var matDst = new Mat();

            Cv2.Merge(hsvChannels, matDst);
            Glb.DrawHist1(matDst, true);

            // HSV to BGR변환
            matDst = matDst.CvtColor(ColorConversionCodes.HSV2BGR);
            Glb.DrawMat1(matDst);

            Glb.DrawMatAndHist2(null);

            matHsv.Dispose();
            matDst.Dispose();
        }
Ejemplo n.º 10
0
        public static void ErodeIppRoi(int iteration = 20, int roiX = 50, int roiY = 50, int roiW = 50, int roiH = 50)
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

            var matGray = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2GRAY);

            Glb.DrawMatAndHist1(matGray);

            Glb.TimerStart();
            var matDst = matGray.Clone();

            for (int i = 0; i < iteration; i++)
            {
                if (i % 2 == 0)
                {
                    IpDll.ErodeIppRoi(matGray.Data, matDst.Data, matGray.Width, matGray.Height, (int)matGray.Step(), roiX, roiY, roiW, roiH);
                }
                else
                {
                    IpDll.ErodeIppRoi(matDst.Data, matGray.Data, matGray.Width, matGray.Height, (int)matGray.Step(), roiX, roiY, roiW, roiH);
                }
            }
            if (iteration != 0 && iteration % 2 == 0)
            {
                matGray.CopyTo(matDst);
            }

            Console.WriteLine("=> Method Time: {0}ms", Glb.TimerStop());
            Glb.DrawMatAndHist2(matDst);

            matGray.Dispose();
            matDst.Dispose();
        }
Ejemplo n.º 11
0
        public static void Blob_CvConnectedComponent()
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

            var matThr = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2GRAY).Threshold(128, 255, ThresholdTypes.Otsu);

            var matLabels    = new Mat();
            var matStats     = new Mat();
            var matCentroids = new Mat();

            Glb.TimerStart();
            int num = matThr.ConnectedComponentsWithStats(matLabels, matStats, matCentroids) - 1;   // 배경까지 블럽으로 계산된다.

            Console.WriteLine("=> Label Time: {0}ms", Glb.TimerStop());

            var matDsp = new Mat(Glb.matSrc.Rows, Glb.matSrc.Cols, MatType.CV_8UC3);

            matDsp.SetTo(Scalar.Black);

            Glb.TimerStart();
            MyBlobRenderer.RenderBlobs(matLabels, matStats, matCentroids, matDsp);
            Console.WriteLine("=> Render Time: {0}ms", Glb.TimerStop());

            Console.WriteLine("=> Blob Count: {0}", num);

            Glb.DrawMatAndHist1(matThr);
            Glb.DrawMatAndHist2(matDsp);

            matThr.Dispose();
            matLabels.Dispose();
            matStats.Dispose();
            matCentroids.Dispose();
            matDsp.Dispose();
        }
Ejemplo n.º 12
0
        public static void RenderBlobs(MyBlobs blobs, Mat matDst)
        {
            byte *pdst       = matDst.DataPointer;
            int   bw         = matDst.Width;
            int   bh         = matDst.Height;
            int   stride     = (int)matDst.Step();
            int   colorCount = 0;

            foreach (var blob in blobs.Blobs.Values)
            {
                double r, g, b;
                Glb.Hsv2Rgb((colorCount * 77) % 360, 0.5, 1.0, out r, out g, out b);
                colorCount++;
                byte bb    = (byte)b;
                byte bg    = (byte)g;
                byte br    = (byte)r;
                int  label = blob.label;
                for (int y = blob.MinY; y <= blob.MaxY; y++)
                {
                    for (int x = blob.MinX; x <= blob.MaxX; x++)
                    {
                        if (blobs.Labels[y * bw + x] == label)
                        {
                            byte *ppdst = pdst + stride * y + x * 3;
                            ppdst[0] = bb;
                            ppdst[1] = bg;
                            ppdst[2] = br;
                        }
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public static double InverseMarshal()
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

            var matDst = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2GRAY);

            Glb.DrawMatAndHist1(matDst);

            IntPtr buf    = matDst.Data;
            int    bw     = matDst.Width;
            int    bh     = matDst.Height;
            int    stride = (int)matDst.Step();

            var st = GetTimeMs();

            for (int y = 0; y < bh; y++)
            {
                IntPtr pp = buf + stride * y;
                for (int x = 0; x < bw; x++, pp = pp + 1)
                {
                    Marshal.WriteByte(pp, (byte)~Marshal.ReadByte(pp));
                }
            }
            var dt = GetTimeMs() - st;

            Glb.DrawMatAndHist2(matDst);

            matDst.Dispose();
            return(dt);
        }
Ejemplo n.º 14
0
        public static double InverseApi()
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

            var matDst = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2GRAY);

            Glb.DrawMatAndHist1(matDst);

            int bw = matDst.Width;
            int bh = matDst.Height;

            var st = GetTimeMs();

            for (int y = 0; y < bh; y++)
            {
                for (int x = 0; x < bw; x++)
                {
                    matDst.Set(y, x, (byte)~matDst.Get <byte>(y, x));
                }
            }
            var dt = GetTimeMs() - st;

            Glb.DrawMatAndHist2(matDst);

            matDst.Dispose();
            return(dt);
        }
Ejemplo n.º 15
0
        public static void FaceDetect()
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

            var    matGray     = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2GRAY);
            string xmlPath     = Application.StartupPath + "\\..\\haarcascades\\haarcascade_frontalface_alt2.xml";
            var    haarCascade = new CascadeClassifier(xmlPath);

            Glb.TimerStart();
            Rect[] faces = haarCascade.DetectMultiScale(matGray);
            Console.WriteLine("=> Detect Time: {0}ms", Glb.TimerStop());
            Console.WriteLine("=> Face Count: {0}", faces.Length);

            var matDsp = Glb.matSrc.Clone();

            foreach (var face in faces)
            {
                matDsp.Rectangle(face.TopLeft, face.BottomRight, Scalar.Lime, 4);
            }

            Glb.DrawMatAndHist1(matDsp);
            Glb.DrawMatAndHist2(null);

            matDsp.Dispose();
            matGray.Dispose();
        }
Ejemplo n.º 16
0
        public static void RenderBlobs(MyBlobs blobs, Mat matDst)
        {
            int colorCount = 0;
            int dstPitch   = matDst.ElemSize();

            foreach (var blob in blobs.Blobs.Values)
            {
                double r, g, b;
                Glb.Hsv2Rgb((colorCount * 77) % 360, 0.5, 1.0, out r, out g, out b);
                colorCount++;
                byte bb    = (byte)b;
                byte bg    = (byte)g;
                byte br    = (byte)r;
                int  label = blob.label;
                for (int y = blob.MinY; y <= blob.MaxY; y++)
                {
                    int * plabel = (int *)blobs.Labels.Ptr(y, blob.MinX);
                    byte *pdst   = (byte *)matDst.Ptr(y, blob.MinX);
                    for (int x = blob.MinX; x <= blob.MaxX; x++, plabel++, pdst += dstPitch)
                    {
                        if (*plabel == label)
                        {
                            pdst[0] = bb;
                            pdst[1] = bg;
                            pdst[2] = br;
                        }
                    }
                }
            }
        }
Ejemplo n.º 17
0
        private void btnExample_Click(object sender, EventArgs e)
        {
            var bmp = (Bitmap)Resources.ResourceManager.GetObject(this.cbxExampleImage.Text);

            var mat = bmp.ToMat();

            Console.WriteLine($"Load From Bitmap: ({mat.Info()})");
            Glb.AddSrcImage(mat, this.cbxExampleImage.Text);
        }
Ejemplo n.º 18
0
        public static void ImageCopyOpenCV()
        {
            Mat matDst = new Mat(Glb.matSrc[0].Size(), Glb.matSrc[0].Type());

            Glb.matSrc[0].CopyTo(matDst);

            Glb.DrawMatAndHist(Glb.matSrc[0]);
            Glb.DrawMatAndHist(matDst);
        }
Ejemplo n.º 19
0
        public static void ImageCopyMarshal1()
        {
            Mat matDst = new Mat(Glb.matSrc[0].Size(), Glb.matSrc[0].Type());
            int nbytes = (int)Glb.matSrc[0].Step() * Glb.matSrc[0].Height;

            IpUnsafe.MemcpyMarshal1(matDst.Data, Glb.matSrc[0].Data, nbytes);

            Glb.DrawMatAndHist(Glb.matSrc[0]);
            Glb.DrawMatAndHist(matDst);
        }
Ejemplo n.º 20
0
        private void btnGrab_Click(object sender, EventArgs e)
        {
            VideoCapture cap = new VideoCapture(0);
            var          mat = new Mat();

            cap.Read(mat);
            cap.Dispose();
            Console.WriteLine($"grb from camera{cap.ToString()}");
            Glb.AddSrcImage(mat, "grab");
        }
Ejemplo n.º 21
0
        public static void ImageCopyCrt()
        {
            Mat matDst = new Mat(Glb.matSrc[0].Size(), Glb.matSrc[0].Type());
            var nbytes = Glb.matSrc[0].Step() * Glb.matSrc[0].Height;

            Crt.memcpy(matDst.Data, Glb.matSrc[0].Data, nbytes);

            Glb.DrawMatAndHist(Glb.matSrc[0]);
            Glb.DrawMatAndHist(matDst);
        }
Ejemplo n.º 22
0
        public static void MedianBlur(int ksize = 3)
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

            var matDst = Glb.matSrc.MedianBlur(ksize);

            Glb.DrawMatAndHist1(matDst);
            Glb.DrawMatAndHist2(null);

            matDst.Dispose();
        }
Ejemplo n.º 23
0
        public static void CvtColor(ColorConversionCodes code = ColorConversionCodes.BGR2GRAY)
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

            var matDst = Glb.matSrc.CvtColor(code);

            Glb.DrawMatAndHist1(matDst);
            Glb.DrawMatAndHist2(null);

            matDst.Dispose();
        }
Ejemplo n.º 24
0
        public static void LabColorSpace(int channel1 = 0, int channel2 = 1)
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

            var matLab      = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2Lab);
            var hsvChannels = matLab.Split();

            Glb.DrawMatAndHist1(hsvChannels[channel1]);
            Glb.DrawMatAndHist2(hsvChannels[channel2]);
            matLab.Dispose();
        }
Ejemplo n.º 25
0
        public static void GammaCorrection(double gamma_value = 1.5)
        {
            Glb.DrawMatAndHist0(Glb.matSrc);
            byte[] lut = Enumerable.Range(0, 256)
                         .Select(src => (byte)(Math.Pow(src / 255.0, 1.0 / gamma_value) * 255.0))
                         .ToArray();
            var matDst = Glb.matSrc.LUT(lut);

            Glb.DrawMatAndHist1(matDst);
            Glb.DrawMatAndHist2(null);
            matDst.Dispose();
        }
Ejemplo n.º 26
0
        public static void DummyFunction(int callCount = 20, int sleepMs = 20)
        {
            var matGray = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2GRAY);
            var matDst  = new Mat(matGray.Size(), matGray.Type());

            Glb.TimerStart();
            for (int i = 0; i < callCount; i++)
            {
                IpDll.DummyFunction(matGray.Data, matDst.Data, matGray.Width, matGray.Height, (int)matGray.Step(), sleepMs);
            }
            Console.WriteLine("=> DummyFunction Time: {0}ms", Glb.TimerStop());
        }
Ejemplo n.º 27
0
        public static void Flip(FlipMode flipCode = FlipMode.X)
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

            Mat matDst = Glb.matSrc.Flip(flipCode);

            Glb.DrawMatAndHist1(matDst);

            Glb.DrawMatAndHist2(null);

            matDst.Dispose();
        }
Ejemplo n.º 28
0
        public static void ImageCopyOpenCV()
        {
            Mat matDst = new Mat(Glb.matSrc.Size(), Glb.matSrc.Type());

            Glb.TimerStart();
            Glb.matSrc.CopyTo(matDst);
            Console.WriteLine("=> Method Time: {0}ms", Glb.TimerStop());

            Glb.DrawMatAndHist0(Glb.matSrc);
            Glb.DrawMatAndHist1(matDst);
            Glb.DrawMatAndHist2(null);
            matDst.Dispose();
        }
Ejemplo n.º 29
0
        public static void Crop(int x = 10, int y = 10, int width = 100, int height = 100)
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

            Rect roi    = new Rect(x, y, width, height);
            Mat  matDst = new Mat(Glb.matSrc, roi);

            Glb.DrawMatAndHist1(matDst);

            Glb.DrawMatAndHist2(null);

            matDst.Dispose();
        }
Ejemplo n.º 30
0
        public static void EqualizeHist()
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

            var matGray = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2GRAY);
            var matDst  = matGray.EqualizeHist();

            Glb.DrawMatAndHist1(matGray);
            Glb.DrawMatAndHist2(matDst);

            matGray.Dispose();
            matDst.Dispose();
        }