Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. import gab.opencv.*;
  2. import processing.video.*;
  3. import java.awt.*;
  4.  
  5. PImage img;
  6. PImage select;
  7. PImage cur;
  8.  
  9. OpenCV opencv;
  10. Capture cam;
  11.  
  12. int prevPositionX, prevPositionY, currPositionX, currPositionY;
  13. int mode = -1; //mode 1 = s (select) mode 2 = c (copy) mode 3 = d (draw)
  14. int select_ind = -1;
  15.  
  16. //store every dectected things
  17. Rectangle[] hand;
  18.  
  19. //store the biggest hand
  20. Rectangle bhand;
  21.  
  22.  
  23. void setup() {
  24. size(1280, 480);
  25.  
  26. img = loadImage("test.jpg");
  27. cur = loadImage("cursor.png");
  28. stroke(255,10,0);
  29.  
  30. opencv = new OpenCV(this, 640, 480);
  31. opencv.loadCascade("aGest.xml");
  32. cam = new Capture(this, 640, 480);
  33. cam.start();
  34.  
  35. image(img, 0, 0, img.width, img.height);
  36. }
  37.  
  38.  
  39. void draw(){
  40. if (cam.available()==true) {
  41. cam.read();
  42. }
  43.  
  44. opencv.loadImage(cam);
  45. hand = opencv.detect();
  46.  
  47. pushMatrix();
  48. scale(-1.0, 1.0);
  49. image(cam, -1280, 0);
  50. popMatrix();
  51.  
  52. int handcount = -1;
  53. int handsize = -1;
  54.  
  55. //calculate the biggest hand
  56. for( int i=0; i < hand.length; i++ ) {
  57. if(handsize < (hand[i].width * hand[i].height)){
  58. handsize = hand[i].width * hand[i].height;
  59. handcount = 1;
  60. bhand = hand[i];
  61. }
  62. }
  63.  
  64. if(handcount > 0){
  65. rect(1280 - bhand.x, bhand.y, -bhand.width, bhand.height);
  66. noFill();
  67.  
  68. //draw the position indicator
  69. image(cur, 480 - bhand.x, bhand.y, 16, 16);
  70.  
  71. prevPositionX = currPositionX;
  72. prevPositionY = currPositionY;
  73. currPositionX = 480 - bhand.x + 4;
  74. currPositionY = bhand.y;
  75.  
  76. //select mode
  77. if (mode == 1){
  78. }
  79.  
  80. //copy mode
  81. else if (mode == 2){
  82. }
  83.  
  84. //draw mode
  85. else if (mode == 3){
  86. line(prevPositionX,prevPositionY,currPositionX,currPositionY);
  87. }
  88. }
  89. }
  90.  
  91.  
  92. void keyPressed(){
  93. if(key=='s'||key=='S')
  94. mode = 1;
  95.  
  96. else if(key=='c'||key=='C')
  97. mode = 2;
  98.  
  99. else if(key=='d'||key=='D')
  100. mode = 3;
  101.  
  102. else if(key=='i'||key=='I')
  103. image(img, 0, 0, img.width, img.height);
  104. }
  105.  
  106.  
  107.  
  108. void keyReleased(){
  109. if(select_ind > -1 && mode == 2){
  110. //to be done
  111.  
  112. }
  113.  
  114. mode = -1;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement