|
@@ -8,38 +8,66 @@ using Emgu.CV;
|
|
|
using Emgu.CV.Structure;
|
|
|
using System.Drawing;
|
|
|
|
|
|
+using bbiwarg.Detectors.Fingers;
|
|
|
+using bbiwarg.Utility;
|
|
|
+
|
|
|
namespace bbiwarg.Images
|
|
|
{
|
|
|
class PalmImage
|
|
|
{
|
|
|
private Image<Gray, Byte> image;
|
|
|
private int width, height;
|
|
|
- private Contour<Point> contour;
|
|
|
bool[,] inContour;
|
|
|
-
|
|
|
- public PalmImage(EdgeImage edgeImage)
|
|
|
+
|
|
|
+ public PalmImage(EdgeImage edgeImage, FingerTracker fingerTracker)
|
|
|
{
|
|
|
- image = edgeImage.getImage().Clone();
|
|
|
+ image = edgeImage.getImage(); //.Clone();
|
|
|
width = image.Width;
|
|
|
height = image.Height;
|
|
|
+
|
|
|
+ foreach (Finger f in fingerTracker.getFingers())
|
|
|
+ {
|
|
|
+ Vector<float> tip = new Vector<float>(new float[] { f.getTipPoint().x, f.getTipPoint().y });
|
|
|
+ Vector<float> hand = new Vector<float>(new float[] { f.getHandPoint().x, f.getHandPoint().y });
|
|
|
|
|
|
- findContours();
|
|
|
|
|
|
+ for (int x = 0; x < width; ++x)
|
|
|
+ {
|
|
|
+ for (int y = 0; y < height; ++y)
|
|
|
+ {
|
|
|
+ if (image.Data[y, x, 0] != 0)
|
|
|
+ {
|
|
|
+ Vector<float> p = new Vector<float>(new float[] { x, y });
|
|
|
|
|
|
-
|
|
|
+ float l2 = (tip - hand) * (tip - hand);
|
|
|
+ float t = (p - tip) * (hand - tip) / l2;
|
|
|
+ if (t >= 0.0 && t <= 1.0)
|
|
|
+ {
|
|
|
+ Vector<float> tmp = hand - tip;
|
|
|
+ tmp.multiply(t);
|
|
|
+ Vector<float> projection = tip + tmp;
|
|
|
+
|
|
|
+ if (p.distance(projection) <= 15)
|
|
|
+ image.Data[y, x, 0] = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ findContour();
|
|
|
}
|
|
|
|
|
|
- private void findContours()
|
|
|
+ private void findContour()
|
|
|
{
|
|
|
- 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);
|
|
|
+ //image = image.Dilate(1);
|
|
|
+ Contour<Point> contour = image.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_NONE,
|
|
|
+ Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST);
|
|
|
|
|
|
Contour<Point> maxContour = contour;
|
|
|
double maxPerimeter = 0;
|
|
|
- int count = 0;
|
|
|
while (contour != null)
|
|
|
{
|
|
|
- ++count;
|
|
|
if (contour.Perimeter > maxPerimeter)
|
|
|
{
|
|
|
maxPerimeter = contour.Perimeter;
|
|
@@ -48,11 +76,12 @@ namespace bbiwarg.Images
|
|
|
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;
|
|
|
+ if (maxContour != null)
|
|
|
+ {
|
|
|
+ foreach (Point p in maxContour)
|
|
|
+ inContour[p.X, p.Y] = true;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public bool belongsToPalm(int x, int y)
|