コード例 #1
0
ファイル: Board.cs プロジェクト: JasonCrease/SeeBoard
        private void RemovePerspective(OLSRegression regression)
        {
            float tBit = 300;
            float B = regression.B;
            float A = regression.A;
            float x1 = A * (tBit / (B + tBit));
            float x2 = A + ((400 - A) * (B / (B + tBit)));

            PointF[] srcs = new PointF[4];
            srcs[0] = new PointF((float)x1, 0);
            srcs[1] = new PointF((float)x2, 0);
            srcs[2] = new PointF(400, tBit);
            srcs[3] = new PointF(0, tBit);

            PointF[] dsts = new PointF[4];
            dsts[0] = new PointF(0, 0);
            dsts[1] = new PointF(400, 0);
            dsts[2] = new PointF(400, 300);
            dsts[3] = new PointF(0, 300);

            HomographyMatrix warpMat = CameraCalibration.GetPerspectiveTransform(srcs, dsts);
            WarpedImage = BoardImage.WarpPerspective(warpMat, 400, 300,
                Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC,
                Emgu.CV.CvEnum.WARP.CV_WARP_FILL_OUTLIERS,
                GetBottomBorderColor(BoardImage));

            m_InverseWarpMatrix = CameraCalibration.GetPerspectiveTransform(dsts, srcs);
            //WarpedImage = WarpedImage.WarpPerspective(m_InverseWarpMatrix, 400, 300,
            //    Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC,
            //    Emgu.CV.CvEnum.WARP.CV_WARP_FILL_OUTLIERS,
            //    GetBottomBorderColor(BoardImage));
        }
コード例 #2
0
        internal OLSRegression GetBoardRegression()
        {
            List<FullLine> fullLines = new List<FullLine>();

            foreach (LineSegment2D lineSegment in VertLines)
            {
                // Set lowest point as p1
                var p1 = lineSegment.P1;
                var p2 = lineSegment.P2;
                if (p1.Y > p2.Y)
                {
                    p2 = lineSegment.P1;
                    p1 = lineSegment.P2;
                }

                // Calculate crossing of x-axis (call it c)
                float m = (float)(p2.X - p1.X) / (float)(p2.Y - p1.Y);
                float c = (float)p1.X - ((float)p1.Y * m);

                FullLine fullLine = new FullLine(m, c);
                fullLines.Add(fullLine);
            }

            OLSRegression olsRegression = new OLSRegression();
            olsRegression.Perform(fullLines.ToArray());

            return olsRegression;
        }