Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Simple example on how to load an image using OpenCV and display it in Gtk
- * Compile with: valac --pkg opencv --pkg gdk-pixbuf-2.0 --pkg gtk+-2.0 opencv.vala
- * Author: A.Lepe (dev@alepe.com)
- */
- using OpenCV;
- using Gdk;
- using Gtk;
- class Utils {
- public static void PixbufDestroyNotify (uint8* pixels) {
- GLib.stdout.printf("delete buffer\n");
- delete pixels;
- }
- public static Gtk.Widget convertOpenCvToGtk(IPL.Image gtkMask) {
- Gtk.Widget gtkImg;
- Gdk.Pixbuf pix = new Gdk.Pixbuf.from_data (
- gtkMask.image_data,//Raw image data
- Gdk.Colorspace.RGB, //Colorspace
- false, //Has alpha channel or not
- gtkMask.depth, //Bits per pixel
- gtkMask.width, //Width of image
- gtkMask.height, //Height of image
- gtkMask.width_step, //Row stride
- Utils.PixbufDestroyNotify //destroy function (optional)
- );
- gtkImg = new Gtk.Image.from_pixbuf (pix);
- return gtkImg;
- }
- }
- void main (string[] args) {
- IPL.Image img = new IPL.Image.load("/var/www/test/image.jpg");
- stdout.printf("Width: %d\n", img.width);
- stdout.printf("Height: %d\n", img.height);
- Gtk.init (ref args);
- var win = new Gtk.Window ();
- win.set_size_request (img.width,img.height);
- win.border_width = 5;
- win.title = "Widget test";
- win.destroy.connect (Gtk.main_quit);
- var frame = new Frame ("Example Vala Widget");
- win.add (frame);
- frame.add (Utils.convertOpenCvToGtk(img));
- win.show_all ();
- Gtk.main ();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement