How could do what a capture from webcam show croped (no resize)

edited November 2017 in Library Questions

How could do what a capture from webcam show croped in a square image like example 192x256 (or 400x400)? Not resize, crop.

import processing.video.*;
    Capture cam;    
    PImage uno;
    PImage dos;
    PImage img;
    PImage circulo;
    final int anchoCam = 1024;
    final int altoCam = 768;
    final int anchoLienzo = 1024;
    final int altoLienzo = 768;
    final int anchoImagen = anchoLienzo/2;
    final int altoImagen =altoLienzo/2;
    final int anchoDelta = (anchoCam-anchoImagen)/2;
    final int altoDelta = (altoCam-altoImagen)/2;
    void setup() {

          size (anchoLienzo, altoLienzo);
          cam = new Capture(this, anchoCam, altoCam, 30);

          cam.crop(anchoDelta, altoDelta, anchoImagen, altoImagen);

          cam.read();
          uno = cam.get();


          circulo = loadImage("circulo.jpg");
          res = 0.0;
        }

PImage updateImg(Capture cam, PImage lado) {
  cam.read();
  lado = cam.get();

     if ( img = loadImage(int(random(26, 50)) + ".jpg"));     //y aquí el 26 y el 50
 {
  lado.blend(img, 0, 0, anchoImagen, altoImagen, 0, 0, anchoImagen, altoImagen, SCREEN);
  lado.blend(circulo, 0, 0, anchoImagen, altoImagen, 0, 0, anchoImagen, altoImagen, MULTIPLY); //Se puede cambiar el modo de fusión de las fotos cambiando MULTIPLY por otro, como BLEND, ADD, SUBTRACT, DARKEST, LIGHTEST, DIFFERENCE, EXCLUSION, MULTIPLY, SCREEN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE o BURN.
  lado.filter(GRAY);
  return lado;}
}

void draw() {

  background (0);
  if (keyPressed) {

   if (key == 'a' || key == 'A') {

     uno = updateImg(cam, uno);
}

    else if (keyCode == DOWN) {

    }
  }
  image(uno, 300, 0, anchoImagen, altoImagen);
 }
Tagged:

Answers

Sign In or Register to comment.