Annonce

>>> Bienvenue sur codelab! >>> Première visite ? >>> quelques mots sur codelab //// une carte des membres//// (apéros) codelab


#1 2016-01-13 20:27:24 Convertir un traitement photographique en traitement vidéo

lindecis
membre
Date d'inscription: 2015-02-09
Messages: 15

Convertir un traitement photographique en traitement vidéo



Bonjour,
Interessé par le rendu de nombreux sketch destinés à des images, j'aurais aimé connaitre la manière la plus simple pour les transformer en sketch pouvant traité une vidéo.

Voici par exemple un sketch de traitement photo que j'apprécie. Je l'ai récupéré sur le site du livre Design Génératif:

// P_4_3_1_02.pde
// 
// Generative Gestaltung, ISBN: 978-3-87439-759-9
// First Edition, Hermann Schmidt, Mainz, 2009
// Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
// Copyright 2009 Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
//
// http://www.generative-gestaltung.de
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * pixel mapping. each pixel is translated into a new element (svg file).
 * take care to sort the svg file according to their greyscale value.
 * see also "_4_3_1_02_analyse_svg_grayscale.pde" 
 * 
 * KEYS
 * s                   : save png
 * p                   : save pdf
 */
 
import processing.pdf.*;
import java.util.Calendar;

boolean savePDF = false;

PShape[] shapes;
int shapeCount = 0;

PImage img;

void setup() {
  size(600, 900); 
  smooth();
  img = loadImage("pic.png");
  println(img.width+" x "+img.height);

  // ------ load shapes ------
  // replace this location with a folder on your machine or use selectFolder()
  //File dir = new File(selectFolder("choose a folder with svg files ..."));
  File dir = new File(sketchPath(""),"data");
  if (dir.isDirectory()) {
    String[] contents = dir.list();
    shapes = new PShape[contents.length]; 
    for (int i = 0 ; i < contents.length; i++) {
      // skip hidden files and folders starting with a dot, load .svg files only
      if (contents[i].charAt(0) == '.') continue;
      else if (contents[i].toLowerCase().endsWith(".svg")) {
        File childFile = new File(dir, contents[i]);
        println(childFile.getPath());        
        shapes[shapeCount] = loadShape(childFile.getPath());
        shapeCount++;             
      }
    }
  }
  
  println(shapeCount);
}

void draw() {
  if (savePDF) beginRecord(PDF, timestamp()+".pdf");
  background(255);

  float mouseXFactor = map(mouseX, 0,width, 0.05,1);
  float mouseYFactor = map(mouseY, 0,height, 0.05,1);

  for (int gridX = 0; gridX < img.width; gridX++) {
    for (int gridY = 0; gridY < img.height; gridY++) {
      // grid position + tile size
      float tileWidth = width / (float)img.width;
      float tileHeight = height / (float)img.height;
      float posX = tileWidth*gridX;
      float posY = tileHeight*gridY;

      // get current color
      color c = img.pixels[gridY*img.width+gridX];
      // greyscale conversion
      int greyscale = round(red(c)*0.222+green(c)*0.707+blue(c)*0.071);

      int gradientToIndex = round(map(greyscale, 0,255, 0,shapeCount-1));
      shape(shapes[gradientToIndex], posX,posY, tileWidth,tileHeight);
    }
  }

  if (savePDF) {
    savePDF = false;
    endRecord();
  }
}

void keyReleased() {
  if (key == 's' || key == 'S') saveFrame(timestamp()+"_##.png");
  if (key == 'p' || key == 'P') savePDF = true;
}

// timestamp
String timestamp() {
  Calendar now = Calendar.getInstance();
  return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now);
}

Je souhaitais grossièrement le mixer avec un sketch de lecture vidéo simple que j'ai trouvé dans les exemple de la librairie vidéo, c'est pixelate:

/**
 * Pixelate  
 * by Hernando Barragan.  
 * 
 * Load a QuickTime file and display the video signal 
 * using rectangles as pixels by reading the values stored 
 * in the current video frame pixels array. 
 */

