private Mat DisplayTriangleOnInfrared(Mat infraredMat, Triangle2DF tri) { using (Mat convertMat = new Mat(infraredMat.Size, DepthType.Cv8U, 1)) { infraredMat.ConvertTo(convertMat, DepthType.Cv8U, 1 / 256d); Mat displayMat = new Mat(infraredMat.Size, DepthType.Cv8U, 3); CvInvoke.CvtColor(convertMat, displayMat, ColorConversion.Gray2Bgr); CvInvoke.Polylines(displayMat, Array.ConvertAll(tri.GetVertices(), System.Drawing.Point.Round), true, new Bgr(0, 0, 255).MCvScalar, 2); return(displayMat); } }
private void CalculateNormal(Mat depthMat, Triangle2DF tri) { if (depthMat == null || (tri.Centeroid.X == 0 && tri.Centeroid.Y == 0)) { return; } var vertices = Array.ConvertAll(tri.GetVertices(), System.Drawing.Point.Round); var point2dList = vertices;// Kolos.haromszog.belsopontok(vertices); #region Kolos normalvektor //var point3dList = new List<Kolos.pont3d>(); //foreach (var point2d in point2dList) { // var zcoord = GetMatElementU16(depthMat, point2d.X, point2d.Y); // if(zcoord != 0) // point3dList.Add(CalculateWorldPosition(point2d.X, point2d.Y, depthMat.Cols, zcoord)); //} //var normal = Kolos.normalvektor.kiszamitas(point3dList); //Console.WriteLine($"Normálvektor X:{normal[0].ToString("F4")} Y:{normal[1].ToString("F4")}, Z: {normal[2].ToString("F4")}"); #endregion MCvPoint3D32f[] vertices3d = new MCvPoint3D32f[3]; for (int i = 0; i < 3; i++) { var point2d = point2dList[i]; var zcoord = GetMatElementU16(depthMat, point2d.X, point2d.Y); if (zcoord == 0) { return; } var point3d = CalculateWorldPosition(point2d.X, point2d.Y, depthMat.Cols, zcoord); vertices3d[i] = new MCvPoint3D32f((float)point3d.x, (float)point3d.y, (float)point3d.z); } var tri3d = new Triangle3DF(vertices3d[0], vertices3d[1], vertices3d[2]); var normal = tri3d.Normal; Console.WriteLine($"Normal: X:{normal.X} Y:{normal.Y} Z:{normal.Z}"); }