Ejemplo n.º 1
0
    def __init__(self, canvas, parent, plot_win, prj, coordinates=True):

        self.plot_win = plot_win
        self.prj = prj
        self.grid_action = None
        self.flagged_action = None
        self.flag_action = None
        self.unflag_action = None
        self.insert_action = None
        self.insert_sample = None
        self.mon_label = None

        self._ids_flag = None
        self._flag_mode = None
        self._flag_start = None
        self._flag_end = None

        # custom  cursors
        pan_px = QtGui.QPixmap(os.path.join(self.media, 'pan_cursor.png'))
        pan_px.setMask(pan_px.mask())
        self.pan_cursor = QtGui.QCursor(pan_px)
        grab_px = QtGui.QPixmap(os.path.join(self.media, 'grab_cursor.png'))
        grab_px.setMask(grab_px.mask())
        self.grab_cursor = QtGui.QCursor(grab_px)

        NavigationToolbar2QT.__init__(self,
                                      canvas=canvas,
                                      parent=parent,
                                      coordinates=coordinates)
        self.setIconSize(QtCore.QSize(24, 24))

        self.canvas.mpl_connect('button_press_event', self.press)
        self.canvas.mpl_connect('button_release_event', self.release)
 def set_color(self, color):
     if color != self._color:
         self._color = color
         self.colorChanged.emit(self._color)
         pixmap = QtGui.QPixmap(self.iconSize())
         pixmap.fill(color)
         self.setIcon(QtGui.QIcon(pixmap))
Ejemplo n.º 3
0
 def set_large_image(self, index):
     self.thumbnails[self.current_thumbnail].setFrameShape(0)
     self.current_thumbnail = index
     pixmap = QtGui.QPixmap(self.entries[self.current_entry].thumbnails[
         self.current_thumbnail])
     self.image_display.setPixmap(pixmap)
     self.thumbnails[self.current_thumbnail].setFrameShape(1)
Ejemplo n.º 4
0
 def _icon(name):
     direct = os.path.dirname(__file__)
     name = os.path.join(direct, name)
     pm = QtGui.QPixmap(name)
     if hasattr(pm, 'setDevicePixelRatio'):
         pm.setDevicePixelRatio(fig.canvas._dpi_ratio)
     return QtGui.QIcon(pm)
Ejemplo n.º 5
0
    def draw_input_image(self, idx1=None, idx2=None, new_image=False):
        """
        Draws input image, with additional box visualizations if a node is selected
        - idx1: idx of object1 (subject)
        - idx2: idx of object2 (object)
        """
        image = np.copy(self.image)

        if idx1 is not None and idx2 is None:
            # its an object node
            image = eval_utils.draw_image_box(image,
                                              self.boxes[idx1].cpu().numpy())

        if idx1 is not None and idx2 is not None:
            # its a predicate node
            image = eval_utils.draw_image_edge(image,
                                               self.boxes[idx1].cpu().numpy(),
                                               self.boxes[idx2].cpu().numpy())
            image = eval_utils.draw_image_box(image,
                                              self.boxes[idx1].cpu().numpy())
            image = eval_utils.draw_image_box(image,
                                              self.boxes[idx2].cpu().numpy())

        image = QtGui.QImage(image, image.shape[1], \
                             image.shape[0], QtGui.QImage.Format_RGB888)

        self.pixmap = QtGui.QPixmap(image)
        self.imb.setPixmap(self.pixmap.scaled(200, 200))

        if new_image:
            self.ima.setVisible(0)
            self.imLoadCounter += 1
Ejemplo n.º 6
0
 def _icon(self, name):
     if is_pyqt5():
         name = name.replace('.png', '_large.png')
     pm = QtGui.QPixmap(os.path.join(self.basedir, name))
     if hasattr(pm, 'setDevicePixelRatio'):
         pm.setDevicePixelRatio(self.canvas._dpi_ratio)
     return QtGui.QIcon(pm)
