Need help with function copy() and video

<
import processing.video.*;

String PATH = “MVI_3180.MP4”;
Movie gare;

void setup() {

size(1440, 900);
frameRate(30);
gare = new Movie(this, PATH);
gare.play();
}

void movieEvent(Movie m) {
m.read();
}

void draw() {

image(gare, 0, 0, 1440, 900);

// SOURCE
int sx = mouseX-75;
int sy = mouseY-75;
int sw = 150;
int sh = 150;

// DESTINATION
int dx = width/2-75;
int dy = height/2-75;
int dw = 150;
int dh = 150;

copy (sx, sy, sw, sh, dx, dy, dw, dh);

//background(0);

noFill();
fill(#ffffff);
noStroke();
ellipse(mouseX, mouseY, 10, 10);
}

Hello!

And welcome to the forum !

Great to have you here !

here is a version with an image instead of movie…

but it works

PImage gare; 

void setup() {

  size(1440, 900);
  frameRate(30);

  gare=loadImage("BB1bUFxv.jpg");

  //gare = new Movie(this, PATH);
  //gare.play();
}

//void movieEvent(Movie m) {
//  m.read();
//}

void draw() {

  image(gare, 
    0, 0, 1440, 900);

  // SOURCE
  int sx = mouseX-75;
  int sy = mouseY-75;
  int sw = 150;
  int sh = 150;

  // DESTINATION
  int dx = width/2-75;
  int dy = height/2-75;
  int dw = 150;
  int dh = 150;

  copy (sx, sy, sw, sh, 
    dx, dy, dw, dh);

  //background(0);

  // noFill();
  fill(#ffffff);
  noStroke();
  ellipse(mouseX, mouseY, 10, 10);
}

1 Like

Hello,
thank you so much your answer !
and also for your greeting :grin:

Unfortunately, I forgot to write that my problem was that I would like to have all the rest in black (juste the little square of pixel not in black --> like if you was searching information in the video with your mouse)

Sorry for my English I’m from Switzerland haha :wink:

Sure you’re actually wanting to use copy() and not image()?

eg.

background(0);
image(gare, dx, dy, dw, dh, sx, sy, sx + sw, sy + sh);
2 Likes

Okay, then you should not display the entire image at the start of draw()

here is the idea, I am not sure whether this works with movie images



PImage gare; 

void setup() {

  size(1440, 900);
  frameRate(30);

  gare=loadImage("BB1bUFxv.jpg");

  //gare = new Movie(this, PATH);
  //gare.play();
}

//void movieEvent(Movie m) {
//  m.read();
//}

void draw() {

  background (0);  // New. 

  //image(gare, 
  //  0, 0, 1440, 900);   // No. 

  // SOURCE
  int sx = mouseX-75;
  int sy = mouseY-75;
  int sw = 150;
  int sh = 150;

  // DESTINATION
  int dx = width/2-75;
  int dy = height/2-75;
  int dw = 150;
  int dh = 150;

  PImage my = gare.get (sx, sy, sw, sh);    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  image (my, 222, 222); 

  //background(0);

  // noFill();
  fill(#ffffff);
  noStroke();
  ellipse(mouseX, mouseY, 10, 10);
}

2 Likes

Yeaaaaah it’s work thank you so much !!
I’m very grateful to you :blush:
but it just deform the size but it’s work !!

1 Like

Oh yes it’s work also just small adjustments to be made but it works too thank you very much !!
:slight_smile:

1 Like

You could display the new small image also at mouse position.

Then you would see what’s directly underneath the mouse (real position of the section like in the movie)

2 Likes

The nine argument variant of image(..) will always be more efficient than get() (and potentially than copy()), with all the renderers, although particularly the non-default ones. So it’s worth looking at, even if not particularly well documented!

The key thing is that parameters 2-5 are the destination rectangle as position and dimensions. However 6-9 are the top-left and bottom-right coordinates of the source image. That’s why you have to add the source width to source x, and source height to source y. Upside of source being coordinates is that you can also have the second position to left and/or above the first to draw reversed.

If that sounds complicated, just play around with it! :smile:

1 Like

ah, my apologies, I didn’t get what you did there…

1 Like

Yes it’s another possibility ! :wink:
thanks

1 Like

I will try and play with it !
Thank you :blush: :pray: