Problems using Capture and loadPixels()

edited October 2013 in Questions about Code

Hello all! I'm trying to troubleshoot the below sketch. Right now, the camera capture for some reason zooms/enlarges (and goes outside the sketch) as the pixelation increases (i.e., less number of pixels, but larger pixels). I don't want the captured live video to zoom. Can anyone take a look and see where I went wrong? Thank you all!


import processing.video.*;

int videoScale;
int cols, rows;
int savedTime;
int totalTime = 5000;

Capture video;

void setup() {
  size(1200,1200);

  int videoScale = 5;
  cols = width/videoScale;
  rows = height/videoScale;
  video = new Capture(this,cols,rows,30);
  video.start();
  savedTime = millis();
}

void draw() {

  int passedTime = millis() - savedTime;

  if (video.available()) {
    video.read();
   }

   video.loadPixels();


  if (passedTime > totalTime){
    videoScale=videoScale;
    cols = width/(videoScale);
    rows = height/(videoScale);

    for (int i = 0; i < cols; i++) {
      for (int j = 0; j < rows; j++) {

        int x = i*videoScale;
        int y = j*videoScale;
        color c = video.pixels[i + j*video.width];
        fill(c);
        stroke(0);
        rect(x,y,videoScale,videoScale);
      }
    }
    savedTime = millis();

}else{

      for (int i = 0; i < cols; i++) {
      for (int j = 0; j < rows; j++) {

        int x = i*videoScale;
        int y = j*videoScale;
        color c = video.pixels[i + j*video.width];
        fill(c);
        stroke(0);
        rect(x,y,videoScale,videoScale);

      }
    }
}    
}

Answers

  • So let's start with what you actually want, and get this sorted out.

    Are you trying to pixelate the captured video?

  • I don't want the captured live video to zoom.

    You don't want it to zoom, but that's what you coded the rectangle to do. If you have a resizing rectangle with the video as the texture, then obviously the video will resize.

Sign In or Register to comment.