コード例 #1
0
        public int FindCorner()
        {
            Emgu.CV.Cvb.CvBlobDetector bDetect    = new Emgu.CV.Cvb.CvBlobDetector();
            Emgu.CV.Cvb.CvBlobs        markerBlob = new Emgu.CV.Cvb.CvBlobs();

            List <Rectangle> blobs = new List <Rectangle>();

            Image <Gray, Byte> preprocessImage = originalImage.Convert <Gray, Byte>();

            preprocessImage = preprocessImage.ThresholdBinary(new Gray(100), new Gray(255));
            preprocessImage = preprocessImage.Not();



            markerBlob.Clear();

            bDetect.Detect(preprocessImage, markerBlob);
            //preprocessImage.Dispose();
            //preprocessImage = null;

            //markerBlob.FilterByArea(250, 1800);

            foreach (Emgu.CV.Cvb.CvBlob targetBlob in markerBlob.Values)
            {
                if (targetBlob.BoundingBox.Width <= 32 && targetBlob.BoundingBox.Width >= 29)
                {
                    if (targetBlob.BoundingBox.Height <= 32 && targetBlob.BoundingBox.Height >= 29)
                    {
                        Rectangle r = new Rectangle(targetBlob.BoundingBox.X, targetBlob.BoundingBox.Y, targetBlob.BoundingBox.Width, targetBlob.BoundingBox.Height);
                        outerMarker.Add(r);
                    }
                }
                CvInvoke.PutText(preprocessImage, targetBlob.BoundingBox.Width + " " + targetBlob.BoundingBox.Height, new Point(targetBlob.BoundingBox.X, targetBlob.BoundingBox.Y), FontFace.HersheyComplex, 1, new Bgr(Color.Red).MCvScalar, 2);
            }

            return(outerMarker.Count);
        }
コード例 #2
0
        public void DeSkew()
        {
            Rectangle vBoundary = new Rectangle(new Point(0, 0), new Size(140, originalImage.Height));

            Emgu.CV.Cvb.CvBlobDetector bDetect = new Emgu.CV.Cvb.CvBlobDetector();
            Emgu.CV.Cvb.CvBlobs markerBlob = new Emgu.CV.Cvb.CvBlobs();

            List<Rectangle> blobs = new List<Rectangle>();

            Image<Gray, Byte> preprocessImage = originalImage.Convert<Gray, Byte>();
            preprocessImage = preprocessImage.ThresholdBinary(new Gray(200), new Gray(255));
            preprocessImage = preprocessImage.Not();

            markerBlob.Clear();

            bDetect.Detect(preprocessImage, markerBlob);
            preprocessImage.Dispose();
            preprocessImage = null;

            markerBlob.FilterByArea(250, 1800);

            foreach (Emgu.CV.Cvb.CvBlob targetBlob in markerBlob.Values)
            {
                if (vBoundary.Contains(targetBlob.BoundingBox))
                {
                    if (targetBlob.BoundingBox.Width >= targetBlob.BoundingBox.Height - 5)
                    {
                        Rectangle r = new Rectangle(targetBlob.BoundingBox.X, targetBlob.BoundingBox.Y, targetBlob.BoundingBox.Width, targetBlob.BoundingBox.Height);
                        blobs.Add(r);
                    }
                }
            }

            RectangleF temp = blobs.First();
            RectangleF temp2 = blobs.Last();

            double dY = Math.Abs(temp.Y - temp2.Y);
            double dX = Math.Abs(temp.X - temp2.X);

            double angle = Math.Atan2(dX, dY);
            angle = angle * (180 / Math.PI);

            if (temp2.X > temp.X)
            {
                angle = angle * -1;
            }

            RotatedRect rot_rec = new RotatedRect();
            rot_rec.Center = new PointF(temp.X, temp.Y);
            RotationMatrix2D rot_mat = new RotationMatrix2D(rot_rec.Center, angle, 1);
            Image<Bgr, Byte> outimage = originalImage.CopyBlank();
            CvInvoke.WarpAffine(originalImage, outimage, rot_mat, originalImage.Size, Inter.Cubic, Warp.Default, BorderType.Constant, new Bgr(Color.White).MCvScalar);

            int xOffset = 80 - (int)temp.X;
            int yOffset = 45 - (int)temp.Y;

            originalImage = outimage.Copy();

            Bitmap a = originalImage.ToBitmap();
            CanvasMove filter = new CanvasMove(new AForge.IntPoint(xOffset, yOffset), Color.White);
            a = filter.Apply(a);
            originalImage = new Image<Bgr, Byte>(a);

            a.Dispose();
            a = null;
            outimage.Dispose();
            outimage = null;
            blobs = null;
        }
