Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PImage img, mimg;
- PImage bimg;
- int[] mmask;
- PImage sil;
- boolean cameraInitDone = false;
- boolean picture = false;
- int holdMouse = 0;
- boolean a = false;
- boolean camLoaded = false;
- //import java.util.Deque;
- //import java.util.ArrayDeque;
- //final Deque<PImage> ints = new ArrayDeque<PImage>();
- void beginState1() {
- sil = loadImage("sil.png");
- println("STATE1");
- }
- void updateState1() {
- readInputs();
- calculations();
- writeOutputs();
- drawDisplay();
- if (keyPressed) {
- if (key == '2') currentState = 2;
- if (key == '3') currentState = 3;
- }
- background(100);
- // if (camera.available() == true) {
- // camera.read();
- // }
- if (!cameraInitDone) {
- setupCam();
- background(100);
- // return; // don't continue with code below but a start
- }
- if (cameraInitDone) {
- PImage camImage = camera.get();
- image(camera, 0, 0);
- camImage.loadPixels();
- for (int i=0; i<width*height; i++) {
- int greenn=(camImage.pixels[i]>>8) & 0xff;
- int redd=(camImage.pixels[i]>>16) & 0xff;
- int bluee=camImage.pixels[i] & 0xff;
- float thresh=map(mouseX, 0, width, 0, 255);
- float d=dist(redd, greenn, bluee, 0, 250, 0);
- ////APPROACH #1: Testing only for green. Not perfect
- //if (greenn>thresh )
- ////APPROACH #2: Testing the boundary of green. Better performance
- if (d<thresh){
- mmask[i]=0;
- } else{
- mmask[i]=255;
- }
- }
- mimg=camImage.get();
- mimg.mask(mmask);
- }
- if (mousePressed == true) {
- if (camImgNr < camImageArray.length) {
- }
- }
- if (buttonValue == 1) {
- println("BUTTON");
- }
- }
- void mousePressed() {
- if (camImgNr < camImageArray.length) {
- if (mouseButton == LEFT)
- picture = true;
- //ints.addFirst(mimg);
- camImageArray[camImgNr] = mimg;
- currentState = 2;
- camImgNr ++;
- printArray(camImageArray);
- } else {
- // println("Removed oldest:", ints.pollLast());
- }
- }
- void endState1() {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement