GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Oct 30, 2014 5:26 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: How to show an iplImage (opencv) in a GTK window?
PostPosted: Mon Oct 24, 2011 2:08 pm 
Offline
Familiar Face

Joined: Mon Oct 17, 2011 10:18 am
Posts: 26
Hello All,

I am a new GTK user, and I would be grateful if someone will find time to help me.
Lets say that I receive an iplImage (opencv parameter), and my goal is to show this image in a GTK/GDK window/widget.
I have written this code, but I am not able to see the image inside a widget (nothing appears on the screen):

GtkWidget* convertOpenCv2Gtk (IplImage* srcImage)
{
GtkWidget* gtkImg = NULL;
GdkPixbuf* gtkPixbuf = NULL;
IplImage* dstImage = NULL;

/** Creating the destionation image */
dstImage = cvCreateImage( cvSize(srcImage->width,srcImage->height), IPL_DEPTH_8U, 3);

/** Converting the format of the picture from BGR to RGB */
cvCvtColor ( srcImage, dstImage, CV_BGR2RGB );

/** Creates a new GdkPixbuf out of in-memory image data */
gtkPixbuf = gdk_pixbuf_new_from_data ( (guchar*)dstImage->imageData,
GDK_COLORSPACE_RGB,
FALSE,
dstImage->depth,
dstImage->width,
dstImage->height,
(dstImage->widthStep),
NULL,
NULL
);

/** Create new GtkImage displaying pixbuf */
gtkImg = gtk_image_new_from_pixbuf ( gtkPixbuf );
return gtkImg;
}


In the main function I am just trying to show the received widget:

gtkWindow = convertOpenCv2Gtk ( iplImage );
gtk_widget_queue_draw ( gtkWindow );


Why it doesn´t works?
What wrong have I done?
What parts are missing?

Thanks in advance to you all :),
Felix.


Top
 Profile  
 
 Post subject: Re: How to show an iplImage (opencv) in a GTK window?
PostPosted: Tue Oct 25, 2011 10:08 am 
Offline
Familiar Face

Joined: Mon Oct 17, 2011 10:18 am
Posts: 26
Felix wrote:
Hello All,

I am a new GTK user, and I would be grateful if someone will find time to help me.
Lets say that I receive an iplImage (opencv parameter), and my goal is to show this image in a GTK/GDK window/widget.
I have written this code, but I am not able to see the image inside a widget (nothing appears on the screen):

GtkWidget* convertOpenCv2Gtk (IplImage* srcImage)
{
GtkWidget* gtkImg = NULL;
GdkPixbuf* gtkPixbuf = NULL;
IplImage* dstImage = NULL;

/** Creating the destionation image */
dstImage = cvCreateImage( cvSize(srcImage->width,srcImage->height), IPL_DEPTH_8U, 3);

/** Converting the format of the picture from BGR to RGB */
cvCvtColor ( srcImage, dstImage, CV_BGR2RGB );

/** Creates a new GdkPixbuf out of in-memory image data */
gtkPixbuf = gdk_pixbuf_new_from_data ( (guchar*)dstImage->imageData,
GDK_COLORSPACE_RGB,
FALSE,
dstImage->depth,
dstImage->width,
dstImage->height,
(dstImage->widthStep),
NULL,
NULL
);

/** Create new GtkImage displaying pixbuf */
gtkImg = gtk_image_new_from_pixbuf ( gtkPixbuf );
return gtkImg;
}


In the main function I am just trying to show the received widget:

gtkWindow = convertOpenCv2Gtk ( iplImage );
gtk_widget_queue_draw ( gtkWindow );


Why it doesn´t works?
What wrong have I done?
What parts are missing?

Thanks in advance to you all :),
Felix.


Hello All,

Please do not answer all together, I can´t read so many answers ;).
Please remember, that you also have started once...

Thanks again,
Felix.


Top
 Profile  
 
 Post subject: Re: How to show an iplImage (opencv) in a GTK window?
PostPosted: Wed Oct 26, 2011 10:28 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 766
Location: UK
Hi,

I am joining the stampede of answers here ;-)

I have not used opencv before so can not answer specifics on opencv. You have shown a function to convert the opencv image to a GtkImage widget. I am going to have to assume that that code is correct!!!!! If not you could try placing a temporary known GtkWidget there to see it that works. What you do not describe is where and how you place the widget so that it could be seen. The use of gtk_widget_queue_draw() is also odd as normally it is not needed.

E.

_________________
E.


Top
 Profile  
 
 Post subject: Re: How to show an iplImage (opencv) in a GTK window?
PostPosted: Thu Oct 27, 2011 3:24 pm 
Offline
Familiar Face

Joined: Mon Oct 17, 2011 10:18 am
Posts: 26
errol wrote:
Hi,

I am joining the stampede of answers here ;-)

I have not used opencv before so can not answer specifics on opencv. You have shown a function to convert the opencv image to a GtkImage widget. I am going to have to assume that that code is correct!!!!! If not you could try placing a temporary known GtkWidget there to see it that works. What you do not describe is where and how you place the widget so that it could be seen. The use of gtk_widget_queue_draw() is also odd as normally it is not needed.

E.


Hello Errol,

Thank you for your will to help.
Anyway, I have solved this problem by myself.

Best,
Felix.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group