Implementing laser graffiti using processing

edited October 12 in How To...

hello , i am trying to implement laser graffiti in processing but i am having trouble in drawing line as the point of laser moves. I need to implement in such a way that as the laser light moves it should draw a line along with it. There is a simple code for continuous line in processing example( https://processing.org/examples/continuouslines.html ) i need same but with laser light tracking help me with this...

Tagged:

Answers

  • @krishna_18 -- re:

    but with laser light tracking

    What does this mean? Are you using a laptop / webcam? A special camera like a Kinect or a Wii sensor bar? Will this be a literal laser-pointer -- and if so what size / at what distance?

    Lasers are so bright that you could probably do this just using a high-pass filter on your camera -- check each camera pixel and draw the ones bright than n to the screen.

    But you could also use computer vision. This sounds like it might be an extremely simple case of blob detection for the OpenCV or BoofCV libraries.

  • If you image is static, you can use static background subtraction. You can check the examples under File>>Examples in the Processing IDE. Then go to Libraries>>Video>Capture and there should be a background subtraction example there. The concept is as follows:

    1. Start by capturing the background image.

    2. Then check any new image against a background image. If you find your laser pointer in the image by using image differentiation (either pixel by pixel comparison or using the blob library), store those pixels x,y or store the center of the blob.

    3. Then display the background image

    4. Finally, display the x,y coordinates of the blob either using the pixels stored before or by using a predefined shape like an ellipse.

    For the blob library, you need to install it using the library manager in the Processing IDE. Then you can go to the example section and explore the provided examples that come with the library.

    Kf

  • edited October 13

    @jeremydouglass

    i am using logitech Webcam having resolution 1280x720. it should detect the laser light from 20-30meter distance.

  • edited October 17

    @krishna_18 --

    You could use the OpenCV, BoofCV, or blob / blobdetector libraries to detect your point, then feed those coordinates into the continuous line drawing sketch.

    This presumes that your laser is the brightest thing on camera -- i.e. that it is brighter than whatever you are drawing, if you are projecting the drawing into the same scene as the laser.

    If that is the case, you could also use an extremely simple brightest point detector.

    I don't have a laser pointer and camera setup handy, but here is a demo of a brightest point detector using a fake mouse-driven "laser":

    /**
     * LaserPointerDetector
     * Mocks up a fake "laser pointer" under the mouse.
     * It then draws a box around the brightest point in the scene.
     * Assumes that the laser pointer will contain the brightest point!
     * 2017-10-16 Jeremy Douglass - Processing 3.3.6
     * forum.processing.org/two/discussion/24516/implementing-laser-graffiti-using-processing
     */
    PImage bg;
    
    void setup() {
      colorMode(HSB, 255);
      frameRate(10);
      bg = loadImage("https://processing.org/img/processing3-logo.png");
      bg.resize(width,height);
    }
    
    void draw() {
      background(0);
      fakeScene();
      fakePointer(mouseX, mouseY);
      PVector pv = brightPointDetector();
      drawDetectBox(pv);
    }
    
    PVector brightPointDetector() {
      int idx = 0;
      float max = 0;
      loadPixels();
      for (int i = 0; i < pixels.length; i++) {
        float pb = brightness(pixels[i]);
        if ( pb >= max) {
          max = pb;
          idx = i;
        }
      }
      int x = idx%width;
      int y = (idx-x)/width;
      return new PVector(x, y);
    }
    
    void fakeScene(){
      pushStyle();
      tint(255,128);
      image(bg, 0, 0);
      popStyle();
    }
    
    void fakePointer(float x, float y) {
      pushStyle();
      fill(255, 255, 255, 16);
      noStroke();
      ellipseMode(CENTER);
      for (int i=0; i<20; i++) {
        pushMatrix();
        translate(random(-5, 5), random(-5, 5));
        ellipse(x, y, random(10, 30), random(10, 30));
        popMatrix();
      }
      popStyle();
    }
    
    void drawDetectBox(PVector pv) {
      pushStyle();
      noFill();
      stroke(255);
      rectMode(CENTER);
      rect(pv.x, pv.y, 30, 30);
      popStyle();
    }
    

    As you can see, it works pretty well.

    LaserPointerDetector--screenshot

    Now, how to use those accurate coordinates and draw a continuous line with them...?

Sign In or Register to comment.