void Start() { int i = 0; cubes = new CubeParams[8]; cubes[i] = new CubeParams("red", cubeColors[i++], new int[] { 0, 1, 3, 6, 9, 15 }); cubes[i] = new CubeParams("green", cubeColors[i++], new int[] { 2, 4, 7, 13, 19, 24 }); cubes[i] = new CubeParams("blue", cubeColors[i++], new int[] { 28, 5, 8, 10, 20, 47 }); cubes[i] = new CubeParams("pink", cubeColors[i++], new int[] { 33, 34, 11, 12, 17, 22 }); cubes[i] = new CubeParams("yellow", cubeColors[i++], new int[] { 14, 16, 37, 27, 39, 41 }); cubes[i] = new CubeParams("purple", cubeColors[i++], new int[] { 18, 21, 43, 44, 46, 23 }); cubes[i] = new CubeParams("cyan", cubeColors[i++], new int[] { 25, 26, 29, 35, 42, 38 }); cubes[i] = new CubeParams("brown", cubeColors[i++], new int[] { 30, 31, 32, 36, 45, 40 }); i = 0; rotation = new RotationParams[6]; rotation[i++] = new RotationParams(Axis4D.xy, 0f); rotation[i++] = new RotationParams(Axis4D.xz, 0f); rotation[i++] = new RotationParams(Axis4D.xw, 0f); rotation[i++] = new RotationParams(Axis4D.yz, 0f); rotation[i++] = new RotationParams(Axis4D.yw, 0f); rotation[i++] = new RotationParams(Axis4D.zw, 0f); ResetVertices(); SetupLineRenderer(); for (i = 0; i < faces.Length; i++) { FaceParams p = faces[i]; DrawFace(rotatedVerts[p.a], rotatedVerts[p.b], rotatedVerts[p.c], rotatedVerts[p.d], Vector3.zero, i, p.faceColor, p.faceGroup, p); } }
} // end of Face Update() public static Face MakeFace(GetModelInstance getModel, XmlGameActor xmlActor) { Face face = null; if (xmlActor != null) { FaceParams faceParams = xmlActor.FaceParams; if (faceParams != null) { switch (faceParams.TypeFace) { case FaceParams.FaceType.Boku: face = MakeBokuFace(getModel, faceParams); break; case FaceParams.FaceType.Wide: face = MakeWideFace(getModel, faceParams); break; case FaceParams.FaceType.Two: face = MakeTwoFace(getModel, faceParams); break; default: Debug.Assert(false, "Unknown face type"); break; } face.PupilCenter = faceParams.PupilCenter; face.PupilSize = faceParams.PupilSize; face.LidDistance = faceParams.LidDistance; face.EyeSpeed = faceParams.EyeSpeed; face.BlinkRange = faceParams.BlinkRange; face.MaxAsymmetry = faceParams.MaxAsymmetry; face.backgroundColor = new Vector4( faceParams.BackgroundColor, 1.0f); face.pupilsName = faceParams.PupilsName; face.pupilsCrossName = faceParams.PupilsCrossName; } } return(face); }
void DrawCube(CubeParams cube) { // Cube center is average of all vertices Vector4 cubeCenter = Vector3.zero; int numVerts = 0; for (int i = 0; i < cube.faceIndices.Length; i++) { int faceIndex = cube.faceIndices[i]; FaceParams p = faces[faceIndex]; cubeCenter += rotatedVerts[p.a]; cubeCenter += rotatedVerts[p.b]; cubeCenter += rotatedVerts[p.c]; cubeCenter += rotatedVerts[p.d]; numVerts += 4; } cubeCenter *= 1.0f / numVerts; if (drawDebug) { Debug.DrawLine(Vector3.zero, cubeCenter, Color.red); } for (int i = 0; i < cube.faceIndices.Length; i++) { int faceIndex = cube.faceIndices[i]; FaceParams p = faces[faceIndex]; DrawFace( VectorFromProjection(projection, rotatedVerts[p.a]), VectorFromProjection(projection, rotatedVerts[p.b]), VectorFromProjection(projection, rotatedVerts[p.c]), VectorFromProjection(projection, rotatedVerts[p.d]), VectorFromProjection(projection, cubeCenter), faceIndex, cube.cubeColor, cube.tag, p); } }
private static TwoFace MakeTwoFace(GetModelInstance getModel, FaceParams faceParams) { TwoFace face = new TwoFace(getModel); return(face); }
private static WideFace MakeWideFace(GetModelInstance getModel, FaceParams faceParams) { WideFace face = new WideFace(getModel); return(face); }
private static OneFace MakeBokuFace(GetModelInstance getModel, FaceParams faceParams) { OneFace face = new OneFace(getModel); return(face); }
void DrawFace(Vector3 a, Vector3 b, Vector3 c, Vector3 d, Vector3 cubeCenter, int faceIndex, Color color, string name, FaceParams p) { // might be able to do this with matrices (push, pop) if it gets more complex Vector3 pushOutCube = cubeCenter * pushOutCubeAmount; Vector3 faceCenter = 0.25f * (a + b + c + d); Vector3 pushOutFace = (faceCenter - cubeCenter) * pushOutFaceAmount; LineRenderer r = lineRendererRoot.transform.GetChild(faceIndex).GetComponent <LineRenderer>(); for (int i = 0; i < r.transform.childCount; i++) { Transform t = r.transform.GetChild(i); Destroy(t.gameObject); } r.colorGradient = CreateGradient(color, color); r.SetPosition(0, a + pushOutCube + pushOutFace); r.SetPosition(1, b + pushOutCube + pushOutFace); r.SetPosition(2, c + pushOutCube + pushOutFace); r.SetPosition(3, d + pushOutCube + pushOutFace); r.SetPosition(4, a + pushOutCube + pushOutFace); r.gameObject.name = "cube " + name; r.enabled = true; }
public static VectorOfVectorOfPoint Detect(IImage eye, int BinaryValue = 140, FaceParams MainFace = null) { Image <Gray, Byte> _eye = new Image <Gray, Byte>(eye.Bitmap); _eye = _eye.ThresholdBinary(new Gray(BinaryValue), new Gray(255)); VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint(); Mat Heir = new Mat(); CvInvoke.FindContours(_eye, contours, Heir, RetrType.External, ChainApproxMethod.ChainApproxSimple); VectorOfVectorOfPoint pupilAreas = new VectorOfVectorOfPoint(); if (MainFace != null) { MainFace.RightEyeImg = _eye; } for (int i = 0; i < contours.Size; i++) { double area = CvInvoke.ContourArea(contours[i]); if (area < 50 && area > 5) { pupilAreas.Push(contours[i]); } } return(pupilAreas); }
public static void Run(FaceParams MainFace, int SizeBufNum = 3, int BinaryValue = 143) { //Read the files as an 8-bit Bgr image long detectionTime; List <Rectangle> faces = new List <Rectangle>(); List <Rectangle> eyes = new List <Rectangle>(); Detect(MainFace.CurrentFrame, @"Haar\haarcascade_frontalface_default.xml", @"Haar\haarcascade_eye.xml", faces, eyes, out detectionTime); if (faces.Count == 1) { if (Math.Abs(MainFace.PrevFaceSize.X - faces[0].X) < SizeBufNum && !MainFace.PrevFaceSize.IsEmpty) { faces[0] = MainFace.PrevFaceSize; } CvInvoke.Rectangle(MainFace.CurrentFrame, faces[0], new Bgr(Color.Red).MCvScalar, 2); MainFace.FaceImg = new Mat((Mat)MainFace.CurrentFrame, faces[0]); MainFace.PrevFaceSize = faces[0]; } if (eyes.Count == 2) { if (eyes[0].X < eyes[1].X) //0 - правый, 1- левый { eyes.Reverse(); } if (Math.Abs(MainFace.PrevRightEyeSize.X - eyes[0].X) < SizeBufNum && !MainFace.PrevRightEyeSize.IsEmpty) { eyes[0] = MainFace.PrevRightEyeSize; } if (Math.Abs(MainFace.PrevLeftEyeSize.X - eyes[1].X) < SizeBufNum && !MainFace.PrevLeftEyeSize.IsEmpty) { eyes[1] = MainFace.PrevLeftEyeSize; } MainFace.PrevRightEyeSize = eyes[0]; MainFace.PrevLeftEyeSize = eyes[1]; MainFace.RightEyeImg = new Mat((Mat)MainFace.CurrentFrame, eyes[0]); MainFace.LeftEyeImg = new Mat((Mat)MainFace.CurrentFrame, eyes[1]); CvInvoke.Rectangle(MainFace.CurrentFrame, eyes[0], new Bgr(Color.Blue).MCvScalar, 2); CvInvoke.Rectangle(MainFace.CurrentFrame, eyes[1], new Bgr(Color.Green).MCvScalar, 2); VectorOfVectorOfPoint RightPupilAreas = PupilDetection.Detect(MainFace.RightEyeImg, BinaryValue, MainFace); VectorOfVectorOfPoint LeftPupilAreas = PupilDetection.Detect(MainFace.LeftEyeImg); for (int i = 0; i < RightPupilAreas.Size; i++) { CvInvoke.DrawContours(MainFace.RightEyeImg, RightPupilAreas, i, new MCvScalar(255, 0, 0)); } for (int i = 0; i < LeftPupilAreas.Size; i++) { CvInvoke.DrawContours(MainFace.LeftEyeImg, LeftPupilAreas, i, new MCvScalar(255, 0, 0)); } } }