import processing.video.*;

int numPixelsWide, numPixelsHigh;
int blockSize = 10;
Movie mov;
color movColors[];

void setup() {
  size(640, 360);
  noStroke();
  mov = new Movie(this, "transit.mov");
  mov.loop();
  numPixelsWide = width / blockSize;
  numPixelsHigh = height / blockSize;
  println(numPixelsWide);
  movColors = new color[numPixelsWide * numPixelsHigh];
}

// Display values from movie
void draw() {
  if (mov.available() == true) {
    mov.read();
    mov.loadPixels();
    int count = 0;
    for (int j = 0; j < numPixelsHigh; j++) {
      for (int i = 0; i < numPixelsWide; i++) {
        movColors[count] = mov.get(i*blockSize, j*blockSize);
        count++;
      }
    }
  }

  background(255);
  for (int j = 0; j < numPixelsHigh; j++) {
    for (int i = 0; i < numPixelsWide; i++) {
      fill(movColors[j*numPixelsWide + i]);
      rect(i*blockSize, j*blockSize, blockSize, blockSize);
    }
  }

}

Peut-importe mes tentatives, a aucun moment je trouve un truc lisible par processing. Est ce vraiment impossible de convertir ce traitement image en traitement vidéo ? Si le calcul est trop lourd en visualisation directe, est-ce possible de demander à processing un fichier vidéo ?

Merci d'avance pour vos réponse

Hors ligne

 

#2 2016-01-13 20:31:56 Re : Convertir un traitement photographique en traitement vidéo

lindecis
membre
Date d'inscription: 2015-02-09
Messages: 15

Re: Convertir un traitement photographique en traitement vidéo



Je crois que le problème vient d'une contrariété entre le mode "active" et "static", c'est ce que me dit processing pour le moment dans un sketch en cours:

import processing.video.*;
import processing.pdf.*;
import java.util.Calendar;

boolean savePDF = false;


int numPixelsWide, numPixelsHigh;
int blockSize = 10;
Movie mov;
color movColors[];

void setup() {
  size(640, 360);
  noStroke();
  mov = new Movie(this, "transit.mov");
  mov.loop();
  numPixelsWide = width / blockSize;
  numPixelsHigh = height / blockSize;
  println(numPixelsWide);
  movColors = new color[numPixelsWide * numPixelsHigh];
  
  println(img.width+" x "+img.height);
  
  // ------ load shapes ------
  // replace this location with a folder on your machine or use selectFolder()
  //File dir = new File(selectFolder("choose a folder with svg files ..."));
  File dir = new File(sketchPath(""),"data");
  if (dir.isDirectory()) {
    String[] contents = dir.list();
    shapes = new PShape[contents.length]; 
    for (int i = 0 ; i < contents.length; i++) {
      // skip hidden files and folders starting with a dot, load .svg files only
      if (contents[i].charAt(0) == '.') continue;
      else if (contents[i].toLowerCase().endsWith(".svg")) {
        File childFile = new File(dir, contents[i]);
        println(childFile.getPath());        
        shapes[shapeCount] = loadShape(childFile.getPath());
        shapeCount++;             
      }
    }
  }
    println(shapeCount);
}

   background(255);
   
   if (mov.available() == true) {
    mov.read();
    mov.loadPixels();
    
      float mouseXFactor = map(mouseX, 0,width, 0.05,1);
  float mouseYFactor = map(mouseY, 0,height, 0.05,1);
  
    int count = 0;
     // grid position + tile size
      float tileWidth = width / (float)img.width;
      float tileHeight = height / (float)img.height;
      float posX = tileWidth*gridX;
      float posY = tileHeight*gridY;
        movColors[count] = mov.get(i*blockSize, j*blockSize);
        count++;
      }
    }
  }

Hors ligne

 

fil rss de cette discussion : rss

Pied de page des forums

Powered by FluxBB

codelab, graphisme & code : emoc / 2008-2024