當前位置: 首頁>>代碼示例>>C#>>正文


C# Mat.Circle方法代碼示例

本文整理匯總了C#中OpenCvSharp.CPlusPlus.Mat.Circle方法的典型用法代碼示例。如果您正苦於以下問題:C# Mat.Circle方法的具體用法?C# Mat.Circle怎麽用?C# Mat.Circle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在OpenCvSharp.CPlusPlus.Mat的用法示例。


在下文中一共展示了Mat.Circle方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main

        private static void Main(string[] args)
        {
            string fileName = "C:\\perspective_chessboard.jpg";

            // Cv
            using (CvMat chessboard = new CvMat(fileName))
            {
                Cv.ShowImage("Input_Cv", chessboard);

                CvPoint2D32f[] corners;
                if (Cv.FindChessboardCorners(chessboard, new Size(10, 7), out corners))
                {
                    using (CvMat dest = new CvMat(chessboard.Rows, chessboard.Cols, MatrixType.U8C3))
                    {
                        CvPoint2D32f[] a = 
                        {
                            corners[0],
                            corners[60],
                            corners[69],
                            corners[9]
                        };

                        foreach (var corner in a)
                        {
                            Cv.Circle(chessboard, corner, 5, new CvScalar(0, 0, 255));
                        }
                        Cv.ShowImage("RectangleVertices_Cv", chessboard);

                        CvPoint2D32f[] b =
                        {
                            new CvPoint2D32f(0, 0),
                            new CvPoint2D32f(0, chessboard.Height),
                            new CvPoint2D32f(chessboard.Width, chessboard.Height),
                            new CvPoint2D32f(chessboard.Width, 0)
                        };

                        CvMat map_matrix;
                        Cv.GetPerspectiveTransform(a, b, out map_matrix);
                        Cv.WarpPerspective(chessboard, dest, map_matrix, Interpolation.Linear | Interpolation.FillOutliers, CvScalar.ScalarAll(255)); //Succeed
                        Cv.ReleaseMat(map_matrix);

                        Cv.ShowImage("Output_Cv", dest);
                    }

                    //Cv.WaitKey();
                }
            }

            //Cv2
            using (Mat chessboard = new Mat(fileName))
            {
                Point2f[] corners;
                if (Cv2.FindChessboardCorners(chessboard, new Size(10, 7), out corners))
                {
                    Point2f[] a =
                    {
                        corners[0],
                        corners[60],
                        corners[69],
                        corners[9]
                    };

                    foreach (var corner in a)
                    {
                        chessboard.Circle(corner, 5, new Scalar(0, 0, 255));
                    }
                    Cv2.ImShow("RectangleVertices_Cv2", chessboard);
                    //Cv2.WaitKey();

                    Point2f[] b =
                    {
                        new Point2f(0, 0),
                        new Point2f(0, chessboard.Height),
                        new Point2f(chessboard.Width, chessboard.Height),
                        new Point2f(chessboard.Width, 0)
                    };

                    using (Mat map_matrix = Cv2.GetPerspectiveTransform(a, b))
                    using (Mat dest = new Mat(new Size(640, 480), MatType.CV_8UC3))
                    {
                        Cv2.WarpPerspective(chessboard, dest, map_matrix, dest.Size(), Interpolation.Linear | Interpolation.FillOutliers, BorderType.Default, Scalar.All(255)); //AccessViolation
                        Cv2.ImShow("Output_Cv2", dest);
                    }

                    ////Another way (Using Mat.WarpPerspective())
                    //using (Mat map_matrix = Cv2.GetPerspectiveTransform(a, b))
                    //using (Mat dest = chessboard.WarpPerspective(map_matrix, new Size(640, 480), Interpolation.Linear | Interpolation.FillOutliers, BorderType.Default, Scalar.All(255))) //AccessViolation
                    //{
                    //    Cv2.ImShow("Output_Cv2", dest);
                    //}

                    Cv2.WaitKey();
                }
            }

            //Track();
            //Run();
        }
開發者ID:healtech,項目名稱:opencvsharp,代碼行數:98,代碼來源:Program.cs


注:本文中的OpenCvSharp.CPlusPlus.Mat.Circle方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。