Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to convert cv::Mat to Gdk::Pixbuf?

Hello, everyone

Recently, I am trying to write a GUI for my image processing application(commandline), using Gtkmm. After processing a image using opencv, I want to display the result in a Gtkmm' s Image widget. The following is the code I used to setup Gtk::Image:

cv::Mat temp;
const int width = img_window.get_allocation().get_width();
const int height = img_window.get_allocation().get_height();
cv::resize(fusion_img, temp, cv::Size(width, height));
cv::cvtColor(temp, temp, cv::COLOR_BGR2RGB);

img.set(Gdk::Pixbuf::create_from_data(temp.data, Gdk::COLORSPACE_RGB, false, 8, width, height, temp.step[0]));

but it display a damged image. I need some advice to make it right. Thank you.

How to convert cv::Mat to Gdk::Pixbuf?

Hello, everyone

Recently, I am trying to write a GUI for my image processing application(commandline), using Gtkmm. After processing a image using opencv, I want to display the result in a Gtkmm' s Image widget. The following is the code I used to setup Gtk::Image:

cv::Mat temp;
const int width = img_window.get_allocation().get_width();
const int height = img_window.get_allocation().get_height();
cv::resize(fusion_img, temp, cv::Size(width, height));
cv::cvtColor(temp, temp, cv::COLOR_BGR2RGB);

img.set(Gdk::Pixbuf::create_from_data(temp.data, Gdk::COLORSPACE_RGB, false, 8, width, height, temp.step[0]));

but it display a damged damaged image. I need some advice to make it right. Thank you. you.