コード例 #3
0
        public int Validate()
        {
            Emgu.CV.Cvb.CvBlobDetector bDetect = new Emgu.CV.Cvb.CvBlobDetector();
            Emgu.CV.Cvb.CvBlobs markerBlob = new Emgu.CV.Cvb.CvBlobs();

            Image<Gray, Byte> preprocessImage = originalImage.Convert<Gray, Byte>();

            UMat pyr = new UMat();
            CvInvoke.PyrDown(preprocessImage, pyr);
            CvInvoke.PyrUp(pyr, preprocessImage);

            preprocessImage = preprocessImage.ThresholdBinary(new Gray(200), new Gray(255));
            preprocessImage = preprocessImage.Not();

            markerBlob.Clear();

            bDetect.Detect(preprocessImage, markerBlob);

            preprocessImage.Dispose();
            preprocessImage = null;

            markerBlob.FilterByArea(400, 1800);

            foreach (Emgu.CV.Cvb.CvBlob targetBlob in markerBlob.Values)
            {
                if (vBoundary.Contains(targetBlob.BoundingBox))
                {
                    if (targetBlob.BoundingBox.Width >= targetBlob.BoundingBox.Height - 5)
                    {
                        Rectangle r = new Rectangle(targetBlob.BoundingBox.X, targetBlob.BoundingBox.Y, targetBlob.BoundingBox.Width, targetBlob.BoundingBox.Height);
                        vBlobs.Add(r);
                    }
                }
                else if (hBoundary.Contains(targetBlob.BoundingBox))
                {
                    if (targetBlob.BoundingBox.Height >= targetBlob.BoundingBox.Width - 5)
                    {
                        Rectangle r = new Rectangle(targetBlob.BoundingBox.X, targetBlob.BoundingBox.Y, targetBlob.BoundingBox.Width, targetBlob.BoundingBox.Height);
                        hBlobs.Add(r);
                    }
                }
                else if (idBoundary.Contains(targetBlob.BoundingBox))
                {
                    Rectangle r = new Rectangle(targetBlob.BoundingBox.X, targetBlob.BoundingBox.Y, targetBlob.BoundingBox.Width, targetBlob.BoundingBox.Height);
                    idBlobs.Add(r);
                }

                else if (answerBoundary.Contains(targetBlob.BoundingBox))
                {
                    Rectangle r = new Rectangle(targetBlob.BoundingBox.X, targetBlob.BoundingBox.Y, targetBlob.BoundingBox.Width, targetBlob.BoundingBox.Height);
                    answerBlobs.Add(r);
                }
            }

            vBlobs.RemoveAt(0);
            int bCount = 0;

            hBlobs = hBlobs.OrderBy(r => r.X).ToList();
            vBlobs = vBlobs.OrderBy(r => r.Y).ToList();

            markerBlob.Dispose();
            markerBlob = null;
            return bCount;
        }
コード例 #4
0
        public int FindCorner()
        {
            Emgu.CV.Cvb.CvBlobDetector bDetect = new Emgu.CV.Cvb.CvBlobDetector();
            Emgu.CV.Cvb.CvBlobs markerBlob = new Emgu.CV.Cvb.CvBlobs();

            List<Rectangle> blobs = new List<Rectangle>();

            Image<Gray, Byte> preprocessImage = originalImage.Convert<Gray, Byte>();

            preprocessImage = preprocessImage.ThresholdBinary(new Gray(100), new Gray(255));
            preprocessImage = preprocessImage.Not();

            markerBlob.Clear();

            bDetect.Detect(preprocessImage, markerBlob);
            //preprocessImage.Dispose();
            //preprocessImage = null;

            //markerBlob.FilterByArea(250, 1800);

            foreach (Emgu.CV.Cvb.CvBlob targetBlob in markerBlob.Values)
            {
                if (targetBlob.BoundingBox.Width <= 32 && targetBlob.BoundingBox.Width >= 29)
                {
                    if (targetBlob.BoundingBox.Height <= 32 && targetBlob.BoundingBox.Height >= 29)
                    {
                        Rectangle r = new Rectangle(targetBlob.BoundingBox.X, targetBlob.BoundingBox.Y, targetBlob.BoundingBox.Width, targetBlob.BoundingBox.Height);
                        outerMarker.Add(r);
                    }
                }
                CvInvoke.PutText(preprocessImage, targetBlob.BoundingBox.Width + " " + targetBlob.BoundingBox.Height, new Point(targetBlob.BoundingBox.X, targetBlob.BoundingBox.Y), FontFace.HersheyComplex, 1, new Bgr(Color.Red).MCvScalar, 2);
            }

            return outerMarker.Count;
        }