Ejemplo n.º 7
0
 def set_large_image(self, index):
     self.thumbnails[self.current_thumbnail].setFrameShape(
         _enum('QtWidgets.QFrame.Shape').NoFrame)
     self.current_thumbnail = index
     pixmap = QtGui.QPixmap(
         os.fspath(self.entries[self.current_entry].thumbnails[
             self.current_thumbnail]))
     self.image_display.setPixmap(pixmap)
     self.thumbnails[self.current_thumbnail].setFrameShape(
         _enum('QtWidgets.QFrame.Shape').Box)
 def _icon(self, name, color=None):
     if is_pyqt5():
         name = name.replace('.png', '_large.png')
     pm = QtGui.QPixmap(os.path.join(self.basedir, name))
     if hasattr(pm, 'setDevicePixelRatio'):
         pm.setDevicePixelRatio(self.canvas._dpi_ratio)
     if color is not None:
         mask = pm.createMaskFromColor(QtGui.QColor('black'),
                                       QtCore.Qt.MaskOutColor)
         pm.fill(color)
         pm.setMask(mask)
     return QtGui.QIcon(pm)
Ejemplo n.º 9
0
    def set_entry(self, index):
        if self.current_entry == index:
            return

        self.current_entry = index
        entry = self.entries[index]

        self.pixmaps = []
        for fname, thumbnail in zip(entry.thumbnails, self.thumbnails):
            pixmap = QtGui.QPixmap(fname)
            scaled_pixmap = pixmap.scaled(thumbnail.size(),
                                          QtCore.Qt.KeepAspectRatio,
                                          QtCore.Qt.SmoothTransformation)
            thumbnail.image.setPixmap(scaled_pixmap)
            self.pixmaps.append(scaled_pixmap)

        self.set_large_image(0)
        self.filelist.setCurrentRow(self.current_entry)
Ejemplo n.º 10
0
 def __controls(self):
     #Quit Button
     self.btnQuit = QtWidgets.QPushButton('Quit', self)
     self.btnQuit.setToolTip('Quit from PyTrack')
     self.btnQuit.clicked.connect(self.parent.close)
     #Label stupida
     self.lblinfo = QtWidgets.QLabel(' ',self)
     self.lblinfo.setToolTip('http://esss.se')
     self.lblinfo.setPixmap(QtGui.QPixmap('ESS_Logo.png'))
     #Take a measurement
     self.btnStart = QtWidgets.QPushButton('Start',self)
     self.btnStart.clicked.connect(self.Start)
     self.btnStop = QtWidgets.QPushButton('Stop',self)
     self.btnStop.clicked.connect(self.Stop)
     #Label for Messages
     self.lblMessages=QtWidgets.QLabel('Press button to start',self)
     self.lblAuthors=QtWidgets.QLabel('MuYuan 2019\nSRF Section\nLinac Group\nAcceleration Division')
     self.lblAuthors.setAlignment(QtCore.Qt.AlignCenter)
     self.lblAuthors.setFont(QtGui.QFont('',10))
     #puts a canvas object here
     self.PSensorPlot=PSensorCanvas(self, width=5, height=3.5, dpi=144)
     self.PSensorPlot.setToolTip('IOC Measurement')
     #time message
     self.lblTimeMessages=QtWidgets.QLabel(time.strftime("%d-%m-%Y %H:%M:%S",time.localtime(time.time())),self)
     #other controls
     self.lblOperator=QtWidgets.QLabel('Operator',self)
     self.txtOperator=QtWidgets.QLineEdit(self)
     self.txtOperator.setText('SRF Team')
     self.txtOperator.setFixedWidth(100)
     self.lblLocation=QtWidgets.QLabel('Location',self)
     self.txtLocation=QtWidgets.QLineEdit(self)
     self.txtLocation.setText('SRF Laboratory')
     self.lblComments=QtWidgets.QLabel('Comments',self)
     self.txtComments=QtWidgets.QLineEdit(self)
     self.txtComments.setText('IOC waveform measurement')
     self.txtComments.setFixedWidth(300)
     self.lblScanInterval=QtWidgets.QLabel('Interval:',self)
     self.txtScanInterval=QtWidgets.QLineEdit(self)
     self.txtScanInterval.setText('1')
     self.txtScanInterval.setFixedWidth(40)
     self.lblUnit=QtWidgets.QLabel('s',self)
     self.btnInterval=QtWidgets.QPushButton('Apply',self)
     self.btnInterval.setEnabled(True)
     self.btnInterval.clicked.connect(self.setInterval)
