IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

OpenCV Discussion :

Conversion d'Iplimage (OpenCV) vers GTKimage (GTK+)


Sujet :

OpenCV

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Juillet 2007
    Messages
    29
    Détails du profil
    Informations forums :
    Inscription : Juillet 2007
    Messages : 29
    Par défaut Conversion d'Iplimage (OpenCV) vers GTKimage (GTK+)
    Conversion Iplimage (OpenCV) vers GTKimage (GTK+)
    Bonjour a tout le monde,
    Je désire dans le cadre d'un stage faire de l'acquisition d'images a partir d'une camera avec OpenCV puis afficher cette image dans GTK. L’idée première est de faire tourner la camera et afficher le flux avec une fenêtre OpenCV et d’un clic de souris acquérir l’image.
    Le problème que j'ai se fait au moment d'afficher une image dans la fenêtre GTK et bien la conversion Ipl image vers GTKimage bugge et l’affichage n’est pas très beau à voir.
    Je m'excuse par avance du code quick and dirty avec les variables globales mais pour me rattraper j’ai commenté le code et remanié pour qu’il soit lisible a lire enfin je l’espère.
    Voila en espérant que quelqu’un a déjà eu un problème similaire en utilisant conjointement OpenCV et GTK+ et pourrait m’aider.
    Cordialement et merci par avance,
    Damien

    Le code:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
     
    // projetessai.cpp : Defines the entry point for the console application.
     
    #include "stdafx.h"
    #include <stdio.h>
    //Libraries OpenCV
    #include <cv.h>
    #include <cvaux.h>
    #include <highgui.h>
    #include <cvcam.h>
    #include <Windows.h>
    // Libraries GTK+
    #include <gtk/gtk.h>
    #include <stdlib.h>
     
    // Global variables used here for simplicity
     
      //Windows created
      GtkWidget *pWin;
      GtkWidget *pWin2;
     
    // Callbacks widgets
      GtkWidget *pQuitBtn;
      GtkWidget *pGrabBtn;
     
    // Table created for the main window
      GtkWidget *pTable;
     
      GtkWidget *pImage;
      GdkPixbuf *pGdkpix; 
     
    // OpenCV 
      IplImage  *pIplimg;
      IplImage  *pIplimgnew;
     
      void transfoIplImageToGtkImage(void)
      {
    // Creation and placement of the grabbed frame
       pWin2 = gtk_window_new(GTK_WINDOW_POPUP);
       gtk_window_set_title(GTK_WINDOW(pWin2), "picture grabbed");
       gtk_window_set_default_size(GTK_WINDOW(pWin2), 600, 400);
       gtk_window_move(GTK_WINDOW(pWin2), 400, 400);
     
    // Information about the IPL Image
        int iHeightipl=      pIplimg->height; 	printf("iHeightipl  %d  ",iHeightipl);printf("\n\n");
        int iWidthipl=       pIplimg->width;  printf("iWidthipl  %d  ",iWidthipl);printf("\n\n");
        int iWidthStepipl=   pIplimg->widthStep; printf("iWidthStepipl  %d  ",iWidthStepipl);printf("\n\n");
     
    	//je crois que le probleme vient d'ici, c'est bien la conversion qui cloche car si je sauve l'image et je la remet 
    	// ce sont les fcts de sauvegarde bitmap en commentaire le prog fonctionne
     
       	pIplimgnew=pIplimg; //constructeur par recopie pour pas se fouler
     
    	 //Create a pixbuf from the imageData of the OpenCv image in BGR order to an RGB one 
    	cvCvtColor( pIplimg,pIplimgnew,  CV_BGR2RGB );
    	pGdkpix=gdk_pixbuf_new_from_data((guchar*)pIplimg,GDK_COLORSPACE_RGB,FALSE, //We don't have alpha channel
    	                               8,iWidthipl,iHeightipl,iWidthStepipl,NULL,NULL);
     
        pImage=gtk_image_new_from_pixbuf(pGdkpix);
    	pImage=gtk_image_new_from_file("c:\\toto.bmp");
        gtk_container_add(GTK_CONTAINER(pWin2),pImage);
     
        gtk_widget_show_all(pWin2);
     
     
      }
     
     
    //Callbacks functions
     
    void cb_grab (GtkWidget *p_widget, gpointer user_data)
    {
      transfoIplImageToGtkImage();
     
    }
     
    void cb_quit (GtkWidget *p_widget, gpointer user_data)
    {
     gtk_main_quit();
    }
     
     
    int main (int argc, char *argv[])
    {
     
      gtk_init(&argc, &argv);
     
     //Creation of the GUI enviromment
      pWin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
      gtk_window_set_default_size(GTK_WINDOW(pWin), 200, 200);
      gtk_window_set_title(GTK_WINDOW(pWin), "GTK-Win");
      gtk_window_set_default_size(GTK_WINDOW(pWin), 200, 200);
      g_signal_connect(G_OBJECT(pWin), "destroy", G_CALLBACK(cb_quit), NULL);
     
      // Creation of the table here just for two buttons with two collumns
      pTable = gtk_table_new(2, 1, FALSE);
      gtk_container_add (GTK_CONTAINER(pWin),pTable);
     
      //Callbacks button and attached signal
      pQuitBtn = gtk_button_new_with_label("Quit");
      g_signal_connect(G_OBJECT(pQuitBtn),"clicked",G_CALLBACK(cb_quit), NULL);
      gtk_widget_set_size_request(pQuitBtn, 50, 40);
      gtk_table_attach(GTK_TABLE(pTable), pQuitBtn, 0, 1, 0, 1, GTK_SHRINK, GTK_SHRINK, 50, 50);
     
      pGrabBtn = gtk_button_new_with_label("Grab");
      g_signal_connect(G_OBJECT(pGrabBtn),"clicked",G_CALLBACK(cb_grab), NULL);
      gtk_widget_set_size_request(pGrabBtn, 50, 40);
      gtk_table_attach(GTK_TABLE(pTable), pGrabBtn, 1, 2, 0, 1, GTK_FILL, GTK_FILL,50, 50);
     
      //OpenCV part of camera acquisition here just the first frame
       CvCapture* capture=cvCaptureFromCAM(0);
       cvNamedWindow("Capture Webcam", 0);
     
       pIplimg=cvQueryFrame(capture); 
       //Displaying and recording the first image
       cvShowImage("Capture Webcam",pIplimg);	
       cvSaveImage( "c:\\toto.bmp", pIplimg);
     
      gtk_widget_show_all(pWin);
      gtk_main ();
     
     
      return 0;
    }

  2. #2
    Membre expérimenté Avatar de Vinsss84
    Profil pro
    Inscrit en
    Février 2008
    Messages
    175
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Février 2008
    Messages : 175
    Par défaut
    et en utilisant :
    gdk_image_put_pixel ()

    void gdk_image_put_pixel (GdkImage *image,
    gint x,
    gint y,
    guint32 pixel);

    Sets a pixel in a GdkImage to a given pixel value.
    image : a GdkImage.
    x : the x coordinate of the pixel to set.
    y : the y coordinate of the pixel to set.
    pixel : the pixel value to set.
    dans une boucle

  3. #3
    Membre averti
    Inscrit en
    Juillet 2007
    Messages
    29
    Détails du profil
    Informations forums :
    Inscription : Juillet 2007
    Messages : 29
    Par défaut
    ok merci je vais voir a nouveau, je me rappelle que je n'avais pas retenu cette idée car je ne comprenais pas vraiment la structure d'une GDK Image.
    Je tiens au courant.
    Damien

  4. #4
    Membre averti
    Inscrit en
    Juillet 2007
    Messages
    29
    Détails du profil
    Informations forums :
    Inscription : Juillet 2007
    Messages : 29
    Par défaut
    Ah voila je comprends pourquoi je n'ai pas pris cette solution car pour creer une image vide qui correspond a une iplimage avec le widget image c'est le parcours du combattant:

    Le prototype de la fct c'est :

    gdk_image_new(GdkImageType type, GdkVisual *visual, gint width, gint height);


    Si quelqu'un est au courant comment on setup visual merci de me repondre
    le reste du code donne cela:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
     imagefinale  = gdk_image_new (GDK_IMAGE_NORMAL, visual, iWidthipl, iHeightipl);
     
    	  for(int y = 0; y < (iHeightipl); y++) 
    		for(int x = 0; x < (iWidthipl); x++) 
    		{ 
    			gdk_image_put_pixel(imagefinale,x,y,(iImageDataipl + iWidthStepipl*y)[x*3]);
     
    		}
    Merci
    D

  5. #5
    Membre expérimenté Avatar de Vinsss84
    Profil pro
    Inscrit en
    Février 2008
    Messages
    175
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Février 2008
    Messages : 175
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    typedef struct {
      GObject parent_instance;
     
      GdkVisualType type;
      gint depth;
      GdkByteOrder byte_order;
      gint colormap_size;
      gint bits_per_rgb;
     
      guint32 red_mask;
      gint red_shift;
      gint red_prec;
     
      guint32 green_mask;
      gint green_shift;
      gint green_prec;
     
      guint32 blue_mask;
      gint blue_shift;
      gint blue_prec;
    } GdkVisual;

  6. #6
    Membre averti
    Inscrit en
    Juillet 2007
    Messages
    29
    Détails du profil
    Informations forums :
    Inscription : Juillet 2007
    Messages : 29
    Par défaut
    merci vinss84, j'avais quand même un peu regarde avant de poster, je vois tjs pas comment l'utiliser...
    si t'as un bout de code qui traine et qui fait cette maudite conversion ca me ferait plaisir d'y jeter un oeil.
    Ca fait 2 jours que je tourne en rond et essaye
    A +
    D

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. conversion de Turbo Pascal vers Delphi 5
    Par samir1674 dans le forum Langage
    Réponses: 5
    Dernier message: 28/11/2005, 17h03
  2. [VB.net]problème de conversion de code c# vers VB.net
    Par cladsam dans le forum Windows Forms
    Réponses: 2
    Dernier message: 18/10/2005, 14h07
  3. Pb de conversion de données 16 vers 32
    Par Ducmonster dans le forum Langage
    Réponses: 2
    Dernier message: 09/10/2005, 11h53
  4. Conversion Access 2.0 vers 2003
    Par davidf dans le forum Access
    Réponses: 13
    Dernier message: 16/06/2005, 17h40
  5. conversion : VARIANT FAR* URL vers CString
    Par kam dans le forum MFC
    Réponses: 2
    Dernier message: 29/03/2004, 13h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo