Example #1
0
        public static void ErodeSse(int iteration, bool useParallel)
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

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

            Glb.DrawMatAndHist1(matGray);

            Glb.TimerStart();
            var matDst = new Mat(matGray.Size(), matGray.Type());

            for (int i = 0; i < iteration; i++)
            {
                if (i % 2 == 0)
                {
                    IpDll.ErodeC(matGray.Data, matDst.Data, matGray.Width, matGray.Height, (int)matGray.Step(), true, useParallel);
                }
                else
                {
                    IpDll.ErodeC(matDst.Data, matGray.Data, matGray.Width, matGray.Height, (int)matGray.Step(), true, useParallel);
                }
            }
            if (iteration != 0 && iteration % 2 == 0)
            {
                matGray.CopyTo(matDst);
            }

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

            matGray.Dispose();
            matDst.Dispose();
        }
Example #2
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();
        }
Example #3
0
        public static void GetStringTest()
        {
            StringBuilder sb = new StringBuilder(512);

            IpDll.GetString(sb);
            Console.WriteLine(sb.ToString());
        }
Example #4
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());
        }
Example #5
0
        public static Mat ErodeIpp(Mat matGray, int iteration)
        {
            var mat0 = matGray.Clone();
            var mat1 = new Mat(mat0.Size(), mat0.Type());

            for (int i = 0; i < iteration; i++)
            {
                var matSrc = (i % 2 == 0) ? mat0 : mat1;
                var matDst = (i % 2 == 0) ? mat1 : mat0;
                IpDll.ErodeIpp(matSrc.Data, matDst.Data, matGray.Width, matGray.Height, (int)matGray.Step());
            }
            return((iteration % 2 == 0) ? mat0 : mat1);
        }
Example #6
0
        public static void InverseIppRoi(int roiX = 100, int roiY = 100, int roiW = 100, int roiH = 100)
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

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

            Glb.DrawMatAndHist1(matGray);

            var matDst = matGray.Clone();

            IpDll.InverseIppRoi(matGray.Data, matDst.Data, matGray.Width, matGray.Height, roiX, roiY, roiW, roiH);
            Glb.DrawMatAndHist2(matDst);

            matGray.Dispose();
            matDst.Dispose();
        }
Example #7
0
        public static double InverseAvx()
        {
            Glb.DrawMatAndHist(Glb.matSrc[0]);

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

            Glb.DrawMatAndHist(matDst);

            var st = Util.GetTimeMs();

            IpDll.InverseAvx(matDst.Data, matDst.Width, matDst.Height, (int)matDst.Step());
            var dt = Util.GetTimeMs() - st;

            Glb.DrawMatAndHist(matDst);

            return(dt);
        }
Example #8
0
        public static double InverseVectorClass()
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

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

            Glb.DrawMatAndHist1(matDst);

            var st = GetTimeMs();

            IpDll.InverseVec(matDst.Data, matDst.Width, matDst.Height, (int)matDst.Step());
            var dt = GetTimeMs() - st;

            Glb.DrawMatAndHist2(matDst);

            matDst.Dispose();
            return(dt);
        }
Example #9
0
        public unsafe int LabelIpp(IntPtr src, int bw, int bh, int stride, bool connectivity_4or8)
        {
            var matSrc = new Mat(bh, bw, MatType.CV_8UC1, src, stride);

            // label 버퍼
            this.Labels = new Mat(bw, bw, MatType.CV_32SC1, Scalar.All(0));


            int numLabels = 0;

            numLabels = IpDll.LabelMarker(src, (IntPtr)Labels.DataPointer, bw, bh, connectivity_4or8);

            // 4. 데이터 추출
            var blobs = this.Blobs;

            blobs.Clear();
            for (int i = 0; i < numLabels; i++)
            {
                int label = i + 1;
                blobs[label] = new MyBlob(label);
            }

            // labels 수정
            for (int y = 0; y < bh; y++)
            {
                int *plabel = (int *)Labels.Ptr(y);
                for (int x = 0; x < bw; x++, plabel++)
                {
                    var label = *plabel;
                    if (label == 0)
                    {
                        continue;
                    }

                    var blob = blobs[label];
                    blob.area++;
                    blob.centroidX += x;
                    blob.centroidY += y;
                    if (x < blob.MinX)
                    {
                        blob.MinX = x;
                    }
                    if (y < blob.MinY)
                    {
                        blob.MinY = y;
                    }
                    if (x > blob.MaxX)
                    {
                        blob.MaxX = x;
                    }
                    if (y > blob.MaxY)
                    {
                        blob.MaxY = y;
                    }
                }
            }

            foreach (var blob in this.Blobs.Values)
            {
                blob.centroidX /= blob.area;
                blob.centroidY /= blob.area;
            }

            return(numLabels);
        }