Ejemplo n.º 11
0
 def _icon(self, name):
     pm = QtGui.QPixmap(os.path.join(self.basedir, name))
     if hasattr(pm, 'setDevicePixelRatio'):
         pm.setDevicePixelRatio(self.canvas._dpi_ratio)
     return QtGui.QIcon(pm)
Ejemplo n.º 12
0
    def gen_image(self):
        """
        Generates an image, as indicated by the modified graph
        """
        if self.new_triples is not None:
            triples_ = self.new_triples
        else:
            triples_ = self.triples

        query_feats = None

        model_out = self.model(
            self.new_objs,
            triples_,
            None,
            boxes_gt=self.boxes,
            masks_gt=None,
            src_image=self.imgs_in,
            mode=self.mode,
            query_feats=query_feats,
            keep_box_idx=self.keep_box_idx,
            keep_feat_idx=self.keep_feat_idx,
            combine_gt_pred_box_idx=self.combine_gt_pred_box_idx,
            keep_image_idx=self.keep_image_idx,
            random_feats=args.random_feats,
            get_layout_boxes=True)

        imgs_pred, boxes_pred, masks_pred, noised_srcs, _, layout_boxes = model_out

        image = imagenet_deprocess_batch(imgs_pred)
        image = image[0].detach().numpy().transpose(1, 2, 0).copy()
        if args.update_input:
            self.image = image.copy()

        image = QtGui.QImage(image, image.shape[1], image.shape[0],
                             QtGui.QImage.Format_RGB888)

        im_pm = QtGui.QPixmap(image)
        self.ima.setPixmap(im_pm.scaled(200, 200))
        self.ima.setVisible(1)
        self.imCounter += 1

        if args.update_input:
            # reset everything so that the predicted image is now the input image for the next step
            self.imgs = imgs_pred.detach().clone()
            self.imgs_in = torch.cat(
                [self.imgs,
                 torch.zeros_like(self.imgs[:, 0:1, :, :])], 1)
            self.draw_input_image()
            self.boxes = layout_boxes.detach().clone()
            self.keep_box_idx = torch.ones_like(self.objs.unsqueeze(1),
                                                dtype=torch.float)
            self.keep_feat_idx = torch.ones_like(self.objs.unsqueeze(1),
                                                 dtype=torch.float)
            self.keep_image_idx = torch.ones_like(self.objs.unsqueeze(1),
                                                  dtype=torch.float)
            self.combine_gt_pred_box_idx = torch.zeros_like(self.objs)
        else:
            # input image is still the original one - don't reset anything
            # if an object is added for the first time, the GT/input box is still a dummy (set in add_triple)
            # in this case, we update the GT/input box, using the box predicted from SGN,
            # so that it can be used in future changes that rely on the GT/input box, e.g. replacement
            self.boxes = self.added_objs_idx * layout_boxes.detach().clone(
            ) + (1 - self.added_objs_idx) * self.boxes
            self.added_objs_idx = torch.zeros_like(self.objs.unsqueeze(1),
                                                   dtype=torch.float)
Ejemplo n.º 13
0
 def _icon(self, name):
     pm = QtGui.QPixmap(name)
     if hasattr(pm, 'setDevicePixelRatio'):
         pm.setDevicePixelRatio(self.toolmanager.canvas._dpi_ratio)
     return QtGui.QIcon(pm)