ISSN 2616-8901. Математика және жаратылыстану-техникалық сериясы № 4 / 2018 техникалық ғылымдар» сериясы 20, //threshold
30, //min Line width
10); //gap between lines
watch.Stop();
msgBuilder.Append(String.Format("Canny
&
Hough
lines
-
{0}
ms;
",
watch.ElapsedMilliseconds));
#endregion
Үшбұрыштар мен төртбұрыштар пішіндерін анықтайтын код: #region Find triangles and rectangles
watch.Reset(); watch.Start();
List triangleList = new List();
List boxList = new List(); //a box is a rotated rectangle
using (VectorOfVectorOfPoint contours = new
VectorOfVectorOfPoint())
{
CvInvoke.FindContours(cannyEdges,
contours,
null,
RetrType.List,
ChainApproxMethod.ChainApproxSimple );
int count = contours.Size;
for (int i = 0; i < count; i++)
{
using (VectorOfPoint contour = contours[i])
using (VectorOfPoint approxContour = new VectorOfPoint())
{
CvInvoke.ApproxPolyDP(contour, approxContour,
CvInvoke.ArcLength(contour, true) * 0.05, true);
if (CvInvoke.ContourArea(approxContour, false) > 250) //only consider contours with
area greater than 250
{
if (approxContour.Size == 3) //The contour has 3 vertices, it is a triangle
{
Point[] pts = approxContour.ToArray();
triangleList.Add(new Triangle2DF(
pts[0],
pts[1],
pts[2]
));
} else if (approxContour.Size == 4) //The contour has 4 vertices.
{
#region determine if all the angles in the contour are within [80,
100] degree
bool isRectangle = true;
Point[] pts = approxContour.ToArray();
LineSegment2D[] edges = PointCollection.PolyLine(pts, true);
for (int j = 0; j < edges.Length; j++)
{
double angle = Math.Abs(edges[(j+1)%
edges.Length].GetExteriorAngleDegree(edges[j]));
if (angle < 80 || angle > 100)
{
isRectangle = false;
break;
}