Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import gab.opencv.*;
- import processing.video.*;
- import java.awt.*;
- PImage img;
- PImage select;
- PImage cur;
- OpenCV opencv;
- Capture cam;
- int prevPositionX, prevPositionY, currPositionX, currPositionY;
- int mode = -1; //mode 1 = s (select) mode 2 = c (copy) mode 3 = d (draw)
- int select_ind = -1;
- //store every dectected things
- Rectangle[] hand;
- //store the biggest hand
- Rectangle bhand;
- void setup() {
- size(1280, 480);
- img = loadImage("test.jpg");
- cur = loadImage("cursor.png");
- stroke(255,10,0);
- opencv = new OpenCV(this, 640, 480);
- opencv.loadCascade("aGest.xml");
- cam = new Capture(this, 640, 480);
- cam.start();
- image(img, 0, 0, img.width, img.height);
- }
- void draw(){
- if (cam.available()==true) {
- cam.read();
- }
- opencv.loadImage(cam);
- hand = opencv.detect();
- pushMatrix();
- scale(-1.0, 1.0);
- image(cam, -1280, 0);
- popMatrix();
- int handcount = -1;
- int handsize = -1;
- //calculate the biggest hand
- for( int i=0; i < hand.length; i++ ) {
- if(handsize < (hand[i].width * hand[i].height)){
- handsize = hand[i].width * hand[i].height;
- handcount = 1;
- bhand = hand[i];
- }
- }
- if(handcount > 0){
- rect(1280 - bhand.x, bhand.y, -bhand.width, bhand.height);
- noFill();
- //draw the position indicator
- image(cur, 480 - bhand.x, bhand.y, 16, 16);
- prevPositionX = currPositionX;
- prevPositionY = currPositionY;
- currPositionX = 480 - bhand.x + 4;
- currPositionY = bhand.y;
- //select mode
- if (mode == 1){
- }
- //copy mode
- else if (mode == 2){
- }
- //draw mode
- else if (mode == 3){
- line(prevPositionX,prevPositionY,currPositionX,currPositionY);
- }
- }
- }
- void keyPressed(){
- if(key=='s'||key=='S')
- mode = 1;
- else if(key=='c'||key=='C')
- mode = 2;
- else if(key=='d'||key=='D')
- mode = 3;
- else if(key=='i'||key=='I')
- image(img, 0, 0, img.width, img.height);
- }
- void keyReleased(){
- if(select_ind > -1 && mode == 2){
- //to be done
- }
- mode = -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement