Logo Mon Club Elec

Processing – Capture Vidéo avec GSVideo et GLGraphics : Capture d’un flux vidéo avec la librairie GSVideo couplée aux librairies openGL (native) et GLGraphics.

La capture vidéo est un outil puissant pour les artistes et les développeurs qui souhaitent créer des expériences visuelles interactives. Avec la librairie GSVideo et les librairies openGL (native) et GLGraphics, il est possible de capturer un flux vidéo et de le traiter pour créer des effets visuels intéressants. Dans cet article, nous allons examiner comment capturer un flux vidéo avec GSVideo et GLGraphics et comment le traiter pour créer des effets visuels intéressants.

Processing – Capture Vidéo avec GSVideo et GLGraphics : Capture d’un flux vidéo avec la librairie GSVideo couplée aux librairies openGL (native) et GLGraphics.

Explication

  • L’utilisation de la librairie GLGraphics permet de réduire l’utilisation de la CPU lors de la capture vidéo en utilisant un conteneur GLTexture pour le stockage des frames vidéos.
Processing – Capture Vidéo avec GSVideo et GLGraphics : Capture d’un flux vidéo avec la librairie GSVideo couplée aux librairies openGL (native) et GLGraphics.
  • Comme le montre ce graphique,
    • les 4 threads de la CPU sont davantage sollicités avec GSVideo utilisée seule (moitié gauche)
    • que lorsque les librairies openGL et GLGraphics sont utilisées pour la capture (moitié droite)
  • Ceci est bon à savoir pour les applications nécessitant une utilisation CPU critique…

Matériel et configuration utilisés

  • PC Intel Core Quad 2.33 Ghz
  • Webcam(s) USB Hercules DualPix Exchange
  • Ubuntu 10.04 LTS
  • Processing 1-5
  • Librairie GSVideo 0.9
  • Librairie GLGraphics 0.99

Ressources utiles

  • Librairie GSVideo
  • Librairie openGL
  • Librairie GLGraphics

Le programme

// Using integration with GLGraphics for fast video playback.
// All the decoding stages, until the color conversion from YUV
// to RGB are handled by gstreamer, and the video frames are
// directly transfered over to the OpenGL texture encapsulated
// by the GLTexture object.
// You need the GLGraphics library (0.99+) to use this functionality:
// http://glgraphics.sourceforge.net/

import processing.opengl.*; // librairie openGL pour Processing (librairie native)

import codeanticode.glgraphics.*; // librairie GLGraphics

import codeanticode.gsvideo.*; // librairie GS Video

GSCapture cam; // objet GSCapture = webcam
GLTexture tex; // objet GLTexture = conteneur d’image vidéo – étend PImage

void setup() {
  size(320, 240, GLConstants.GLGRAPHICS); // initialisation graphique pour openGL

  cam = new GSCapture(this, 640, 480); // initialise webcam

  // Use texture tex as the destination for the camera pixels.
  tex = new GLTexture(this); // initialise objet GLTexture
  cam.setPixelDest(tex);  // initialise la destination pour l’image vidéo – ici le conteneur GLTexture  
  cam.start(); // démarre la webcam

  /*
  // You can get the resolutions supported by the
  // capture device using the resolutions() method.
  // It must be called after creating the capture
  // object.
  int[][] res = cam.resolutions();
  for (int i = 0; i < res.length; i++) {
    println(res[i][0] + « x » + res[i][1]);
  }
  */

  /*
  // You can also get the framerates supported by the
  // capture device:
  String[] fps = cam.framerates();
  for (int i = 0; i < fps.length; i++) {
    println(fps[i]);
  }
  */
 
}

void captureEvent(GSCapture cam) { // est appelée lorsqu’une capture survient
  cam.read(); // acquisition d’une nouvelle frame
}

void draw() {
  // If there is a new frame available from the camera, the
  // putPixelsIntoTexture() function will copy it to the
  // video card and will return true.
  if (tex.putPixelsIntoTexture()) {

    //img1=tex;

    image(tex, 0, 0, width, height); // le plus efficace !

    //image(img1, 0, 0, width, height);

  }
}

 

Noter cet article

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Archive Mon Club Elec

Articles populaires

Newsletter

Inscrivez-vous maintenant et bénéficiez d'un soutien continu pour réaliser vos travaux électriques en toute sécurité.