Advertisement
Guest User

Untitled

a guest
May 28th, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. import JMyron.*;
  2. import pFaceDetect.*;
  3.  
  4. JMyron m;
  5. PFaceDetect face;
  6. PFaceDetect hand;
  7. PImage img;
  8.  
  9. Robot robby;
  10.  
  11. int search_width = 320;
  12. int search_height = 240;
  13. float actualX=search_width/2;
  14. float actualY=search_height/2;
  15. int x_rato = 0;
  16. int y_rato = 0;
  17.  
  18. void setup() {
  19. size(320,240,P3D);
  20. m = new JMyron();
  21. m.start(width,height);
  22. face = new PFaceDetect(this,width,height, "haarcascade_frontalface_alt.xml");
  23. hand = new PFaceDetect(this,width,height, "aGest.xml");
  24.  
  25. img = createImage(width,height,ARGB);
  26. noFill();
  27. stroke(255,0,0);
  28.  
  29. try
  30. {
  31. robby = new Robot();
  32. }
  33. catch (AWTException e)
  34. {
  35. println("Robot class not supported by your system!");
  36. exit();
  37. }
  38. }
  39.  
  40. void draw() {
  41. m.update();
  42.  
  43. int[] imgNormal = m.cameraImage();
  44. this.loadPixels();
  45. for(int i=1; i<width;i++){
  46. for(int j=1;j<height;j++){
  47. this.pixels[(m.width() - i - 1) + j * m.width()] = imgNormal[(i) + j * m.width()];
  48. }
  49. }
  50. this.updatePixels();
  51.  
  52. arraycopy(m.cameraImage(),img.pixels);
  53.  
  54. face.findFaces(img);
  55. drawFace();
  56. hand.findFaces(img);
  57. drawHand();
  58.  
  59. // code for drawing the lines
  60. line((width/2-10),0,(width/2-10),height);
  61. line((width/2+10),0,(width/2+10),height);
  62. line(0,(height/2-10),width,(height/2-10));
  63. line(0,(height/2+10),width,(height/2+10));
  64.  
  65. //verifica posição do ponto
  66. //diagonal subir para direita
  67. if (actualX < (width/2-10) && actualY < (height/2-10))
  68. {
  69. x_rato = x_rato + 4;
  70. y_rato = y_rato - 4;
  71. }
  72.  
  73. else if (actualX > (width/2+10) && actualY < (height/2-10))
  74. {
  75. x_rato = x_rato - 4;
  76. y_rato = y_rato - 4;
  77. }
  78. //subir
  79. else if (actualX < (width/2+10) && actualX > (width/2-10) && actualY < (height/2-10))
  80. {
  81. y_rato = y_rato - 4;
  82. }
  83.  
  84. else if (actualX < (width/2+10) && actualX > (width/2-10) && actualY > (height/2+10))
  85. {
  86. y_rato = y_rato + 4;
  87. }
  88.  
  89. else if (actualX < (width/2-10) && actualY > (height/2+10))
  90. {
  91. x_rato = x_rato + 4;
  92. y_rato = y_rato + 4;
  93. }
  94. //diagonal descer para esquerda
  95. else if (actualX > (width/2+10) && actualY > (height/2+10))
  96. {
  97. x_rato = x_rato - 4;
  98. y_rato = y_rato + 4;
  99. }
  100. else if (actualX > (width/2+10) && actualY < (height/2+10) && actualY > (height/2-10))
  101. {
  102. x_rato = x_rato - 4;
  103. }
  104.  
  105. else if (actualX < (width/2-10) && actualY < (height/2+10) && actualY > (height/2-10))
  106. {
  107. x_rato = x_rato + 4;
  108. }
  109. print(actualY+"n");
  110. robby.mouseMove(screen.width/2+x_rato, screen.height/2+y_rato);
  111. }
  112.  
  113. void drawFace() {
  114. int [][] res = face.getFaces();
  115. if (res.length>0) {
  116. for (int i=0;i<res.length;i++) {
  117. int x = res[i][0];
  118. int y = res[i][1];
  119. int w = res[i][2];
  120. int h = res[i][3];
  121. x = x + w/2;
  122. actualX = round(actualX + 0.1*(x-actualX));
  123. y = y + h/2;
  124. actualY = round(actualY + 0.1*(y-actualY));
  125. /*pushMatrix();
  126. strokeWeight(10);*/
  127. point(width-actualX, actualY);
  128. //popMatrix();
  129. }
  130. }
  131. }
  132.  
  133. void drawHand() {
  134. int [][] res = hand.getFaces();
  135. if (res.length>0) {
  136. print("ai"+"n");
  137. robby.mousePress(InputEvent.BUTTON1_MASK);
  138. robby.delay(500);
  139. robby.mouseRelease(InputEvent.BUTTON1_MASK);
  140. }
  141. }
  142.  
  143.  
  144. void stop() {
  145. m.stop();
  146. super.stop();
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement