def __refresh_ir_cam_frame(self, item): """ Refresh the camera frame for the IR preview """ cam_image = self.__builder.get_object("cam_image") ir_image = self.__builder.get_object("ir_image") frame = facade.get_frame_bgr_to_rgb() ir_frame = facade.find_robot_in_frame(frame) cam_image.set_from_pixbuf( self.__scale_with_aspect_ratio(gtk.gdk.pixbuf_new_from_array(frame, gtk.gdk.COLORSPACE_RGB, 8), 400, 400) ) ir_image.set_from_pixbuf( self.__scale_with_aspect_ratio(gtk.gdk.pixbuf_new_from_array(ir_frame, gtk.gdk.COLORSPACE_RGB, 8), 400, 400) )
def __select_image_file(self, item): """ Open the image selector for testing various images with the image recognition """ cam_image = self.__builder.get_object("cam_image") ir_image = self.__builder.get_object("ir_image") chooser = gtk.FileChooserDialog( title="Select an image to preview image recognition", action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK), ) filter = gtk.FileFilter() filter.set_name("Images") filter.add_mime_type("image/png") filter.add_mime_type("image/jpeg") filter.add_mime_type("image/gif") filter.add_pattern("*.png") filter.add_pattern("*.jpg") filter.add_pattern("*.gif") filter.add_pattern("*.tif") filter.add_pattern("*.xpm") chooser.add_filter(filter) response = chooser.run() if response == gtk.RESPONSE_OK: # Refresh image if one was successfully chosen frame = facade.get_image_from_file(chooser.get_filename()) preview_frame = gtk.gdk.pixbuf_new_from_file_at_size(chooser.get_filename(), 400, 400) cam_image.set_from_pixbuf(preview_frame) ir_frame = facade.find_robot_in_frame(frame) # Scale IR frame to preview dimensions ir_image.set_from_pixbuf( self.__scale_with_aspect_ratio( gtk.gdk.pixbuf_new_from_array(ir_frame, gtk.gdk.COLORSPACE_RGB, 8), 400, 400 ) ) # print chooser.get_filename(), 'selected' elif response == gtk.RESPONSE_CANCEL: pass # print 'Closed, no files selected' chooser.destroy()