Opencvinvert Main.Opencvinvert HistoryHide minor edits - Show changes to output Added lines 120-211:
// Programme d'exemple de la librairie javacvPro // par X. HINAULT - Mars 2012 // Tous droits réservés - Licence GPLv3 // Exemple fonction invert import codeanticode.gsvideo.*; // importe la librairie vidéo GSVideo qui implémente GStreamer pour Processing (compatible Linux) // librairie comparable à la librairie native vidéo de Processing (qui implémente QuickTime..)- Voir Reference librairie Video Processing // cette librairie doit être présente dans le répertoire modes/java/libraries du répertoire Processing (1-5) // voir ici : http://gsvideo.sourceforge.net/ import monclubelec.javacvPro.*; // importe la librairie javacvPro PImage img; GSCapture cam; // déclare un objet GSCapture représentant une webcam // L'objet GSCapture étend PImage - se comporte comme un conteneur des frames issues de la webcam OpenCV opencv; // déclare un objet OpenCV principal int widthCapture=320; // largeur image capture int heightCapture=240; // hauteur image capture int fpsCapture=30; // framerate de Capture int millis0=0; // variable mémorisation millis() void setup(){ // fonction d'initialisation exécutée 1 fois au démarrage //--- initialise fenêtre Processing size (widthCapture*2, heightCapture); // crée une fenêtre Processing de la 2xtaille du buffer principal OpenCV //size (img.width, img.height); // aalternative en se basant sur l'image d'origine frameRate(fpsCapture); // taux de rafraichissement de l'image //---- initialise la webcam --- cam = new GSCapture(this, widthCapture, heightCapture); // forme simplifiée //cam = new GSCapture(this, widthCapture, heightCapture,"v4l2src","/dev/video1", fpsCapture); // Initialise objet GSCapture désignant webcam - forme complète //--- initialise OpenCV --- opencv = new OpenCV(this); // initialise objet OpenCV à partir du parent This opencv.allocate(widthCapture, heightCapture); // initialise les buffers OpenCv à la taille de l'image cam.start(); // démarre objet GSCapture = la webcam } void draw() { // fonction exécutée en boucle // Code capture GSVideo if (cam.available() == true) { // si une nouvelle frame est disponible sur la webcam background(0); // fond noir entre 2 images //------ gestion image webcam par GSCapture ------ cam.read(); // acquisition d'un frame //image(cam1, 0, 0); // affiche image //set(0, 0, cam); // affiche image - plus rapide //------- gestion image par Opencv ---------- //imgSrc=cam1.get(); // récupère l'image GS video dans Pimage //opencv.copy(imgSrc); // charge l'image dans le buffer openCV millis0=millis(); // mémorise millis() opencv.copy(cam.get()); // autre possibilité - charge directement l'image GSVideo dans le buffer openCV println("Durée chargement buffer OpenCV=" + (millis()-millis0)+"ms."); //--- affiche image de départ avant opération sur image --- image(opencv.getBuffer(),0,0); // affiche le buffer principal OpenCV dans la fenêtre Processing //--- opérations sur image --- millis0=millis(); // mémorise millis() //-- toutes ces formes sont possibles : opencv.invert(); // inverse le buffer principal OpenCV //opencv.invert(opencv.Buffer); // inverse le buffer OpenCV désigné //opencv.invert(opencv.BUFFER); // inverse le buffer OpenCV désigné //opencv.invert("BUFFER"); // inverse le buffer OpenCV désigné println("Durée traitement image par OpenCV=" + (millis()-millis0)+" ms."); //--- affiche image finale --- image(opencv.getBuffer(),widthCapture,0); // affiche le buffer principal OpenCV dans la fenêtre Processing } // fin if available } // fin draw Added lines 116-122:
!! Exemple webcam (:source lang=processing:) (:sourcend:) Changed line 69 from:
import monclubelec. to:
import monclubelec.javacvPro.*; // importe la librairie javacvPro Added lines 1-127:
(:notitle:) (:include HautPageReference:)\\ [[Main.LibrairieJavacvPro|Librairie JavacvPro]] ! Classe OpenCV : invert() ---- %center%Path:/mes_images/javacvpro/javacvpro_exemple_invert.png !! Description * Cette fonction inverse l'image du buffer principal ou un objet IplImage reçu en paramètre : on obtient le "négatif" de l'image. Attention, l'image utilisée doit être en 3 canaux. * Voir également : !! Déclaration source java (:source lang=java :) public void invert() public void invert(String stringIn) public void invert(opencv_core.IplImage iplImgIn) (:sourcend:) !! Syntaxe (:source lang=processing :) opencv.invert(); opencv.invert(iplImg); opencv.invert(str); (:sourcend:) !! Paramètres * opencv : un objet OpenCV déclaré avec le constructeur [[OpencvOpencv|OpenCV]]. * iplImg : un objet IplImage * str (String) : chaine de caractère identifiant le buffer. Voir la page "[[OpencvBuffers|Les buffers image]]" pour plus de détails. !! Valeur renvoyée Aucune. L'image source est modifiée. !! Utilisation type * Par exemple, après l'application d'un filtre de contour, il est intéressant d'inverser l'image pour obtenir une image en dessin "au crayon". !! Exemple (:source lang=processing :) opencv.invert(); opencv.invert(opencv.Memory); opencv.invert("MEMORY"); opencv.invert(opencv.MEMORY); (:sourcend:) %center%%red% L'exemple complet suivant est à copier dans Processing et est exécutable immédiatement si vous êtes connectés à internet : (:source lang=processing :) // Programme d'exemple de la librairie javacvPro // par X. HINAULT - octobre 2011 // Tous droits réservés - Licence GPLv3 // Exemple fonction invert() import monclubelec.javacvProc.*; // importe la librairie javacvPro PImage img; String url="http://www.mon-club-elec.fr/mes_images/online/lena.jpg"; // String contenant l'adresse internet de l'image à utiliser OpenCV opencv; // déclare un objet OpenCV principal void setup(){ // fonction d'initialisation exécutée 1 fois au démarrage //-- charge image utilisée --- img=loadImage(url,"jpg"); // crée un PImage contenant le fichier à partir adresse web //--- initialise OpenCV --- opencv = new OpenCV(this); // initialise objet OpenCV à partir du parent This opencv.allocate(img.width, img.height); // initialise les buffers OpenCv à la taille de l'image opencv.copy(img); // charge le PImage dans le buffer OpenCV //--- initialise fenêtre Processing size (opencv.width()*2, opencv.height()); // crée une fenêtre Processing de la 2xtaille du buffer principal OpenCV //size (img.width, img.height); // aalternative en se basant sur l'image d'origine //--- affiche image de départ --- image(opencv.getBuffer(),0,0); // affiche le buffer principal OpenCV dans la fenêtre Processing //--- opérations sur image --- //-- toutes ces formes sont possibles : opencv.invert(); // inverse le buffer principal OpenCV //opencv.invert(opencv.Buffer); // inverse le buffer OpenCV désigné //opencv.invert(opencv.BUFFER); // inverse le buffer OpenCV désigné //opencv.invert("BUFFER"); // inverse le buffer OpenCV désigné //--- affiche image finale --- image(opencv.getBuffer(),opencv.width(),0); // affiche le buffer principal OpenCV dans la fenêtre Processing } void draw() { // fonction exécutée en boucle } (:sourcend:) !! Commentaires utilisateurs >>bgcolor=#dfd border='3px dotted green'<< Aucun >><< (:include BasPageReference:) Cette page est une création originale de Xavier HINAULT - Tous droits réservés - 2011 |