Exemplo n.º 1
0
def convert_bitmap(image, width=None, height=None):
    pix = None
    if isinstance(image, ImageResource):
        pix = traitsui_convert_bitmap(image)
    elif isinstance(image, Image):
        # image = image.convert('RGBA')
        data = image.tostring('raw', 'RGBA')
        im = QImage(data, image.size[0], image.size[1], QImage.Format_ARGB32)
        pix = QPixmap.fromImage(QImage.rgbSwapped(im))
    else:
        s = image.shape
        if len(s) >= 2:
            # im = QImage(image.tostring(),s[1], s[0], QImage.Format_RGB888)
            im = QImage(image, s[1], s[0], QImage.Format_RGB888)
            pix = QPixmap.fromImage(QImage.rgbSwapped(im))
        else:
            pix = QPixmap()
    if pix:
        if width > 0 and height > 0:
            pix = pix.scaled(width, height)
        elif width > 0:
            pix = pix.scaledToWidth(width)
        if height > 0:
            pix = pix.scaledToHeight(height)

    return pix
Exemplo n.º 2
0
 def mathTex_to_QPixmap(self, mathTex, fs):
 
 
     self.fig.patch.set_facecolor('none')
     t = self.ax.text(0, 0, mathTex, ha='left', va='bottom', fontsize=fs)
 
     #---- fit figure size to text artist ----
 
     fwidth, fheight = self.fig.get_size_inches()
     fig_bbox = self.fig.get_window_extent(self.renderer)
 
     text_bbox = t.get_window_extent(self.renderer)
 
     tight_fwidth = text_bbox.width * fwidth / fig_bbox.width
     tight_fheight = text_bbox.height * fheight / fig_bbox.height
 
     self.fig.set_size_inches(tight_fwidth, tight_fheight)
 
     #---- convert mpl figure to QPixmap ----
 
     buf, size = self.fig.canvas.print_to_buffer()
     qimage = QImage.rgbSwapped(QImage(buf, size[0], size[1], QImage.Format_ARGB32))
     qpixmap = QPixmap(qimage)
     self.ax.cla()
     
     return qpixmap
Exemplo n.º 3
0
 def paint(self, painter, option, widget=None):
     painter_inverted = QPainter()
     brect= QGraphicsProxyWidget.boundingRect(self)
     invertedColor = QImage(brect.width(),brect.height(),QImage.Format_RGB32)
     painter_inverted.begin(invertedColor)
     QGraphicsProxyWidget.paint(self,painter_inverted, option, widget)
     painter_inverted.end()
     painter.drawImage(0,0,invertedColor.rgbSwapped())
Exemplo n.º 4
0
    def _update(self):
        # w, h = self.control.width(), self.control.height()
        # img = self.value.get_image_data(size=(w, h))
        img = self.value.get_image_data()
        if img is not None:
            s = img.shape
            if s:
                im = QImage(img, s[1], s[0], QImage.Format_RGB32)
                # im = QImage(img, s[1], s[0], QImage.Format_RGB16)
                if self.swap:
                    im = QImage.rgbSwapped(im)

                pix = QPixmap.fromImage(im)
                self.control.setPixmap(pix)
Exemplo n.º 5
0
    def _update(self):
        # w, h = self.control.width(), self.control.height()
        # img = self.value.get_image_data(size=(w, h))
        img = self.value.get_image_data()
        if img is not None:
            s = img.shape
            if s:
                im = QImage(img, s[1], s[0], QImage.Format_RGB32)
                # im = QImage(img, s[1], s[0], QImage.Format_RGB16)
                if self.swap:
                    im = QImage.rgbSwapped(im)

                pix = QPixmap.fromImage(im)
                self.control.setPixmap(pix)