コード例 #5
0
        public int Validate()
        {
            Emgu.CV.Cvb.CvBlobDetector bDetect    = new Emgu.CV.Cvb.CvBlobDetector();
            Emgu.CV.Cvb.CvBlobs        markerBlob = new Emgu.CV.Cvb.CvBlobs();

            Image <Gray, Byte> preprocessImage = originalImage.Convert <Gray, Byte>();

            UMat pyr = new UMat();

            CvInvoke.PyrDown(preprocessImage, pyr);
            CvInvoke.PyrUp(pyr, preprocessImage);

            preprocessImage = preprocessImage.ThresholdBinary(new Gray(200), new Gray(255));
            preprocessImage = preprocessImage.Not();


            markerBlob.Clear();

            bDetect.Detect(preprocessImage, markerBlob);

            preprocessImage.Dispose();
            preprocessImage = null;

            markerBlob.FilterByArea(400, 1800);


            foreach (Emgu.CV.Cvb.CvBlob targetBlob in markerBlob.Values)
            {
                if (vBoundary.Contains(targetBlob.BoundingBox))
                {
                    if (targetBlob.BoundingBox.Width >= targetBlob.BoundingBox.Height - 5)
                    {
                        Rectangle r = new Rectangle(targetBlob.BoundingBox.X, targetBlob.BoundingBox.Y, targetBlob.BoundingBox.Width, targetBlob.BoundingBox.Height);
                        vBlobs.Add(r);
                    }
                }
                else if (hBoundary.Contains(targetBlob.BoundingBox))
                {
                    if (targetBlob.BoundingBox.Height >= targetBlob.BoundingBox.Width - 5)
                    {
                        Rectangle r = new Rectangle(targetBlob.BoundingBox.X, targetBlob.BoundingBox.Y, targetBlob.BoundingBox.Width, targetBlob.BoundingBox.Height);
                        hBlobs.Add(r);
                    }
                }
                else if (idBoundary.Contains(targetBlob.BoundingBox))
                {
                    Rectangle r = new Rectangle(targetBlob.BoundingBox.X, targetBlob.BoundingBox.Y, targetBlob.BoundingBox.Width, targetBlob.BoundingBox.Height);
                    idBlobs.Add(r);
                }

                else if (answerBoundary.Contains(targetBlob.BoundingBox))
                {
                    Rectangle r = new Rectangle(targetBlob.BoundingBox.X, targetBlob.BoundingBox.Y, targetBlob.BoundingBox.Width, targetBlob.BoundingBox.Height);
                    answerBlobs.Add(r);
                }
            }

            vBlobs.RemoveAt(0);
            int bCount = 0;

            hBlobs = hBlobs.OrderBy(r => r.X).ToList();
            vBlobs = vBlobs.OrderBy(r => r.Y).ToList();

            markerBlob.Dispose();
            markerBlob = null;
            return(bCount);
        }
コード例 #6
0
        public void DeSkew()
        {
            Rectangle vBoundary = new Rectangle(new Point(0, 0), new Size(140, originalImage.Height));

            Emgu.CV.Cvb.CvBlobDetector bDetect    = new Emgu.CV.Cvb.CvBlobDetector();
            Emgu.CV.Cvb.CvBlobs        markerBlob = new Emgu.CV.Cvb.CvBlobs();

            List <Rectangle> blobs = new List <Rectangle>();

            Image <Gray, Byte> preprocessImage = originalImage.Convert <Gray, Byte>();

            preprocessImage = preprocessImage.ThresholdBinary(new Gray(200), new Gray(255));
            preprocessImage = preprocessImage.Not();

            markerBlob.Clear();

            bDetect.Detect(preprocessImage, markerBlob);
            preprocessImage.Dispose();
            preprocessImage = null;

            markerBlob.FilterByArea(250, 1800);

            foreach (Emgu.CV.Cvb.CvBlob targetBlob in markerBlob.Values)
            {
                if (vBoundary.Contains(targetBlob.BoundingBox))
                {
                    if (targetBlob.BoundingBox.Width >= targetBlob.BoundingBox.Height - 5)
                    {
                        Rectangle r = new Rectangle(targetBlob.BoundingBox.X, targetBlob.BoundingBox.Y, targetBlob.BoundingBox.Width, targetBlob.BoundingBox.Height);
                        blobs.Add(r);
                    }
                }
            }

            RectangleF temp  = blobs.First();
            RectangleF temp2 = blobs.Last();

            double dY = Math.Abs(temp.Y - temp2.Y);
            double dX = Math.Abs(temp.X - temp2.X);

            double angle = Math.Atan2(dX, dY);

            angle = angle * (180 / Math.PI);

            if (temp2.X > temp.X)
            {
                angle = angle * -1;
            }

            RotatedRect rot_rec = new RotatedRect();

            rot_rec.Center = new PointF(temp.X, temp.Y);
            RotationMatrix2D  rot_mat  = new RotationMatrix2D(rot_rec.Center, angle, 1);
            Image <Bgr, Byte> outimage = originalImage.CopyBlank();

            CvInvoke.WarpAffine(originalImage, outimage, rot_mat, originalImage.Size, Inter.Cubic, Warp.Default, BorderType.Constant, new Bgr(Color.White).MCvScalar);

            int xOffset = 80 - (int)temp.X;
            int yOffset = 45 - (int)temp.Y;

            originalImage = outimage.Copy();

            Bitmap     a      = originalImage.ToBitmap();
            CanvasMove filter = new CanvasMove(new AForge.IntPoint(xOffset, yOffset), Color.White);

            a             = filter.Apply(a);
            originalImage = new Image <Bgr, Byte>(a);

            a.Dispose();
            a = null;
            outimage.Dispose();
            outimage = null;
            blobs    = null;
        }