1 2009 B4 GUI TA http://www.cyber.t.u-tokyo.ac.jp/ tani/class/mech enshu/ 2008 6 11 1 1 1 4 C GUI(Graphical User Interface) X Window System GUI 5 GUI 2 Gtk+ GUI 2.1 GUI GUI GUI (event driven) GUI GUI GUI GUI GUI GUI
2 2 Gtk+ GUI (widget ) GUI Gtk+ GUI Gtk+ GUI 2.2 Gtk GUI sample1.c Web (http://www.cyber.t.u-tokyo.ac.jp/ tani/class/mech enshu/) enshu2009gui1.tar.gz % tar xvzf enshu2009gui1.tar.gz % cd 2009gui1 % make 1 1 sample1.c Gtk+ Gtk+ gtk.h sample1.c 12 #include<gtk/gtk.h> gtk.h Gtk+ *1 54 Gtk *1 gtk.h gtk.h
2.3 3 ( ) Gtk int main (int argc, char* argv[]) { { } gtk_set_local(); /* gtk_init(&argc, &argv); /* gtk_get_rc_parse(" "); /* Gtk... sample1.c gtk_init() argv Gtk gtk_init() Gtk+ GUI ( ) GUI ( ) ( ) GUI Gtk+ GUI GtkWidget gtk_widget_show() gtk_widget_show() gtk_widget_show() GUI Gtk 125 gtk_main() gtk_main() main() 2.3 Gtk+ 3
4 2 Gtk+ GUI window Gtk+ sample1.c 67 69 /* GtkWidget *window; /* window window = gtk_window_new(gtk_window_toplevel); /* gtk_window_set_title(gtk_window(window), " "); /* gtk_container_border_width(gtk_container(window), 10); label label label /* GtkWidget *label; /* label label = gtk_label_new(" "); sample3.c 78 80 label label gtk_label_set(gtk_label(label), " "); button
2.4 5 /* GtkWidget *button; /* button button = gtk_button_new_with_label(" "); 2.4 GUI OS Gtk+ ( ) 2 gint gtk_signal_connect( GtkObject object name func gchar GtkSignalFunc *object, *name, func, gpointer func_data ); : GTK ( ) : : func_data : void callback_func( GtkWidget *widget, gpointer data ); widget : data :
6 2 Gtk+ GUI gint gtk_signal_connect_object( GtkObject object name func gchar GtkSignalFunc *object, *name, func, GtkObject *slot_object ); : GTK ( ) : : slot_object : func GTK void callback_func( GtkWidget *widget ); widget : gtk_signal_connect() gtk_signal_connect_object() 1 1 Gtk+ pressed released clicked enter leave sample1.c counter 1 1. sample1.c. 2. sample1.c button2 2 2.5 GUI
2.5 7 2 1.2 GUI Gtk+ GUI Gtk+ (= ) 3 4 gtk_hbox_new() gtk_box_pack_start() gtk_box_pack_end()
8 3 gtk_vbox_new() gtk_box_pack_start() gtk_box_pack_end() 2 1. sample2.c C( ) ( 5) 2. (+,-,*,/) 3. ( ) 5 2.1 3 3.1 sample3.c sample3
3.2 9 3 1. sample3.c 2. sample3.c image_proportion() 6 3. sample3.c image_skew() 7 4. sample3.c image_radial() 8 ( ) image_processing() image_processing() 6 3.2 7 3.3 8 3.4 3.2 PNG, JPEG, TIFF, BMP, GIF PNM(Portable anymap) PGM(Portable Grayscale Map) PPM(Portable Pixel Map) P6 256 256 x y 255...( RGB )... PGM
10 3 P5 256 256 255...( )... 1 P5 P6 P5 P6 2 2 256 256 pixel 255 pixel 0 255 0 255 8 bit(=1 byte) 1pixel 1byte 1pixel RGB 8bit 3byte 3.3 GTK GDK (GIMP Drawing Kit) GDK (X Window system XLib ) (Wrapper) GDK http://www.gnome.gr.jp/docs/gtk+-1.2.x-refs/gdk/index.html DrawingArea GtkWidget* gtk_drawing_area_new ( void ); /* void gtk_drawing_area_size ( GtkDrawingArea *darea, gint width, gint height); realize size allocate expose event RGB ( ) GDK GdkRgb GdkRgb gdk_rgb_init()
3.3 11 core (GtkPreview ) GdkRgb GTK+ (class_init) gdk_rgb_init() GdkRgb void gdk_rgb_init (void); void gdk_draw_rgb_image ( GdkDrawable *drawable, GdkGC *gc, gint x, gint y, gint width, gint height, GdkRgbDither dith, guchar *rgb_buf, gint rowstride ); void gdk_draw_gray_image ( GdkDrawable *drawable, GdkGC *gc, gint x, gint y, gint width, gint height, GdkRgbDither dith, guchar *buf, gint rowstride ); drawable gc x y width height dith rgb_buf : GdkDrawable ( GdkWindow) : ( GDK ) : drawable X : drawable Y : : : GdkRgbDither : Packed24 (Packed : Depth ) rowstride : rgb_buf
12 3 gdk_draw_rgb_image () Drawable RGB gdk_draw_gray_image () Drawable rowstride 0 <= i < width 0 <= j < height pixel(x+i, y+j) (R) = rgb_buf[j*rowstride + i*3] (G) = rgb_buf[j*rowstride + i*3 + 1] (B) = rgb_buf[j*rowstride + i*3 + 2] 3.4 GUI / entry scale entry entry entry /* GtkWidget *entry; /* entry entry = gtk_entry_new_with_max_length (50); entry gchar *entry_text; entry_text = gtk_entry_get_text (GTK_ENTRY(entry)); scale entry GUI scale scale scale adjustment adjustment gtk_adjustment_new()
3.4 13 GtkObject* gtk_adjustment_new ( gfloat value, gfloat lower, gfloat upper, gfloat step_increment, gfloat page_increment, gfloat page_size ); value : lower : upper : step_increment : page_increment : page_size : upper upper - page_size scale adjustment /* GtkObject *adjustment; GtkWidget *scale; /* adjustment adjustment = gtk_adjustment_new(0, 0, 255, 1, 1, 0); /* on_slider_moved() gtk_signal_connect(gtk_object(adjustment), "value_changed", GTK_SIGNAL_FUNC(on_slider_moved), adjustment); /* scale adjustment scale = gtk_vscale_new(gtk_adjustment(adjustment)); /* gtk_scale_set_digits(gtk_scale(scale), 0); scale
14 3 void on_slider_moved(gtkwidget * widget, GtkAdjustment *adj) { int scale_value; } scale_value = adj->value; 4 1. sample4.c sample4.c load_pgm() 9 lena.pgm 2. entry 9 9 4 3.5 T T 1 0 (binarization).
3.6 15 x x f y = f(x) [x m in, x m ax] 10 x max x y = y max x min x < x max y = y max y min (x x min ) + y min x max x min x < x min y = y min ymax ymin xmin xmax 10 3.6 3 3 ( ) 3 3 5 5 ( ) 3 3 f(i, j) g(i, j) (i, j) g(i, j) = 1 9 1 1 m= 1 n= 1 f(i + m, j + n) 1 9 1 9 1 9 1 9 1 9 1 9 1 9 1 9 1 9
16 3 Sobel 1 0 1 1 0 1 1 0 1 1 1 0 1 2 0 2 1 0 1 Sobel 1 1 ( 11) 3 3 f(i, j) 2 2 f(i, j) {f(i + 1, j) f(i, j)} {f(i, j) f(i 1, j)} i2 2 f(i, j) {f(i, j + 1) f(i, j)} {f(i, j) f(i, j 1)} j2 2 2 f(i, j) + f(i, j) i2 j2 3 3
17 11 (A),(B) ( ) (B) ( ) 2 5 1. sample5.c scale 12 2. sample5.c image_filter() 3 3 13 ( ) 3. Sobel ( ) 4. ( ) 12 5.1 13 5.2 4 (/dev/video) mmap videocapture.c GUI
18 4 6 1. gtk capture videocapture gui.c 14 2. 14 6 4.1 OpenCV OpenCV OpenCV 2 binarization()
4.1 OpenCV 19 // 2 void binarization(void){ // BGR cvcvtcolor( sourceimage, grayimage, CV_BGR2GRAY ); // 2 cvthreshold( grayimage, binaryimage, levels, THRESHOLD_MAX_VALUE, CV_THRESH_BINARY ); } // cvshowimage( windownamebinarization, binaryimage); // void on_change( int pos ){ binarization(); } GTK (GTK scale ) char windownamebinarization[] = "Binarization" // int levels = 128; // (2 ) char trackbarnamethreshold[] = "Threshold"; // // cvnamedwindow( windownamebinarization ); // cvcreatetrackbar( trackbarnamethreshold, windownamebinarization, &levels, TRACKBAR_MAX_VALUE, on_change ); // cvdestroywindow( windownamebinarization );
20 4 7 1. binarization opencv OpenCV ( )