本文整理汇总了C#中Contour.GetConvexityDefacts方法的典型用法代码示例。如果您正苦于以下问题:C# Contour.GetConvexityDefacts方法的具体用法?C# Contour.GetConvexityDefacts怎么用?C# Contour.GetConvexityDefacts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Contour
的用法示例。
在下文中一共展示了Contour.GetConvexityDefacts方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DetectFingers
public void DetectFingers(Image<Gray, Byte> image)
{
/*
Point3D ptHandProjective = this.depth.ConvertRealWorldToProjective(ptHand);
Size offset = new Size((int)ptHandProjective.X, (int)ptHandProjective.Y);
//get the hand
Image<Gray, Byte> image = detector.DetectHand(this.depth, ptHand);
*/
//image = image.PyrDown().PyrUp();
//image._SmoothGaussian(5);
//image._ThresholdBinary(new Gray(149), new Gray(255));
Graphics g = Graphics.FromImage(this.bitmap);
MemStorage storage1 = new MemStorage();
Contour<Point> contours = new Contour<Point>(storage1);
// Find the biggest contour
for (Contour<Point> tempContours = image.FindContours(); tempContours != null; tempContours = tempContours.HNext)
{
if (tempContours.Area > contours.Area)
contours = tempContours;
}
//Console.WriteLine(contours.Area);
if (contours.Area != 0)
{
List<KeyValuePair<Point, bool>> significantPts = new List<KeyValuePair<Point, bool>>();
Rectangle contourRectangle = contours.BoundingRectangle;
g.DrawRectangle(new Pen(Brushes.Green), contourRectangle);
//Seq<Point> contoursHull = contours.GetConvexHull(Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);
// Convert the set of contour points to a polygon for graphical representation
Seq<Point> poly = contours.ApproxPoly(20);
Point[] polygon = poly.ToArray();
PointF[] contourF = Array.ConvertAll(contours.ToArray(), new Converter<Point, PointF>(PointToPointF));
//CircleF palmCircle = PointCollection.MinEnclosingCircle(contourF);
//CircleF palmCircle = PointCollection.EllipseLeastSquareFitting(contourF);
//MCvBox2D box = PointCollection.MinAreaRect(contourF);
//g.DrawRectangle(new Pen(Brushes.Aquamarine),(Rectangle) box.MinAreaRect());
//drawCircle(g, new Pen(Brushes.Green), PointFToPoint(palmCircle.Center), (int) Math.Round(palmCircle.Radius));
// Get the convex hull based on the contour polygon
Seq<Point> convexHull = poly.GetConvexHull(Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);
/*
* Handle opening and closing of the fist each frame.
* Fisting gesture controls the left mouse button.
* Based on the ratio of area between the convex and the hull.
* (See calculation above) Threshold currently set to 0.8
*
* NEED TO HAND COORDINATES
*/
double hullArea = convexHull.Area;
double contourArea = contours.Area;
double currentHullRatio = contourArea / hullArea;
// newest ratio is in front of array
hullRatios[2] = hullRatios[1];
hullRatios[1] = hullRatios[0];
hullRatios[0] = currentHullRatio;
this.fixedHullRatio = hullRatios[2];
if (smoothHullRatios && this.frame > 3)
{
this.hullRatios = smoothHullRatioArray(this.hullRatios);
}
bool fistClosed = true;
stopTracking = true;
if (shouldHandClose())
{
stopTracking = true;
fistClosed = false;
}
if (shouldControlMouse)
{
//clickMouse(fistClosed);
}
// Get the convexity defects from the contour
stopwatch.Restart();
Seq<Emgu.CV.Structure.MCvConvexityDefect> contourDefects = contours.GetConvexityDefacts(storage1, Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);
stopwatch.Stop();
//Console.WriteLine(Math.Round(1000.0 * (double)stopwatch.ElapsedTicks / Stopwatch.Frequency, 4) + ", GetConvexityDefacts()");
// Draw the polygon that was converted from the contour
/*
for (int i = 0; i < polygon.Length; i++)
{
if (i == polygon.Length - 1)
g.DrawLine((new Pen(Brushes.Blue))), polygon[i], polygon[0]);
else
//.........这里部分代码省略.........
示例2: findFingerTips
private void findFingerTips(Contour<Point> bigContour, int scale)
{
Contour<Point> appContour = bigContour.ApproxPoly(bigContour.Perimeter * 0.0025, contourStorage);
hull = bigContour.GetConvexHull(Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);
defects = bigContour.GetConvexityDefacts(contourStorage, Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);
defectArray = defects.ToArray();
int defectsTotal = defectArray.Count();
if (defectsTotal > MAX_POINTS)
{
defectsTotal = MAX_POINTS;
}
// copy defect information from defects sequence into arrays
for (int i = 0; i < defectsTotal; i++)
{
MCvConvexityDefect cdf = defectArray.ElementAt(i);
Point startPt = cdf.StartPoint;
Point endPt = cdf.EndPoint;
Point depthPt = cdf.DepthPoint;
double sx = startPt.X;
double sy = startPt.Y;
tipPts[i] = new Point((int)Math.Round(sx * scale), (int)Math.Round(sy * scale)); // array contains coords of the fingertips
double dx = depthPt.X;
double dy = depthPt.Y;
foldPts[i] = new Point((int)Math.Round(dx * scale), (int)Math.Round(dy * scale)); //array contains coords of the skin fold between fingers
depths[i] = cdf.Depth * scale; // array contains distances from tips to folds
reduceTips(defectsTotal, tipPts, foldPts, depths);
}
}
示例3: DecideHandFromDefact
//凸包からのくぼみの数(=指の股の数)から現在の手がどれであるのかを決める。
private Hands DecideHandFromDefact(Contour<Point> contour)
{
if (contour == null)
{
return Hands.UNKNOWN;
}
//凸包からのくぼみを取得
Seq<MCvConvexityDefect> defacts = contour.GetConvexityDefacts(null, ORIENTATION.CV_CLOCKWISE);
int count = 0;
for (int i = 0; i < defacts.Count<MCvConvexityDefect>(); i++)
{
//領域の長さに対するくぼみの深さを求め、それが一定値以上だったら指の股としてカウント
double r = defacts.ElementAt<MCvConvexityDefect>(i).Depth / contour.Perimeter;
if (r > DefThreshold)
{
count++;
}
}
Console.WriteLine("{0:d}個の主要な欠損が見つかりました。", count);
if (count >= 3)
{
return Hands.PAPER;
}
else if (2 >= count && count >= 1)
{
return Hands.SCISSORS;
}
else if (count == 0)
{
return Hands.ROCK;
}
else
{
return Hands.UNKNOWN;
}
}