123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Drawing;
- using bbiwarg.Utility;
- using Emgu.CV;
- using Emgu.CV.Structure;
- namespace bbiwarg.Detectors.Palm
- {
- class PalmRect
- {
- private Vector2D origin;
- private Matrix<float> transformationMatrix;
- public PalmRect(MCvBox2D palmRect)
- {
- PointF[] vertices = palmRect.GetVertices();
- origin = new Vector2D(vertices[1]);
- PointF v0 = vertices[0];
- PointF v2 = vertices[2];
- Matrix<float> tmp = new Matrix<float>(new float[,] { { v0.X - origin.X, v2.X - origin.X }, { v0.Y - origin.Y, v2.Y - origin.Y } });
- transformationMatrix = new Matrix<float>(2, 2);
- CvInvoke.cvInvert(tmp.Ptr, transformationMatrix.Ptr, Emgu.CV.CvEnum.SOLVE_METHOD.CV_LU);
- }
- public bool isWithinMargin(Vector2D position)
- {
- Vector2D relativePosition = getRelativePosition(position);
- return (relativePosition.X >= -0.1 && relativePosition.X <= 1.1 && relativePosition.Y >= -0.1 && relativePosition.Y <= 1.1);
- }
- public Vector2D getRelativePosition(Vector2D absolutePosition)
- {
- Vector2D v = absolutePosition - origin;
- Matrix<float> coordsMatrix = transformationMatrix.Mul(new Matrix<float>(new float[,] { { v.X }, { v.Y } }));
- return new Vector2D(coordsMatrix.Data[0, 0], coordsMatrix.Data[1, 0]);
- }
- }
- }
|