123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Emgu.CV;
- using Emgu.CV.Structure;
- using System.Drawing;
- namespace bbiwarg.Images
- {
- class PalmImage
- {
- private Image<Gray, Byte> image;
- private int width, height;
- private Contour<Point> contour;
- bool[,] inContour;
- public PalmImage(EdgeImage edgeImage)
- {
- image = edgeImage.getImage().Clone();
- width = image.Width;
- height = image.Height;
- findContours();
-
- }
- private void findContours()
- {
- image = image.Dilate(3);
- contour = image.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_NONE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_EXTERNAL);
- Contour<Point> maxContour = contour;
- double maxPerimeter = 0;
- int count = 0;
- while (contour != null)
- {
- ++count;
- if (contour.Perimeter > maxPerimeter)
- {
- maxPerimeter = contour.Perimeter;
- maxContour = contour;
- }
- contour = contour.HNext;
- }
- Console.WriteLine("numContours: " + count + "\nmaxPerimeter = " + maxPerimeter);
- inContour = new bool[width, height];
- foreach (Point p in maxContour)
- inContour[p.X, p.Y] = true;
- }
- public bool belongsToPalm(int x, int y)
- {
- return inContour[x, y];
- }
- }
- }
|