def update_position(self): # print("RS Helper updating position") self.style['position']='absolute' self.style['left'] = \ gui.to_pix( gui.from_pix(self.refWidget.style['left']) + from_px( # self.refWidget.style['width'] self, 'width', self.parent ) - from_px( # self.style['width'] self, 'width', self.parent )/2) self.style['top'] = \ gui.to_pix( gui.from_pix(self.refWidget.style['top']) + from_px( # self.refWidget.style['height'] self, 'height', self.parent ) - from_px( # self.style['height'] self, 'height', self.parent )/2)
def onchange_miniature_selection(self, emitter, selected, miniature): print(selected) if selected: self.miniature_selection_list.append(miniature) else: self.miniature_selection_list.remove(miniature) if len(self.miniature_selection_list) > 1: print("stitching %s images"%len(self.miniature_selection_list)) result = self.miniature_selection_list[0].image.img.copy() roi_logo_x = gui.from_pix(self.roi_logo_widget.style['left']) roi_logo_w = gui.from_pix(self.roi_logo_widget.style['width']) t = time.time() w = float(self.spin_horizontal_perspective.get_value()) h = float(self.spin_vertical_perspective.get_value()) #result = self.calibrate_image(result) result = image_utils.perspective_correction(result, w, h) for m in self.miniature_selection_list[1:]: img = m.image.img#self.calibrate_image(m.image.img) img = image_utils.perspective_correction(img, w, h) result = image_utils.stitch_fast(result, img, roi_logo_x, roi_logo_x+roi_logo_w, 30.0) #image_utils.stitch(result, m.image.img, 20.0) print(time.time() - t) self.camera_image.refresh(result)
def on_dropped(self, left, top): try: self.refWidget.style['width'] = gui.to_pix(gui.from_pix(self.refWidget.style['width']) + gui.from_pix(left) - gui.from_pix(self.style['left'])) self.refWidget.style['height'] = gui.to_pix(gui.from_pix(self.refWidget.style['height']) + gui.from_pix(top) - gui.from_pix(self.style['top'])) except: pass self.update_position()
def update_position(self): self.style['position'] = 'absolute' if self.refWidget: if 'left' in self.refWidget.style and 'top' in self.refWidget.style: self.style['left'] = gui.to_pix( gui.from_pix(self.refWidget.style['left'])) self.style['top'] = gui.to_pix( gui.from_pix(self.refWidget.style['top']))
def update_position(self): self.style['position'] = 'absolute' self.style['left'] = gui.to_pix( gui.from_pix(self.refWidget.style['left']) - gui.from_pix(self.style['width']) / 2) self.style['top'] = gui.to_pix( gui.from_pix(self.refWidget.style['top']) - gui.from_pix(self.style['height']) / 2)
def from_px(obj, attr_name, parent, default=200): try: return G.from_pix(obj.style[attr_name]) except ValueError: try: return G.from_pix(parent.style[attr_name]) except ValueError: return default
def update_position(self): if self.refWidget == None: return if self.refWidget.style['position'] != 'absolute': self.style['display'] = 'none' return self.style['position'] = 'absolute' self.style['display'] = 'block' self.style['left'] = gui.to_pix(gui.from_pix(self.refWidget.style['width'])+gui.from_pix(self.refWidget.style['left'])-gui.from_pix(self.style['width'])/2) self.style['top'] = gui.to_pix(gui.from_pix(self.refWidget.style['height'])+gui.from_pix(self.refWidget.style['top'])-gui.from_pix(self.style['height'])/2)
def on_drag(self, emitter, x, y): if self.active: if self.origin_x == -1: self.origin_x = float(x) self.origin_y = float(y) self.refWidget_origin_x = gui.from_pix(self.refWidget.style['left']) self.refWidget_origin_y = gui.from_pix(self.refWidget.style['top']) else: self.refWidget.style['left'] = gui.to_pix( self.round_grid( self.refWidget_origin_x + float(x) - self.origin_x ) ) self.refWidget.style['top'] = gui.to_pix( self.round_grid( self.refWidget_origin_y + float(y) - self.origin_y ) ) self.update_position()
def on_drag(self, emitter, x, y): if self.active: if self.origin_x == -1: self.origin_x = float(x) self.origin_y = float(y) self.refWidget_origin_x = gui.from_pix(self.refWidget.style['left']) self.refWidget_origin_y = gui.from_pix(self.refWidget.style['top']) else: self.refWidget.style['left'] = gui.to_pix(self.refWidget_origin_x + float(x) - self.origin_x ) self.refWidget.style['top'] = gui.to_pix(self.refWidget_origin_y + float(y) - self.origin_y) self.update_position()
def on_drag(self, emitter, x, y): if self.active: if self.origin_x == -1: self.origin_x = float(x) self.origin_y = float(y) self.refWidget_origin_w = gui.from_pix(self.refWidget.style['width']) self.refWidget_origin_h = gui.from_pix(self.refWidget.style['height']) else: self.refWidget.style['width'] = gui.to_pix(self.refWidget_origin_w + float(x) - self.origin_x ) self.refWidget.style['height'] = gui.to_pix(self.refWidget_origin_h + float(y) - self.origin_y) self.update_position()
def on_drag(self, emitter, x, y): if self.active: if self.origin_x == -1: self.origin_x = float(x) self.origin_y = float(y) self.refWidget_origin_w = gui.from_pix(self.refWidget.style['width']) self.refWidget_origin_h = gui.from_pix(self.refWidget.style['height']) else: self.refWidget.style['width'] = gui.to_pix( self.round_grid( self.refWidget_origin_w + float(x) - self.origin_x ) ) self.refWidget.style['height'] = gui.to_pix( self.round_grid( self.refWidget_origin_h + float(y) - self.origin_y ) ) self.update_position()
def on_drag(self, emitter, x, y): if self.active: if self.origin_x == -1: self.origin_x = int(x) self.origin_y = int(y) self.refWidget_origin_w = gui.from_pix(self.refWidget.style['width']) self.refWidget_origin_h = gui.from_pix(self.refWidget.style['height']) else: self.refWidget.style['width'] = gui.to_pix(self.refWidget_origin_w + int(x) - self.origin_x ) self.refWidget.style['height'] = gui.to_pix(self.refWidget_origin_h + int(y) - self.origin_y) self.update_position() return self.eventManager.propagate(self.EVENT_ONDRAG, ())
def append_with_label(parent,text,field,button,width=300,key=''): fields_spacing = 5 #horizontal spacing field_height = int(gui.from_pix(field.style['height'])) field_width = int(gui.from_pix(field.style['width'])) label = gui.Label(text,width=width-field_width - 3*fields_spacing-20, height=field_height) _container = gui.Widget(width=width, height=field_height) _container.set_layout_orientation(gui.Widget.LAYOUT_HORIZONTAL) _container.style['margin']='4px' _container.append(label,key='lbl' + str(key)) _container.append(field,key='field'+str(key)) if button is not None: _container.append(button,key='button'+str(key)) parent.append(_container,key=key)
def onclick_bt_set_logo(self, emitter): x = gui.from_pix(self.selection_area_widget.style['left']) y = gui.from_pix(self.selection_area_widget.style['top']) w = gui.from_pix(self.selection_area_widget.style['width']) h = gui.from_pix(self.selection_area_widget.style['height']) self.roi_logo_widget.style['left'] = self.selection_area_widget.style['left'] self.roi_logo_widget.style['top'] = "1px" #self.selection_area_widget.style['top'] self.roi_logo_widget.style['width'] = self.selection_area_widget.style['width'] self.roi_logo_widget.style['height'] = gui.to_pix(self.camera_image.img.shape[0])#self.selection_area_widget.style['height'] img = self.camera_image.img[y:y+h, x:x+w] self.logo_image = img self.save_image_add_miniature(img, "logo.png")
def update_position(self): if self.refWidget == None: return if self.refWidget.style['position'] != 'absolute' or ('right' in self.refWidget.style) or ('bottom' in self.refWidget.style): self.style['display'] = 'none' return try: self.style['position'] = 'absolute' self.style['display'] = 'block' if ('left' in self.refWidget.style) and ('top' in self.refWidget.style) and ('height' in self.refWidget.style) and ('width' in self.refWidget.style) and ('height' in self.style) and ('width' in self.style): self.style['left'] = gui.to_pix(gui.from_pix(self.refWidget.style['width'])+gui.from_pix(self.refWidget.style['left'])-gui.from_pix(self.style['width'])/2) self.style['top'] = gui.to_pix(gui.from_pix(self.refWidget.style['height'])+gui.from_pix(self.refWidget.style['top'])-gui.from_pix(self.style['height'])/2) except: self.style['display'] = 'none'
def append_with_label(parent, text, field, button, width=300, key=''): fields_spacing = 5 #horizontal spacing field_height = int(gui.from_pix(field.style['height'])) field_width = int(gui.from_pix(field.style['width'])) label = gui.Label(text, width=width - field_width - 3 * fields_spacing - 20, height=field_height) _container = gui.Container(width=width, height=field_height) _container.set_layout_orientation(gui.Container.LAYOUT_HORIZONTAL) _container.style['margin'] = '4px' _container.append(label, key='lbl' + str(key)) _container.append(field, key='field' + str(key)) if button is not None: _container.append(button, key='button' + str(key)) parent.append(_container, key=key)
def move_widget(self, css_key, value): # css_key can be 'top' or 'left' # value (int): positive or negative value if issubclass(self.selectedWidget.__class__, gui.Widget) and css_key in self.selectedWidget.style: self.selectedWidget.style[css_key] = gui.to_pix( gui.from_pix(self.selectedWidget.style[css_key]) + value)
def on_drag(self, emitter, x, y): if self.active: if self.origin_x == -1: self.origin_x = int(x) self.origin_y = int(y) self.refWidget_origin_w = gui.from_pix( self.refWidget.style['width']) self.refWidget_origin_h = gui.from_pix( self.refWidget.style['height']) else: self.refWidget.style['width'] = gui.to_pix( self.refWidget_origin_w + int(x) - self.origin_x) self.refWidget.style['height'] = gui.to_pix( self.refWidget_origin_h + int(y) - self.origin_y) self.update_position() return self.eventManager.propagate(self.EVENT_ONDRAG, ())
def update_position(self): if self.refWidget == None: return if self.refWidget.style['position'] != 'absolute' or ( 'right' in self.refWidget.style) or ('bottom' in self.refWidget.style): self.style['display'] = 'none' return try: self.style['position'] = 'absolute' self.style['display'] = 'block' if ('left' in self.refWidget.style) and ( 'top' in self.refWidget.style ) and ('height' in self.refWidget.style) and ( 'width' in self.refWidget.style) and ( 'height' in self.style) and ('width' in self.style): self.style['left'] = gui.to_pix( gui.from_pix(self.refWidget.style['width']) + gui.from_pix(self.refWidget.style['left']) - gui.from_pix(self.style['width']) / 2) self.style['top'] = gui.to_pix( gui.from_pix(self.refWidget.style['height']) + gui.from_pix(self.refWidget.style['top']) - gui.from_pix(self.style['height']) / 2) except: self.style['display'] = 'none'
def on_dropped(self, left, top): self.refWidget.style['width'] = gui.to_pix( gui.from_pix(self.refWidget.style['width']) + gui.from_pix(left) - gui.from_pix(self.style['left'])) self.refWidget.style['height'] = gui.to_pix( gui.from_pix(self.refWidget.style['height']) + gui.from_pix(top) - gui.from_pix(self.style['top'])) self.update_position()
def update_position(self): if self.refWidget == None: return if self.refWidget.style['position'] != 'absolute': self.style['display'] = 'none' return self.style['position'] = 'absolute' self.style['display'] = 'block' self.style['left'] = gui.to_pix( gui.from_pix(self.refWidget.style['width']) + gui.from_pix(self.refWidget.style['left']) - gui.from_pix(self.style['width']) / 2) self.style['top'] = gui.to_pix( gui.from_pix(self.refWidget.style['height']) + gui.from_pix(self.refWidget.style['top']) - gui.from_pix(self.style['height']) / 2)
def on_dropped(self, left, top): try: if ('left' in self.refWidget.style) and ( 'top' in self.refWidget.style ) and ('height' in self.refWidget.style) and ( 'width' in self.refWidget.style) and ( 'height' in self.style) and ('width' in self.style): self.refWidget.style['width'] = gui.to_pix( gui.from_pix(self.refWidget.style['width']) + gui.from_pix(left) - gui.from_pix(self.style['left'])) self.refWidget.style['height'] = gui.to_pix( gui.from_pix(self.refWidget.style['height']) + gui.from_pix(top) - gui.from_pix(self.style['top'])) except: pass self.update_position()
def update_position(self): self.style['position']='absolute' self.style['left']=gui.to_pix(gui.from_pix(self.refWidget.style['left']) + gui.from_pix(self.refWidget.style['width']) - gui.from_pix(self.style['width'])/2) self.style['top']=gui.to_pix(gui.from_pix(self.refWidget.style['top']) + gui.from_pix(self.refWidget.style['height']) - gui.from_pix(self.style['height'])/2)
def _update_size(self): width = gui.from_pix(self.style.get('width', "100").replace("%", "")) height = gui.from_pix(self.style.get('height', "100").replace("%", "")) radius = min(width, height) / 2 self.style['border-radius'] = gui.to_pix(radius)
def image_overprint_thread(app, camera, perspective_correction_value_horiz, perspective_correction_value_vert): """ Si prende un'immagine tutte le successive immagini vengono matchate unite e sovrapposte a questa """ app.process_thread_stop_flag = False images_buffer = None immagine_nastro = None vel_nastro_array = [] similarity_array = [] while not app.process_thread_stop_flag: try: images_buffer = camera.get_image_buf() """ print("attenzione, salvataggio immagini da disabilitare !!!") for t,img in images_buffer[:]: filename = "%s.png"%str(time.time()) cv2.imwrite("./immagini_processo/test/" + filename, img) """ if not images_buffer is None: print("Thread loop - Immagini da giuntare: %s"%len(images_buffer)) mem_t, img = images_buffer[0] immagine_nastro = image_utils.perspective_correction(img, perspective_correction_value_horiz, perspective_correction_value_vert) mem_image = img for t,img in images_buffer[1:]: #img = image_utils.histogram_equalize(img) #img = app.calibrate_image(img) #memorizzazione area logo da selezione a video roi_logo_x1 = gui.from_pix(app.selection_area_widget.style['left']) roi_logo_x2 = roi_logo_x1 + gui.from_pix(app.selection_area_widget.style['width']) #tentativo stitching di nuova immagine in immagine_base e viceversa # lo stitching on similarity piu' vicino a 0 (migliore) viene considerato ok, offset_y, similarity_result = image_utils.find_stitch_offset(img, mem_image, roi_logo_x1, roi_logo_x2, 100) ok, offset_y, similarity_result2 = image_utils.find_stitch_offset(mem_image, img, roi_logo_x1, roi_logo_x2, 100) if similarity_result<similarity_result2: #normale stitching di img in immagine nastro (dove Y img risulta piu' in basso) immagine_nastro = image_utils.stitch_offset(img, immagine_nastro, offset_y) else: #stitching contrario immagine nastro in img (dove Y img risulta piu' alto) # ma siccome vogliamo mantenere l'immagine nastro di sfondo, e volendo inoltre mantenere il risultato # allineato in alto (immagine ferma), copiamo img in immagine_nastro, prendendo di img solo la parte che si sovrappone # a immagine_nastro immagine_nastro = image_utils.stitch_offset(img[offset_y:,:], immagine_nastro, offset_y) #ritagliamo il risultato solo in caso la dimensione supera quella impostata sulla spinbox h = int(app.spin_h_logo.get_value()) if immagine_nastro.shape[0] > h: immagine_nastro = immagine_nastro[0:h,:) # 0:mem_image.shape[1]] if not immagine_nastro is None: app.show_process_image(immagine_nastro) #h = int(app.spin_h_logo.get_value()) #andrebbe determinato h logo #l'ultima immagine la rendo disponibile per il prossimo stitching #img = image_utils.perspective_correction(img, perspective_correction_value_horiz, perspective_correction_value_vert) #immagine_nastro = images_buffer[-1][1]#immagine_nastro[0:h,:] #pulisco l'immagine per il successivo ciclo immagine_nastro = None #time.sleep(1.5) except: print("exception")
def update_position(self): self.style['position']='absolute' if self.refWidget: if 'left' in self.refWidget.style and 'top' in self.refWidget.style: self.style['left']=gui.to_pix(gui.from_pix(self.refWidget.style['left'])-gui.from_pix(self.style['width'])) self.style['top']=gui.to_pix(gui.from_pix(self.refWidget.style['top'])-gui.from_pix(self.style['width']))