'img cannot be resolved to a variable'

I’m trying to create a script that will print image frames by interval,

current code:

int xpos = 0;
int ypos = 0;
int VWIDTH = 8; // width of capture
int VHEIGHT = 6; // height of capture
int MOVIEWIDTH = VWIDTH * 60; // width is equivalent to 1 minute of film time
int MOVIEHEIGHT = VHEIGHT * 130; // 130 minutes
int MAXWIDTH = MOVIEWIDTH - VWIDTH;
int MAXHEIGHT = MOVIEHEIGHT - VHEIGHT;
boolean capture = false;
boolean newFrame = false;

void setup()
{
  surface.setSize(MOVIEWIDTH, MOVIEHEIGHT);
  background(0);
}

void mousePressed() {
  // click screen to start capture
  // click again to take screengrab if required
  if (capture == false) {
    capture = true;
  } 
  else {
    saveFrame();
  }

}

void videoEvent()
{
  newFrame = true;
}

void loop()
{
  if(newFrame && capture==true) {

    image(img,xpos, ypos);
    xpos += VWIDTH;
    if (xpos > MAXWIDTH) {
      xpos = 0;
      ypos += VHEIGHT;
    }
    if (ypos > MAXHEIGHT) {
      saveFrame();
      ypos = 0;
      background(0);
    }
    newFrame = false;
  }
}

any fix suggestions welcome!

1 Like

Maybe you forgot to say PImage img; previous to setup() or to load img in setup with loadImage()

2 Likes

loop or draw() is it?

What language?

2 Likes

please format your code posting by pasting it into the

</> code button

of the editor header menu ( context name: Preformatted text )
it looks like
```
type or paste code here
```

also can use the ``` manually above and below your code.

thank you.


for start using ( the video ) lib stay close to the examples
https://processing.org/reference/libraries/video/Capture.html

1 Like

Hi sorry, very new to programming, so I’m trying to create a script that captures frames of a video and arranges them on a grid (60x130)

int xpos = 0;
int ypos = 0;
int VWIDTH = 8; // width of capture
int VHEIGHT = 6; // height of capture
int MOVIEWIDTH = VWIDTH * 60; // width is equivalent to 1 minute of film time
int MOVIEHEIGHT = VHEIGHT * 130; // 130 minutes
int MAXWIDTH = MOVIEWIDTH - VWIDTH;
int MAXHEIGHT = MOVIEHEIGHT - VHEIGHT;
boolean capture = false;
boolean newFrame = false;

void setup()
{
  surface.setSize(MOVIEWIDTH, MOVIEHEIGHT);
  background(0);
}

void mousePressed() {
  // click screen to start capture
  // click again to take screengrab if required
  if (capture == false) {
    capture = true;
  } 
  else {
    saveFrame();
  }

}

void videoEvent()
{
  newFrame = true;
}

void loop()
{
  if(newFrame && capture==true) {

    image(img,xpos, ypos);
    xpos += VWIDTH;
    if (xpos > MAXWIDTH) {
      xpos = 0;
      ypos += VHEIGHT;
    }
    if (ypos > MAXHEIGHT) {
      saveFrame();
      ypos = 0;
      background(0);
    }
    newFrame = false;
  }
}

processing JAVA does not know capture or videoEvent

but you can
after install processing 3.5.3
install a video library via contribution manager
PDE / Tools / Add Tool /
Libraries / Video /

Video 1.0.1 The Processing Foundation  GStreamer-based video library for Processing.

after that might need restart processing IDE
find:
PDE / File / Examples / Libraries / Video / Movies / Frame /

using

import processing.video.*;

a example what play a existing video file and show next frame on [->]

if that is not what you want, please try again to describe what you want to do.
but above you say:


while in the first post you say

for that ignore all the video things and just use

and start from example:
PDE / File / Examples / Topics / File IO / SaveFrames

2 Likes

Isn’t it void draw and not void loop in the first place?

2 Likes

This is perfect, thanks!

1 Like