Advertisement
Guest User

Untitled

a guest
Jul 1st, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. PImage img, mimg;
  2. PImage bimg;
  3. int[] mmask;
  4.  
  5. PImage sil;
  6.  
  7. boolean cameraInitDone = false;
  8.  
  9. boolean picture = false;
  10.  
  11. int holdMouse = 0;
  12. boolean a = false;
  13. boolean camLoaded = false;
  14.  
  15. //import java.util.Deque;
  16. //import java.util.ArrayDeque;
  17. //final Deque<PImage> ints = new ArrayDeque<PImage>();
  18.  
  19. void beginState1() {
  20. sil = loadImage("sil.png");
  21. println("STATE1");
  22. }
  23.  
  24. void updateState1() {
  25.  
  26. readInputs();
  27. calculations();
  28. writeOutputs();
  29. drawDisplay();
  30.  
  31. if (keyPressed) {
  32. if (key == '2') currentState = 2;
  33. if (key == '3') currentState = 3;
  34. }
  35.  
  36. background(100);
  37. // if (camera.available() == true) {
  38. // camera.read();
  39. // }
  40.  
  41. if (!cameraInitDone) {
  42. setupCam();
  43. background(100);
  44.  
  45. // return; // don't continue with code below but a start
  46. }
  47.  
  48. if (cameraInitDone) {
  49. PImage camImage = camera.get();
  50. image(camera, 0, 0);
  51.  
  52. camImage.loadPixels();
  53. for (int i=0; i<width*height; i++) {
  54.  
  55. int greenn=(camImage.pixels[i]>>8) & 0xff;
  56. int redd=(camImage.pixels[i]>>16) & 0xff;
  57. int bluee=camImage.pixels[i] & 0xff;
  58.  
  59. float thresh=map(mouseX, 0, width, 0, 255);
  60. float d=dist(redd, greenn, bluee, 0, 250, 0);
  61.  
  62. ////APPROACH #1: Testing only for green. Not perfect
  63. //if (greenn>thresh )
  64. ////APPROACH #2: Testing the boundary of green. Better performance
  65. if (d<thresh){
  66. mmask[i]=0;
  67. } else{
  68. mmask[i]=255;
  69. }
  70. }
  71.  
  72. mimg=camImage.get();
  73.  
  74. mimg.mask(mmask);
  75. }
  76. if (mousePressed == true) {
  77. if (camImgNr < camImageArray.length) {
  78.  
  79. }
  80. }
  81.  
  82. if (buttonValue == 1) {
  83. println("BUTTON");
  84. }
  85.  
  86. }
  87.  
  88. void mousePressed() {
  89. if (camImgNr < camImageArray.length) {
  90. if (mouseButton == LEFT)
  91. picture = true;
  92.  
  93. //ints.addFirst(mimg);
  94.  
  95. camImageArray[camImgNr] = mimg;
  96. currentState = 2;
  97. camImgNr ++;
  98. printArray(camImageArray);
  99. } else {
  100. // println("Removed oldest:", ints.pollLast());
  101.  
  102. }
  103. }
  104.  
  105. void endState1() {
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement