3DSelfie  Hansjoerg Hofer (1026632), Sebastian Metzler (0927550)
grabPicture.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using System.Collections;
3 using System.Collections.Generic;
4 
5 public class grabPicture : MonoBehaviour {
6 
7 
8  public bool nextRenderStep = false;
9 
10  public int renderStep = 0;
11 
12  GameObject sQuad;
13  screenQuad quadScript;
14  Camera binaryCam;
15 
16  public Texture2D binaryImageHead;
17  public Texture2D binaryImageEyebrows;
18  public Texture2D binaryImageFace;
19  public Texture2D binaryImageAll;
20  public Texture2D colorImage;
21 
22  public Texture2D colorImageSide;
23  public Texture2D binaryImageFaceSide;
24  public Texture2D binaryImageEyesSide;
25  public Texture2D binaryImageMouthSide;
26 
27  float screenHeight;
28  float screenWidth;
29 
30  int texHeight;
31  int texWidth;
32 
33  float[] xHist;
34  float[] yHist;
35 
36  public int eyesYdist = 0;
37  public int eyesXdist = 0;
38  public int eyesXdistBorder = 0;
39  public int eyeBrowsXdistBorder = 0;
40 
41  public int mouthYdist = 0;
42  public int mouthXdist = 0;
43 
44  public int noseYdist = 0;
45 
46  Rect eyesArea;
47  Rect eyesAreaTex;
48  Rect mouthArea;
49  Rect mouthAreaTex;
50  Rect eyeBrowsArea;
51  Rect eyeBrowsAreaTex;
52 
53 
54 
55  Rect leftEyeArea;
56  Rect rightEyeArea;
57 
58 
59  LineRenderer eyesHelpLines;
60  LineRenderer mouthHelpLines;
61  LineRenderer leftEyeHelpLines;
62  LineRenderer rightEyeHelpLines;
63  LineRenderer eyeBrowsHelpLines;
64 
65  Controller controller;
66 
67  bool snakeOK = false;
68 
69 
70  private float[] thresholds ;
71  public float[] faceT;
72  public float[] eyesT;
73  public float[] eyeBrowsT;
74  public float[] mouthT;
75 
76  public string buttonText;
77 
78 
86  void Start () {
87 
88  buttonText = "Capture Face Contour";
89 
90  sQuad = GameObject.Find ("ScreenQuad");
91  quadScript = sQuad.GetComponent<screenQuad> ();
92 
93  Camera mainCam = GameObject.Find ("Main Camera").GetComponent<Camera> ();
94 
95  binaryCam = gameObject.GetComponent<Camera>();
96  binaryCam.enabled = false;
97 
98 
99  screenHeight = (float)Screen.height;
100  screenWidth = (float)Screen.width;
101 
102 
103  texWidth = sQuad.GetComponent<Renderer> ().material.mainTexture.width;
104  texHeight = sQuad.GetComponent<Renderer> ().material.mainTexture.height;
105 
106 
107  reset ();
108 
109  eyesArea = new Rect ( 0.25f, 0.5f, 0.5f, 0.055f);
110  eyeBrowsArea = new Rect ( 0.2f, 0.56f, 0.6f, 0.08f);
111  mouthArea = new Rect ( 0.35f, 0.312f, 0.3f, 0.08f);
112  leftEyeArea = new Rect ( 0.275f, 0.51f, 0.15f, 0.04f);
113  rightEyeArea = new Rect ( 0.575f, 0.51f, 0.15f, 0.04f);
114  setHelpLines ();
115 
116 
117  eyeBrowsAreaTex = new Rect (eyeBrowsArea.xMin * texWidth, eyeBrowsArea.yMin * texHeight, eyeBrowsArea.width * texWidth, eyeBrowsArea.height * texHeight);
118  eyesAreaTex = new Rect (eyesArea.xMin * texWidth, eyesArea.yMin * texHeight, eyesArea.width * texWidth, eyesArea.height * texHeight);
119  mouthAreaTex = new Rect ( mouthArea.xMin * texWidth, mouthArea.yMin * texHeight, mouthArea.width * texWidth, mouthArea.height * texHeight);
120 
121 
122  controller = GameObject.Find ("SnakeScript").GetComponent<Controller> ();
123 
124  }
125 
131  public void reset(){
132 
133  Camera.main.transform.position = new Vector3 (0.5f, 0.5f, -2f);
134  snake = false;
135 
136  binaryImageHead = new Texture2D (texWidth, texHeight);
137  binaryImageFace = new Texture2D (texWidth, texHeight);
138  binaryImageEyebrows = new Texture2D (texWidth, texHeight);
139  binaryImageFaceSide = new Texture2D (texWidth, texHeight);
140 
141  for (int x =0; x<texWidth; x++)
142  for (int y=0; y<texHeight; y++) {
143  binaryImageFace.SetPixel (x, y, Color.white);
144  binaryImageEyebrows.SetPixel (x, y, Color.white);
145  }
146 
147  renderStep = 0;
148  quadScript.webcamTexture.Play();
149  thresholds = faceT;
150 
151 
152  GameObject.Find ("ResizeQuad").transform.localScale = new Vector3 (1.8f, 1.0f, 1f);
153  GameObject.Find ("ResizeQuad").transform.localPosition = new Vector3 (0.5f, 0.5f, 0f);
154 
155 
156  }
157 
163  public void setHelpLines(){
164 
165  eyesHelpLines = GameObject.Find ("EyesHelpLines").GetComponent<LineRenderer>();
166  setHelpLines(eyesArea, eyesHelpLines);
167 
168  leftEyeHelpLines = GameObject.Find ("LeftEyeHelpLines").GetComponent<LineRenderer>();
169  setHelpLines(leftEyeArea, leftEyeHelpLines);
170 
171  rightEyeHelpLines = GameObject.Find ("RightEyeHelpLines").GetComponent<LineRenderer>();
172  setHelpLines(rightEyeArea, rightEyeHelpLines);
173 
174  mouthHelpLines = GameObject.Find ("MouthHelpLines").GetComponent<LineRenderer>();
175  setHelpLines(mouthArea, mouthHelpLines);
176 
177  eyeBrowsHelpLines = GameObject.Find ("EyeBrowsHelpLines").GetComponent<LineRenderer>();
178  setHelpLines(eyeBrowsArea, eyeBrowsHelpLines);
179 
180  }
181 
190  void setHelpLines(Rect area, LineRenderer g){
191  g.SetPosition(0, new Vector3(area.xMin * 0.6f + 0.2f, (area.yMin), -1.0f));
192  g.SetPosition(1, new Vector3(area.xMin * 0.6f + 0.2f, (area.yMax), -1.0f));
193  g.SetPosition(2, new Vector3(area.xMax * 0.6f + 0.2f, (area.yMax), -1.0f));
194  g.SetPosition(3, new Vector3(area.xMax * 0.6f + 0.2f, (area.yMin), -1.0f));
195  g.SetPosition(4, new Vector3(area.xMin * 0.6f + 0.2f, (area.yMin), -1.0f));
196 
197 
198  g.SetPosition(5, new Vector3(area.xMax * 0.6f + 0.2f, (area.yMin), -1.0f));
199  g.SetPosition(6, new Vector3(area.xMax * 0.6f + 0.2f, (area.yMax), -1.0f));
200  g.SetPosition(7, new Vector3(area.xMin * 0.6f + 0.2f, (area.yMax), -1.0f));
201  g.SetPosition(8, new Vector3(area.xMin * 0.6f + 0.2f, (area.yMin), -1.0f));
202 
203 
204  }
205 
211  bool snake = false;
212  bool nextStep = false;
213 
214  void Update () {
215 
216  if (renderStep > 6 && !snake)
217  startSnake ();
218 
219  if (nextStep) {
220  nextStep = false;
221 
222  if (renderStep > 6){
223 // reset ();
224  }else{
225  nextRenderStep = true;
226 
227  if(renderStep == 5){
228 
229  quadScript.webcamTexture.Stop();
230 
231  findFaceSide();
232  }
233 
234  if(renderStep == 4){
235  findMouth();
236 
237  buttonText = "Capture Sideview Contour";
238  }
239 
240  if(renderStep == 3){
241  findEyeBrows();
242 
243  buttonText = "Capture Mouth Contour";
244  }
245  if(renderStep == 2){
246  findEyes();
247 
248  buttonText = "Capture Eyebrows Contour";
249  }
250 
251  if (renderStep == 0) {
252 
253  quadScript.webcamTexture.Stop();
254 
255  buttonText = "Capture Eyes Contour";
256 
257  renderCamImage(0, 0);
258 
259  findFace();
260  }
261  }
262  }
263  }
264 
272  void setHelpLinesEnabled(bool e){
273 
274  eyesHelpLines.enabled = e;
275  mouthHelpLines.enabled = e;
276  leftEyeHelpLines.enabled = e;
277  rightEyeHelpLines.enabled = e;
278  eyeBrowsHelpLines.enabled = e;
279 
280  }
291  public void renderCamImage(int thresholdEnabled, int binaryEnabled){
292 
293  int thresholdPrev = sQuad.GetComponent<Renderer> ().material.GetInt ("_ThresholdMode");
294  int binaryPrev = sQuad.GetComponent<Renderer> ().material.GetInt ("_BinaryMode");
295 
296  sQuad.GetComponent<Renderer>().material.SetFloat ("_ThresholdMode", thresholdEnabled);
297  sQuad.GetComponent<Renderer>().material.SetFloat ("_BinaryMode", binaryEnabled);
298 
299  setHelpLinesEnabled (false);
300 
301 
302  binaryCam.enabled = true;
303  binaryCam.Render ();
304  binaryCam.enabled = false;
305 
306 
307  setHelpLinesEnabled (true);
308 
309  sQuad.GetComponent<Renderer>().material.SetFloat ("_ThresholdMode", thresholdPrev);
310  sQuad.GetComponent<Renderer>().material.SetFloat ("_BinaryMode", binaryPrev);
311  }
312 
320  private void renderCam(string camName){
321 
322  Camera cam = GameObject.Find (camName).GetComponent<Camera> ();
323  cam.enabled = true;
324  cam.Render ();
325  cam.enabled = false;
326  }
327 
328 
335  private void renderAllCams(){
336 
337  renderCam("gaussXCam");
338  renderCam("gaussYCam");
339  renderCam("CornerCamera");
340  renderCam("dFdxCam");
341  renderCam("dFdyCam");
342 
343  }
344 
352  public void OnPostRender(){
353 
354  if (nextRenderStep) {
355  nextRenderStep = false;
356 
357  if(renderStep == 6){
358 
359  colorImageSide = new Texture2D (texWidth, texHeight);
360  colorImageSide.ReadPixels (binaryCam.pixelRect, 0, 0);
361  colorImageSide.Apply ();
362  }
363 
364 
365  if(renderStep == 5){
366 
367  binaryImageFaceSide.ReadPixels (binaryCam.pixelRect, 0, 0);
368  binaryImageFaceSide.Apply ();
369  }
370 
371  //render mouth binary
372 
373  if(renderStep == 4){
374 
375  binaryImageFace.ReadPixels (mouthAreaTex, (int)mouthAreaTex.xMin, (int)mouthAreaTex.yMin);
376  binaryImageFace.Apply ();
377  binaryImageAll.ReadPixels (mouthAreaTex, (int)mouthAreaTex.xMin, (int)mouthAreaTex.yMin);
378  binaryImageAll.Apply();
379  }
380 
381  //render eyebrows binary
382  if(renderStep == 3){
383 
384  binaryImageEyebrows.ReadPixels (eyeBrowsAreaTex, (int)eyeBrowsAreaTex.xMin, (int)eyeBrowsAreaTex.yMin);
385  binaryImageEyebrows.Apply ();
386  binaryImageAll.ReadPixels (eyeBrowsAreaTex, (int)eyeBrowsAreaTex.xMin, (int)eyeBrowsAreaTex.yMin);
387  binaryImageAll.Apply();
388 
389  }
390 
391  //render eyes binary
392  if (renderStep == 2) {
393 
394  binaryImageFace.ReadPixels (eyesAreaTex, (int)eyesAreaTex.xMin, (int)eyesAreaTex.yMin);
395  binaryImageFace.Apply ();
396  binaryImageAll.ReadPixels (eyesAreaTex, (int)eyesAreaTex.xMin, (int)eyesAreaTex.yMin);
397  binaryImageAll.Apply();
398  }
399 
400  //render contour binary
401  if (renderStep == 1) {
402 
403  binaryImageHead.ReadPixels (binaryCam.pixelRect, 0, 0);
404  binaryImageHead.Apply ();
405  binaryImageAll = binaryImageHead;
406  binaryImageAll.Apply ();
407  }
408 
409  if (renderStep == 0) {
410  colorImage = new Texture2D (texWidth, texHeight);
411  colorImage.ReadPixels (binaryCam.pixelRect, 0, 0);
412  colorImage.Apply ();
413  }
414 
415  renderStep++;
416  }
417 
418  }
419 
426  float faceHeight;
427  float faceYPos;
428 
429  void findFace(){
430  nextRenderStep = true;
431 
432  renderCamImage(1, 1);
433 
434  Histogram hist = new Histogram(binaryImageFace, new Rect(0f, 0f, 1f, 1f));
435 // List<KeyValuePair<int, float>> xc = hist.findCluster (hist.xHist);
436  List<KeyValuePair<int, float>> yc = hist.findCluster (hist.yHist);
437 
438  faceHeight = yc [yc.Count - 1].Value;
439  faceYPos = yc [yc.Count - 1].Key/texHeight;
440 
441  thresholds = eyesT;
442  }
443 
444  Vector2 leftEyePos;
445  Vector2 rightEyePos;
446 
447 
456  void findEyes(){
457  nextRenderStep = true;
458 
459 
460  renderCamImage(1, 1);
461 
462 
463  Histogram hist = new Histogram(binaryImageFace, eyesArea);
464  hist.draw ();
465 
466  Vector2[] eyesPos = findEyeFeatures (hist, eyesArea, eyesAreaTex, eyesXdistBorder);
467 
468 
469 
470  leftEyePos = eyesPos[0];
471  rightEyePos = eyesPos[1];
472 
473 
474  // Debug.DrawLine (new Vector3 (0.0f, leftEyeBrowPos.y, -1.0f), new Vector3 (2.0f, leftEyeBrowPos.y, -1.0f), Color.magenta, 30.0f, false);
475  Debug.DrawLine (new Vector3 (0.0f, leftEyePos.y, -1.0f), new Vector3 (2.0f, leftEyePos.y, -1.0f), Color.cyan, 30.0f, false);
476 
477  Debug.DrawLine (new Vector3 (leftEyePos.x, 1.0f, -1.0f), new Vector3 (leftEyePos.x, 0.0f, -1.0f), Color.cyan, 30.0f, false);
478  Debug.DrawLine (new Vector3 (rightEyePos.x, 1.0f, -1.0f), new Vector3 (rightEyePos.x, 0.0f, -1.0f), Color.cyan, 30.0f, false);
479  Debug.DrawLine (new Vector3 (1 + leftEyePos.x, 1.0f, -1.0f), new Vector3 (1 + leftEyePos.x, 0.0f, -1.0f), Color.cyan, 30.0f, false);
480  Debug.DrawLine (new Vector3 (1 + rightEyePos.x, 1.0f, -1.0f), new Vector3 (1 + rightEyePos.x, 0.0f, -1.0f), Color.cyan, 30.0f, false);
481 
482 
483 
484  thresholds = eyeBrowsT;
485 
486  }
487 
496  Vector2 leftEyeBrowPos;
497  Vector2 rightEyeBrowPos;
498 
499  void findEyeBrows(){
500 
501  nextRenderStep = true;
502 
503  renderCamImage(1, 1);
504 
505 
506  Histogram hist = new Histogram(binaryImageEyebrows, eyeBrowsArea);
507 // hist.draw ();
508 
509  Vector2[] eyeBrowsPos = findEyeFeatures (hist, eyeBrowsArea, eyeBrowsAreaTex, eyeBrowsXdistBorder);
510 
511 
512  leftEyeBrowPos = eyeBrowsPos[0];
513  rightEyeBrowPos = eyeBrowsPos[1];
514 
515  Debug.DrawLine (new Vector3 (0.0f, leftEyeBrowPos.y, -1.0f), new Vector3 (2.0f, leftEyeBrowPos.y, -1.0f), Color.cyan, 30.0f, false);
516 
517  Debug.DrawLine (new Vector3 (leftEyeBrowPos.x, 1.0f, -1.0f), new Vector3 (leftEyeBrowPos.x, 0.0f, -1.0f), Color.cyan, 30.0f, false);
518  Debug.DrawLine (new Vector3 (rightEyeBrowPos.x, 1.0f, -1.0f), new Vector3 (rightEyeBrowPos.x, 0.0f, -1.0f), Color.cyan, 30.0f, false);
519  Debug.DrawLine (new Vector3 (1 + leftEyeBrowPos.x, 1.0f, -1.0f), new Vector3 (1 + leftEyeBrowPos.x, 0.0f, -1.0f), Color.cyan, 30.0f, false);
520  Debug.DrawLine (new Vector3 (1 + rightEyeBrowPos.x, 1.0f, -1.0f), new Vector3 (1 + rightEyeBrowPos.x, 0.0f, -1.0f), Color.cyan, 30.0f, false);
521 
522 
523  thresholds = mouthT;
524 
525  }
526 
543  Vector2[] findEyeFeatures(Histogram hist, Rect area, Rect areaTex, int xDistBorder){
544 
545  //find y Position of eyes
546 
547 
548  List<KeyValuePair<int, float>> yMin = hist.findMin(hist.yHist);
549 
550  int m1 = 0;
551 
552  int[] bounds = hist.findSimilarArea (yMin [m1].Key, 1.0f, hist.yHist);
553  int min0 = (int)(bounds[0] + bounds[1]) / 2;
554 
555  Vector2 left = new Vector2 ();
556  Vector2 right = new Vector2 ();
557 
558  left.y = area.yMin + ((float)min0)/texHeight;
559  right.y = area.yMin + ((float)min0)/texHeight;
560 
561 
562  //find x Position of eyes
563 
564  List<KeyValuePair<int, float>> xMin = hist.findMin(hist.xHist);
565 
566  int m3 = 0;
567 
568  while (m3<xMin.Count && (xMin[m3].Key < xDistBorder || xMin[m3].Key > areaTex.xMax - areaTex.xMin - xDistBorder)) {
569  m3++;
570 
571  }
572 
573  bounds = hist.findSimilarArea (xMin [m3].Key, 1.0f, hist.xHist);
574 
575  int min1 = (int)(bounds[0] + bounds[1]) / 2;
576 
577  int m4=m3 +1;
578  while (m4<xMin.Count && (Mathf.Abs((min1- xMin[m4].Key)) < eyesXdist || xMin[m4].Key < xDistBorder || xMin[m4].Key > areaTex.xMax - areaTex.xMin - xDistBorder)) {
579  m4++;
580  }
581 
582  if(m4>= xMin.Count)
583  throw new MissingComponentException ("Could not find eye features)");
584 
585  bounds = hist.findSimilarArea (xMin [m4].Key, 1.0f, hist.xHist);
586 
587  int min2 = (int)(bounds[0] + bounds[1]) / 2;
588 
589 
590  if (min1 < min2) {
591  left.x = (area.xMin + ((float)min1)/texWidth) * 0.6f + 0.2f;
592  right.x = (area.xMin + ((float)min2)/texWidth) * 0.6f + 0.2f;
593  } else {
594  left.x = (area.xMin + ((float)min2)/texWidth) * 0.6f + 0.2f;
595  right.x = (area.xMin + ((float)min1)/texWidth) * 0.6f + 0.2f;
596  }
597 
598 
599  return new Vector2[]{left, right};
600  }
601 
602  Vector2 mouthPos;
603 
610  void findMouth(){
611 
612  nextRenderStep = true;
613  renderCamImage(1, 1);
614 
615  Histogram hist = new Histogram(binaryImageFace, mouthArea);
616 // hist.draw ();
617 
618 
619  List<KeyValuePair<int, float>> yMin = hist.findMin(hist.yHist);
620 
621  int m1 = 0;
622 
623  while ( m1<yMin.Count && (yMin[m1].Key < mouthYdist || yMin[m1].Key > mouthAreaTex.yMax - mouthAreaTex.yMin - mouthYdist)) {
624  m1++;
625  }
626 
627  List<KeyValuePair<int, float>> xMin = hist.findMin(hist.xHist);
628 
629  int m2 = 0;
630 
631  while ( m2<xMin.Count && (xMin[m2].Key < mouthXdist || xMin[m2].Key > mouthAreaTex.xMax - mouthAreaTex.xMin - mouthXdist)) {
632  m2++;
633  }
634 
635  mouthPos = new Vector2 ();
636 
637  mouthPos.x = (mouthArea.xMin + ((float)xMin[m2].Key)/texWidth) * 0.6f + 0.2f;
638  mouthPos.y = mouthArea.yMin + ((float)yMin[m1].Key)/texHeight;
639 
640  Debug.DrawLine (new Vector3 (0.0f, mouthPos.y, -1.0f), new Vector3 (2.0f, mouthPos.y, -1.0f), Color.green, 20.0f, false);
641  Debug.DrawLine (new Vector3 (mouthPos.x, 1.0f, -1.0f), new Vector3 (mouthPos.x, 0.0f, -1.0f), Color.green, 20.0f, false);
642  Debug.DrawLine (new Vector3 (mouthPos.x + 1f, 1.0f, -1.0f), new Vector3 (mouthPos.x + 1f, 0.0f, -1.0f), Color.green, 20.0f, false);
643 
644 
645  thresholds = faceT;
646 
647  quadScript.webcamTexture.Play ();
648 
649  setHelpLinesEnabled (false);
650  }
651 
662  void findFaceSide(){
663 
664  nextRenderStep = true;
665 
666  renderCamImage(1, 1);
667 
668  Histogram hist = new Histogram(binaryImageFaceSide, new Rect(0f, 0f, 1f, 1f));
669 
670  List<KeyValuePair<int, float>> xc = hist.findCluster (hist.xHist);
671  List<KeyValuePair<int, float>> yc = hist.findCluster (hist.yHist);
672 
673  float height = yc [yc.Count-1].Value;
674 
675  float scale = height / faceHeight;
676 
677 
678  Histogram hist2 = new Histogram(binaryImageFaceSide, new Rect(0f, 0f, 0.5f, 1f));
679  hist2.draw ();
680 
681  List<KeyValuePair<int, float>> yMax = hist2.findMax(hist2.yHist);
682 
683  int m1 = yMax.Count-1;
684 
685  while ( m1>=0 && (yMax[m1].Key < noseYdist || yMax[m1].Key > texHeight - noseYdist)) {
686  m1--;
687  }
688 
689  Debug.DrawLine (new Vector3 ( 0.0f, ((float)yMax[m1].Key)/((float)texHeight), -1.0f), new Vector3 ( 1.0f, ((float)yMax[m1].Key/texHeight), -1.0f), Color.yellow, 20.0f, false);
690 
691 
692  float nosePos = 0.55f;
693 
694  float yOffset = nosePos - yMax [m1].Key/texHeight;
695  float xOffset = 0.5f - (xc[xc.Count - 1].Key/texWidth) * 0.6f + 0.2f;
696 
697 
698  GameObject.Find ("ResizeQuad").transform.localScale *= scale;
699  GameObject.Find ("ResizeQuad").transform.position += new Vector3 (xOffset, yOffset, 0f);
700 
701 
702  nextRenderStep = true;
703  renderCamImage(0, 0);
704 
705 
706  GameObject.Find ("Head_mesh").GetComponent<Renderer> ().material.SetTexture ("_MainTex", colorImage);
707  GameObject.Find ("Head_mesh").GetComponent<Renderer> ().material.SetTexture ("_Side", colorImageSide);
708 
709 
710  Camera.main.transform.position = new Vector3 (1.5f, 0.5f, -2f);
711  GameObject.Find("SnakeScript").GetComponent<Renderer>().material.SetTexture ("_MainTex", binaryImageAll);
712 
713 
714  }
715 
725  private void startSnake(){
726 
727 
728  snake = true;
729 
730  controller.resetSnake ();
731 
732  GameObject.Find("GaussQuadX").GetComponent<Renderer>().material.mainTexture = binaryImageHead;
733  renderAllCams();
734 
735  controller.RunContourDeformation();
736 
737  GameObject.Find("GaussQuadX").GetComponent<Renderer>().material.mainTexture = binaryImageFace;
738  renderAllCams();
739 
740  controller.findFaceContours (leftEyePos, rightEyePos, mouthPos);
741 
742  controller.resetSnake ();
743 
744  GameObject.Find("GaussQuadX").GetComponent<Renderer>().material.mainTexture = binaryImageEyebrows;
745  renderAllCams();
746 
747  controller.findEyebrows (leftEyeBrowPos, rightEyeBrowPos);
748 
749  controller.ApplyDeformation ();
750 
751 
752  }
753 
760  void OnGUI() {
761 
762  if (renderStep <= 6) {
763  float sliderWidth = Screen.width * 0.1f;
764  float sliderY = Screen.height * 0.75f;
765  float sliderHeight = Screen.height * 0.2f;//screenHeight * 0.1f;
766 
767 
768  thresholds [0] = GUI.VerticalSlider (new Rect (Screen.width * 0.2f, sliderY, sliderWidth, sliderHeight), thresholds [0], 240.0F, 16.0F);
769  thresholds [1] = GUI.VerticalSlider (new Rect (Screen.width * 0.3f, sliderY, sliderWidth, sliderHeight), thresholds [1], 240.0F, 16.0F);
770  thresholds [2] = GUI.VerticalSlider (new Rect (Screen.width * 0.45f, sliderY, sliderWidth, sliderHeight), thresholds [2], 240.0F, 16.0F);
771  thresholds [3] = GUI.VerticalSlider (new Rect (Screen.width * 0.55f, sliderY, sliderWidth, sliderHeight), thresholds [3], 240.0F, 16.0F);
772 
773  thresholds [4] = GUI.VerticalSlider (new Rect (Screen.width * 0.7f, sliderY, sliderWidth, sliderHeight), thresholds [4], 240.0F, 16.0F);
774  thresholds [5] = GUI.VerticalSlider (new Rect (Screen.width * 0.8f, sliderY, sliderWidth, sliderHeight), thresholds [5], 240.0F, 16.0F);
775 
776  if (GUI.Button (new Rect (Screen.width / 2 - 75, 20, 200, 50), buttonText))
777  nextStep = true;
778 
779 
780  sQuad.GetComponent<Renderer> ().material.SetVector ("_Thresholds", new Vector4 (thresholds [2], thresholds [3], thresholds [4], thresholds [5]));
781  sQuad.GetComponent<Renderer> ().material.SetVector ("_Thresholds2", new Vector4 (thresholds [0], thresholds [1], 0, 0));
782  }
783 
784  }
785 }
int eyeBrowsXdistBorder
Definition: grabPicture.cs:39
Texture2D binaryImageHead
Definition: grabPicture.cs:16
Texture2D binaryImageAll
Definition: grabPicture.cs:19
float[] eyeBrowsT
Definition: grabPicture.cs:73
int renderStep
Definition: grabPicture.cs:10
int eyesXdistBorder
Definition: grabPicture.cs:38
float[] eyesT
Definition: grabPicture.cs:72
float[] mouthT
Definition: grabPicture.cs:74
void resetSnake()
Reinitializes the snake and control points script.
Definition: Controller.cs:84
void setHelpLines()
Sets help lines.
Definition: grabPicture.cs:163
List< KeyValuePair< int, float > > findCluster(float[] hist)
Finds all clusters in the given histogram.
Definition: Histogram.cs:137
bool nextRenderStep
Definition: grabPicture.cs:8
WebCamTexture webcamTexture
Definition: screenQuad.cs:12
void findEyebrows(Vector2 leftEyeBrowCenter, Vector2 rightEyeBrowCenter)
Runs the eyebrow deformation.
Definition: Controller.cs:73
screenQuad script
Definition: screenQuad.cs:9
float[] faceT
Definition: grabPicture.cs:71
Texture2D binaryImageFaceSide
Definition: grabPicture.cs:23
void OnPostRender()
Saves rendersteps into textures.
Definition: grabPicture.cs:352
Texture2D binaryImageEyebrows
Definition: grabPicture.cs:17
Texture2D binaryImageEyesSide
Definition: grabPicture.cs:24
int mouthXdist
Definition: grabPicture.cs:42
void RunContourDeformation()
runs the deformation for the face contour
Definition: Controller.cs:97
Control script.
Definition: Controller.cs:28
float[] xHist
Definition: Histogram.cs:11
string buttonText
Definition: grabPicture.cs:76
List< KeyValuePair< int, float > > findMin(float[] hist)
Finds all local minima in the given histogram.
Definition: Histogram.cs:84
float[] yHist
Definition: Histogram.cs:12
void renderCamImage(int thresholdEnabled, int binaryEnabled)
Renders the camera image.
Definition: grabPicture.cs:291
int height
Definition: screenQuad.cs:15
void reset()
Resets the image creation progress.
Definition: grabPicture.cs:131
Texture2D binaryImageMouthSide
Definition: grabPicture.cs:25
void ApplyDeformation()
Applies the deformation to the model.
Definition: Controller.cs:307
List< KeyValuePair< int, float > > findMax(float[] hist)
Finds all local maxima in the given histogram.
Definition: Histogram.cs:111
void draw()
Draws the histogram.
Definition: Histogram.cs:61
Texture2D colorImageSide
Definition: grabPicture.cs:22
int mouthYdist
Definition: grabPicture.cs:41
int[] findSimilarArea(int index, float eps, float[] hist)
Finds all surrounding Values, which are not larger than the value with the given index by eps in the ...
Definition: Histogram.cs:191
Texture2D binaryImageFace
Definition: grabPicture.cs:18
void findFaceContours(Vector2 leftEyeCenter, Vector2 rightEyeCenter, Vector2 mouthCenter)
Runs the left/rigt eye and mouth deformation.
Definition: Controller.cs:61
Texture2D colorImage
Definition: grabPicture.cs:20