static void Main(string[] args)
{
// 輸入需要轉(zhuǎn)變的圖的四個(gè)角的坐標(biāo)(可以通過代碼獲得)
var srcPoints = new Point2f[] {
new Point2f(69, 110),
new Point2f(81, 857),
new Point2f(1042, 786),
new Point2f(1038, 147),
};
// 需要轉(zhuǎn)換的圖指定轉(zhuǎn)換后四個(gè)角的坐標(biāo)
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();
}
}
}