def changeVideoToNextFrame(self): """ Display the next frame of the video/plot """ logging.info("Checking: {0}".format(self.image_holder.cur_idx)) if self.image_holder.cur_idx < self.image_holder.vidLen - 1: img, plot_img = self.nextFrame() self.vid_player.setPixmap(toqpixmap(img)) if plot_img != None: self.plot_player.setPixmap(toqpixmap(plot_img))
def changeFrameTo(self, img, plot_img=None): """Change the currently displayed image on the video player or on the plot player Arguments: img {PIL Image} -- Display this image on the video player Keyword Arguments: plot_img {PIL Image} -- Display this image on the plot player (default: {None}) """ if img != None: self.vid_player.setPixmap(toqpixmap(img)) if plot_img != None: self.plot_player.setPixmap(toqpixmap(plot_img))
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.cap = None self.vid_opened = False self.signalSetup() # uic.loadUi("mainwindow.ui", self) im = Image.open("picasso.jpg") pixImg = toqpixmap(im) self.ui.l_video.setPixmap(pixImg) self.openVideo("a.mp4") img = self.nextFrame() p = toqpixmap(img)
def __init__(self, parent, cursor: AnimatedCursor): super().__init__(parent) self._core_painter = QtGui.QPainter() self._pixmaps = [ toqpixmap(sub_cur[self.CURSOR_SIZE].image) for sub_cur, delay in cursor ] self._hotspots = [ sub_cur[self.CURSOR_SIZE].hotspot for sub_cur, delay in cursor ] self._delays = [delay for sub_cur, delay in cursor] self._animation_timer = QtCore.QTimer() self._animation_timer.setSingleShot(True) self._animation_timer.timeout.connect(self.moveStep) self._current_frame = -1 self._main_layout = QtWidgets.QVBoxLayout() self._example_label = QtWidgets.QLabel( "Hover over me to see the cursor! Click to see the hotspot.") self._main_layout.addWidget(self._example_label) self.setLayout(self._main_layout) self._hotspot_preview_loc = None self._pressed = False self.moveStep()
def clicked(self, N): if N >= self.K: print('invalid palette') return print('change palette', N, 'to', end='\t') # choose new color curr_clr = self.palette_color[N] current = QColor(curr_clr[0], curr_clr[1], curr_clr[2]) color = QColorDialog.getColor(initial=current, options=QColorDialog.DontUseNativeDialog) print(color_np(color)) #new_palette = Image.new('RGB',(1,1),html_color(color_np(color))) #palette_lab = np.array(rgb2lab(new_palette).getpixel((0,0))) #print(palette_lab) ###### test ##### print(self.palette2mean()) ###### test ##### self.palette_color[N] = color_np(color) self.set_palette_color() # modify image ####palette_color_lab = cv2.cvtColor( #### self.palette_color[None,:,:],cv2.COLOR_RGB2Lab)[0] ####print(palette_color_lab) self.img = img_color_transfer( self.img_lab, self.means, self.palette2mean(), \ self.sample_weight_map, self.sample_colors, self.sample_level) print('Done') ## for testing #enhancer = ImageEnhance.Brightness(self.img) #self.img = enhancer.enhance(1.1) # show image #self.image_label.setPixmap(pixmap) resized = toqpixmap(self.img).scaledToHeight(512) self.image_label.setPixmap(resized)
def current_cursor(self, cursor: AnimatedCursor): self._cur = cursor self._current_frame = -1 self._is_ani = False self.__animation_timer.stop() if cursor is not None and (len(cursor) > 0): self._cur.normalize([(self._size, self._size)]) self._imgs = [ toqpixmap(cur[(self._size, self._size)].image) for cur, delay in cursor ] self._delays = [delay for cur, delay in cursor] if len(cursor) > 1: self._is_ani = True else: self._imgs = [ QtGui.QPixmap( QtGui.QImage( bytes(4 * self._size**2), self._size, self._size, 4, QtGui.QImage.Format_ARGB32, )) ] self._delays = [0] self.move_step()
def color_pix(color): im = new_im('RGB', (128, 128)) draw = ImageDraw(im, 'RGB') draw.rectangle((0, 0, 128, 128), fill=(int(color[1:3], 16), int(color[3:5], 16), int(color[5:], 16))) return toqpixmap(im)
def changeVideoToNextFrame(self): """ Display the next frame of the video """ print("Checking: ", self.image_holder.cur_idx) if self.image_holder.cur_idx < self.image_holder.vidLen - 1: print("Success") self.vid_player.setPixmap(toqpixmap(self.nextFrame()))
def frame(self, value: int): if 0 <= value < len(self._cursor): self._frame = value self._frame_img = toqpixmap( self._cursor[self._frame][0][self.VIEW_SIZE].image) self.update() else: raise ValueError( f"The frame must land within length of the animated cursor!")
def pixmap_open_img(self, k): # load image self.img = Image.open(self.Source) print(self.Source, self.img.format, self.img.size, self.img.mode) # transfer to lab self.img_lab = rgb2lab(self.img) # get palettes self.calc_palettes(k) pixmap = toqpixmap(self.img) #self.set_number_of_palettes('5') # default 5 palettes return pixmap
def style_transfer(self): print('style transfer in development') options = QFileDialog.Options() file_name, _ = QFileDialog.getOpenFileName( self,"QFileDialog.getOpenFileName()", "", \ "Images (*.jpg *.JPG *jpeg *.png *.webp *.tiff *.tif *.bmp *.dib);;All Files (*)", options=options) if len(file_name) == 0: return # load image style_img = Image.open(file_name) # transfer to lab style_img_lab = rgb2lab(style_img) # get palettes colors = style_img_lab.getcolors(style_img.width * style_img.height) bins = {} for count, pixel in colors: bins[pixel] = count bins = sample_bins(bins) style_means, _ = \ k_means(bins, k=self.K, init_mean=True) print('style', style_means) # rbf weights # style_sample_weight_map = rbf_weights(style_means, self.sample_colors) # change GUI palette color style_palette = np.zeros(style_means.shape) for i in range(0, self.means.shape[0]): lab = Image.new('LAB', (1, 1), html_color(style_means[i].astype(int))) style_palette[i] = np.array(lab2rgb(lab).getpixel((0, 0))) self.palette_color = style_palette.astype(int) self.set_palette_color() #transfer self.img = img_color_transfer( self.img_lab, self.means, style_means, \ self.sample_weight_map, self.sample_colors, self.sample_level) print('Done') resized = toqpixmap(self.img).scaledToHeight(512) self.image_label.setPixmap(resized)
def auto(self): print(self.palette_color) self.palette_color = \ auto_palette(self.palette_color, self.means_weight) self.set_palette_color() print(self.palette_color) # modify image ####palette_color_lab = cv2.cvtColor( #### self.palette_color[None,:,:],cv2.COLOR_RGB2Lab)[0] ####print(palette_color_lab) self.img = img_color_transfer( self.img_lab, self.means, self.palette2mean(), \ self.sample_weight_map, self.sample_colors, self.sample_level) print('Done') ## for testing #enhancer = ImageEnhance.Brightness(self.img) #self.img = enhancer.enhance(1.1) # show image #self.image_label.setPixmap(pixmap) resized = toqpixmap(self.img).scaledToHeight(512) self.image_label.setPixmap(resized)
def __init__(self, parent=None, *args, **kwargs): super().__init__(parent, *args, **kwargs) mem_icon = BytesIO(base64.b64decode(ICON)) self.setWindowTitle("Cursor Theme Builder") self.setWindowIcon(QtGui.QIcon(toqpixmap(Image.open(mem_icon)))) self._open_build_project = None self._metadata = {"author": None, "licence": None} self._main_layout = QtWidgets.QVBoxLayout(self) self._scroll_pane = QtWidgets.QScrollArea() self._scroll_pane.setVerticalScrollBarPolicy( QtCore.Qt.ScrollBarAsNeeded) self._scroll_pane.setHorizontalScrollBarPolicy( QtCore.Qt.ScrollBarAlwaysOff) self._scroll_pane.setWidgetResizable(True) self._inner_pane_area = QtWidgets.QWidget() self._flow_layout = FlowLayout() self._cursor_selectors = {} for cursor_name in sorted(CursorThemeBuilder.DEFAULT_CURSORS): self._cursor_selectors[cursor_name] = CursorSelectWidget( label_text=cursor_name) self._flow_layout.addWidget(self._cursor_selectors[cursor_name]) self._edit_metadata = QtWidgets.QPushButton("Edit Artist Info") self._main_layout.addWidget(self._edit_metadata) self._inner_pane_area.setLayout(self._flow_layout) self._scroll_pane.setWidget(self._inner_pane_area) self._button_layout = QtWidgets.QHBoxLayout() self._main_layout.addWidget(self._scroll_pane) self._build_button = QtWidgets.QPushButton("Build Project") self._create_proj_btn = QtWidgets.QPushButton("Save Project") self._load_proj_btn = QtWidgets.QPushButton("Load Project") self._update_proj_btn = QtWidgets.QPushButton("Update Project") self._build_in_place = QtWidgets.QPushButton("Build in Place") self._clear_btn = QtWidgets.QPushButton("New Project") self._update_proj_btn.setEnabled(False) self._build_in_place.setEnabled(False) self._button_layout.addWidget(self._build_button) self._button_layout.addWidget(self._create_proj_btn) self._button_layout.addWidget(self._load_proj_btn) self._button_layout.addWidget(self._update_proj_btn) self._button_layout.addWidget(self._build_in_place) self._button_layout.addWidget(self._clear_btn) self._main_layout.addLayout(self._button_layout) self.setLayout(self._main_layout) # self.setMinimumSize(self.sizeHint()) self._build_button.clicked.connect(self.build_project) self._create_proj_btn.clicked.connect(self.create_project) self._load_proj_btn.clicked.connect(self.load_project) self._update_proj_btn.clicked.connect(self.update_project) self._build_in_place.clicked.connect(self.build_in_place) self._clear_btn.clicked.connect(self.clear_ui) self._edit_metadata.clicked.connect(self._chg_metadata)
def changeFrameTo(self, img): self.vid_player.setPixmap(toqpixmap(img))
def changeVideoToNextFrame(self): print("Hello") self.ui.l_video.setPixmap(toqpixmap(self.nextFrame()))