Example #10
0
 public static void SetStringTest(string str = "0123456789")
 {
     IpDll.SetString(str);
 }
Example #11
0
        public static unsafe void DevernayTest(double sigma = 0, double th_h = 128, double th_l = 50)
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

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

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

            IntPtr image = Marshal.AllocHGlobal(matGray.Width * matGray.Height * sizeof(double));

            for (int iy = 0; iy < matGray.Height; iy++)
            {
                byte *  sptr = (byte *)matGray.Ptr(iy);
                double *dptr = (double *)image + matGray.Width * iy;
                for (int ix = 0; ix < matGray.Width; ix++, sptr++, dptr++)
                {
                    *dptr = *sptr;
                }
            }
            IntPtr x            = IntPtr.Zero;
            IntPtr y            = IntPtr.Zero;
            int    numXY        = 0;
            IntPtr curve_limits = IntPtr.Zero;
            int    numCurve     = 0;

            IpDll.Devernay(ref x, ref y, ref numXY, ref curve_limits, ref numCurve, image, matGray.Width, matGray.Height, sigma, th_h, th_l);
            Console.WriteLine($"numXY={numXY}, numCurve={numCurve}");

            double *xList          = (double *)x;
            double *yList          = (double *)y;
            int *   curveLimitList = (int *)curve_limits;

            List <List <PointF> > curveList = new List <List <PointF> >();

            for (int i = 0; i < numCurve; i++)
            {
                List <PointF> curve = new List <PointF>();
                curveList.Add(curve);
                int stIdx = curveLimitList[i];
                int edIdx = i < numCurve - 1 ? curveLimitList[i + 1] : numXY;
                for (int j = stIdx; j < edIdx; j++)
                {
                    curve.Add(new PointF((float)xList[j], (float)yList[j]));
                }
            }

            Action <ImageGraphics> drawing = delegate(ImageGraphics ig) {
                foreach (var curve in curveList)
                {
                    var polyline = curve
                                   .Select(ptd => new PointF(ptd.X + 0.5f, ptd.Y + 0.5f)).ToArray();
                    for (int i = 0; i < polyline.Length - 1; i++)
                    {
                        var pt1 = polyline[i];
                        var pt2 = polyline[i + 1];
                        ig.DrawLine(pt1, pt2, System.Drawing.Pens.Lime);
                    }
                }
            };

            Glb.form.pbx1.Tag = drawing;

            IpDll.FreeBuffer(x);
            IpDll.FreeBuffer(y);
            IpDll.FreeBuffer(curve_limits);
            Marshal.FreeHGlobal(image);

            matGray.Dispose();
        }
Example #12
0
        public int LabelIpp(IntPtr src, int bw, int bh, int stride)
        {
            Glb.TimerStart();
            // prepare
            byte *psrc = (byte *)src.ToPointer();

            // label 버퍼
            this.Labels = new int[bw * bh];
            this.bw     = bw;
            this.bh     = bh;

            Console.WriteLine($"=> 1. Prepare buffer time: {Glb.TimerStop()}ms");

            Glb.TimerStart();
            int numLabels = 0;

            fixed(int *pLabels = Labels)
            {
                numLabels = IpDll.LabelMarker(src, (IntPtr)pLabels, bw, bh);
            }

            Console.WriteLine($"=> 2. IpDll.LabelMarker time: {Glb.TimerStop()}ms");

            // 4. 데이터 추출
            Glb.TimerStart();
            var blobs = this.Blobs;

            blobs.Clear();
            for (int i = 0; i < numLabels; i++)
            {
                int label = i + 1;
                blobs[label] = new MyBlob(label);
            }

            // labels 수정
            for (int y = 0; y < bh; y++)
            {
                for (int x = 0; x < bw; x++)
                {
                    var label = this.Labels[bw * y + x];
                    if (label == 0)
                    {
                        continue;
                    }

                    var blob = blobs[label];
                    blob.area++;
                    blob.centroidX += x;
                    blob.centroidY += y;
                    if (x < blob.MinX)
                    {
                        blob.MinX = x;
                    }
                    if (y < blob.MinY)
                    {
                        blob.MinY = y;
                    }
                    if (x > blob.MaxX)
                    {
                        blob.MaxX = x;
                    }
                    if (y > blob.MaxY)
                    {
                        blob.MaxY = y;
                    }
                }
            }

            foreach (var blob in this.Blobs.Values)
            {
                blob.centroidX /= blob.area;
                blob.centroidY /= blob.area;
            }
            Console.WriteLine($"=> 3. 데이터 추출 time: {Glb.TimerStop()}ms");

            return(numLabels);
        }