OpencvSharp-图像修正

OpencvSharp 使用透视变换。
static void Main(string[] args)
{
        // 输入需要转变的图的四个角的坐标(可以通过代码获得)
        var srcPoints = new Point2f[] {
            new Point2f(69, 110),
            new Point2f(81, 857),
            new Point2f(1042, 786),
            new Point2f(1038, 147),
        };

        // 需要转换的图指定转换后四个角的坐标
        var dstPoints = new Point2f[] {
            new Point2f(0, 0),
            new Point2f(0, 480),
            new Point2f(640, 480),
            new Point2f(640, 0),
        };

        using (var matrix = Cv2.GetPerspectiveTransform(srcPoints, dstPoints))
        using (var src = new Mat("Images/1.jpg"))
        using (var dst = new Mat(new Size(640, 480), MatType.CV_8UC3))
        {
            // 透视变换
            Cv2.WarpPerspective(src, dst, matrix, dst.Size());
            using (new Window("result", dst))
            {
                Cv2.WaitKey();
            }
        }
    }

你可能感兴趣的:(OpencvSharp-图像修正)