Simple live capture and scanner effect with mouse

Hi all!

I hope you can help me with this! I am trying to create sort of a scanner effect. When you move the mouse from left to right you’ll move the “beam” that’s capturing. I got this simple code working so far, but now I want it to capture the part from the webcam that is actually in that same beam. So, as you can see now the “beam” moves with the mouseX, but keeps capturing the same part. How do I make it so that it captures a different part every time the mouseX moves based on where on the screen the mouseX is?

I hope it’s clear!

import processing.video.*;

Capture video;

int x = 0;

void setup(){
  size(640, 240);
  video = new Capture(this, 320, 240);
  video.start();
}

void captureEvent(Capture video) {
  video.read();
}

void draw(){
  //image(video,0,0);
  int w = video.width;
  int h = video.height;
  copy(video, w/2,0,20,h,x,0,20,h);
  
  x = mouseX;
}

Do you mean this?:


import processing.video.*;

Capture video;

float x = 0;

void setup(){
  size(640, 240);
  video = new Capture(this, 320, 240);
  video.start();
}

void captureEvent(Capture video) {
  video.read();
}

void draw(){
  //image(video,0,0);
  int w = video.width;
  int h = video.height;
  copy(video, int(x)/2,0,20,h,  int(x), 0, 20 ,h);
  
 x =mouseX; // or x =random( 0,width);   
}
1 Like

YES THANK YOU!!! Very helpful!!

only one more question: how can I mirror the video?

Look this line : copy(video, int(x)/2 , 0 , 20, h, int(abs(x-width)), 0, 20 , h);
This mirror the image ,but not the mouse move (of course)

Try this:

import processing.video.*;

Capture video;

float x = 0;


void setup(){
  size(640, 240);
  video = new Capture(this, 320, 240);
  video.start();
}

void captureEvent(Capture video) {
  video.read();
}

void draw(){
  int w = video.width;
  int h = video.height;
  x =mouseX;
   // copy(video, int(x)/2 , 0 , 20, h,  int(x), 0, 20 , h);
   copy(video, int(x)/2 , 0 , 20, h,  int(abs(x-width)), 0, 20 , h); 

}

Does this also resolve your related to your question here?