Exemplo n.º 6
0
def convert_bitmap(image, width=None, height=None):
    if isinstance(image, ImageResource):
        pix = traitsui_convert_bitmap(image)
    elif isinstance(image, Image):
        data = image.tostring('raw', 'RGBA')
        im = QImage(data, image.size[0], image.size[1], QImage.Format_ARGB32)
        pix = QPixmap.fromImage(QImage.rgbSwapped(im))
    else:
        s = image.shape
        if len(s) >= 2:
            pix = QPixmap.fromImage(array2qimage(image))
        else:
            pix = QPixmap()
    if pix:
        if width > 0 and height > 0:
            pix = pix.scaled(width, height)
        elif width > 0:
            pix = pix.scaledToWidth(width)
        if height > 0:
            pix = pix.scaledToHeight(height)

    return pix
Exemplo n.º 7
0
    def initializeGL(self):  # noqa
        GL.glClearDepth(1.0)
        GL.glDepthFunc(GL.GL_LESS)
        GL.glShadeModel(GL.GL_SMOOTH)
        GL.glEnable(GL.GL_CULL_FACE)
        GL.glEnable(GL.GL_POLYGON_OFFSET_FILL)
        GL.glPolygonOffset(1, 1)

        image = cv2.flip(self.frame.image, 0)
        height, width = image.shape[0], image.shape[1]
        image = QImage(image.data, width, height, QImage.Format_RGB888)
        self.texture = self.bindTexture(image.rgbSwapped())

        self.object_drawer = GL.glGenLists(1)  # noqa
        GL.glNewList(self.object_drawer, GL.GL_COMPILE)
        points = self.object.get_points()
        for face in self.object.get_faces():
            GL.glBegin(GL.GL_POLYGON)
            for i in face:
                point = points[i]
                GL.glVertex4fv(point)
            GL.glEnd()
        GL.glEndList()

        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glLoadIdentity()
        GL.glMultMatrixf(self.frame.internal_camera_parameters.T)

        def rotate(rotation):
            for vector, angle in zip(((0, 0, 1), (0, 1, 0), (1, 0, 0)),
                                     reversed(rotation)):
                GL.glRotatef(angle, *vector)

        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glLoadIdentity()
        GL.glTranslatef(*self.frame.camera_position.translation)
        rotate(self.frame.camera_position.orientation)
        GL.glTranslatef(*self.frame.object_position.translation)
        rotate(self.frame.object_position.orientation)
Exemplo n.º 8
0
def convert_bitmap(image, width=None, height=None):
    pix = None
    if isinstance(image, ImageResource):
        pix = traitsui_convert_bitmap(image)
    else:
        s = image.shape
        if len(s) >= 2:
            im = QImage(image.tostring(), s[1], s[0], QImage.Format_RGB888
                        #                      QImage.Format_RGB16
                        )

            pix = QPixmap.fromImage(QImage.rgbSwapped(im))

    if pix:
        if width > 0 and height > 0:
            pix = pix.scaled(width, height)
        elif width > 0:
            pix = pix.scaledToWidth(width)
        if height > 0:
            pix = pix.scaledToHeight(height)

    return pix
Exemplo n.º 9
0
def convert_bitmap(image, width=None, height=None):
    pix = None
    if isinstance(image, ImageResource):
        pix = traitsui_convert_bitmap(image)
    else:
        s = image.shape
        if len(s) >= 2:
            im = QImage(image.tostring(),
                         s[1], s[0],
                        QImage.Format_RGB888
    #                      QImage.Format_RGB16
                         )

            pix = QPixmap.fromImage(QImage.rgbSwapped(im))

    if pix:
        if width > 0 and height > 0:
            pix = pix.scaled(width, height)
        elif width > 0:
            pix = pix.scaledToWidth(width)
        if height > 0:
            pix = pix.scaledToHeight(height)

    return pix
Exemplo n.º 10
0
 def set_frame(self):
     ok, data = self.cap.read()
     shape = data.shape
     im = QImage(data, shape[1], shape[0], QImage.Format_RGB888)
     pix = QPixmap.fromImage(QImage.rgbSwapped(im))
     self.label.setPixmap(pix)
Exemplo n.º 11
0
 def set_frame(self):
     ok, data = self.cap.read()
     shape = data.shape
     im = QImage(data, shape[1], shape[0], QImage.Format_RGB888)
     pix = QPixmap.fromImage(QImage.rgbSwapped(im))
     self.label.setPixmap(pix)