本文整理汇总了C#中OpenCvSharp.CPlusPlus.Mat.Size方法的典型用法代码示例。如果您正苦于以下问题:C# Mat.Size方法的具体用法?C# Mat.Size怎么用?C# Mat.Size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenCvSharp.CPlusPlus.Mat
的用法示例。
在下文中一共展示了Mat.Size方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例2: GetInitWrap
private void GetInitWrap(Mat image)
{
this.src[0] = new Point2f(0, 0);
this.src[1] = new Point2f(0, image.Height);
this.src[2] = new Point2f(image.Width, image.Height);
this.src[3] = new Point2f(image.Width, 0);
this.dst[0] = new Point2f(0, 0);
this.dst[1] = new Point2f(0, image.Height);
this.dst[2] = new Point2f(image.Width, image.Height);
this.dst[3] = new Point2f(image.Width, 0);
this.SetCanvasCenter(this.SrcMarkList[0], 0, 0);
this.SetCanvasCenter(this.SrcMarkList[1], 0, image.Height);
this.SetCanvasCenter(this.SrcMarkList[2], image.Width, image.Height);
this.SetCanvasCenter(this.SrcMarkList[3], image.Width, 0);
this.SetCanvasCenter(this.DstMarkList[0], 0, 0);
this.SetCanvasCenter(this.DstMarkList[1], 0, image.Height);
this.SetCanvasCenter(this.DstMarkList[2], image.Width, image.Height);
this.SetCanvasCenter(this.DstMarkList[3], image.Width, 0);
this.UpdateLines();
this.m_Mask = new Mat(image.Size(), MatType.CV_8UC1, new Scalar(0));
List<List<Point>> polygons = new List<List<Point>>();
List<Point> polygon = new List<Point>();
polygons.Add(polygon);
foreach (var p in this.dst)
{
polygon.Add(new Point(p.X, p.Y));
}
Cv2.FillPoly(this.m_Mask, polygons, new Scalar(255));
this.SetWarp();
}