12345678910111213141516171819202122232425262728293031323334353637383940 |
- 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 Palm
- {
- private Vector2D origin;
- private Matrix<float> transformationMatrix;
-
- public Palm(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 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]);
- }
- }
- }
|