python类QPixmap()的实例源码

caffeNetViewer.py 文件源码 项目:caffeNetViewer 作者: birolkuyumcu 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def showImg(self,label,img):
        if len(img.shape) == 2:
            img = cv2.applyColorMap(img, cv2.COLORMAP_JET)
            img = cv2.resize(img, (512, 512),cv2.INTER_AREA)
        height, width, byteValue = img.shape
        byteValue = byteValue * width
        timg = img.copy()
        image = QtGui.QImage(timg.data, width, height,byteValue, QtGui.QImage.Format_RGB888)
        label.setPixmap(QtGui.QPixmap(image).scaled(label.size(),aspectMode=QtCore.Qt.KeepAspectRatio))     


        """ visualize function from
        https://github.com/BVLC/caffe/blob/master/examples/00-classification.ipynb
        """
caffeNetViewer.py 文件源码 项目:caffeNetViewer 作者: birolkuyumcu 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def vis_square(self, data):
        """Take an array of shape (n, height, width) or (n, height, width, 3)
           and visualize each (height, width) thing in a grid of size approx. sqrt(n) by sqrt(n)"""

        print "Data Shape : ", data.shape

        # normalize data for display
        data = (data - data.min()) / (data.max() - data.min())

        # force the number of filters to be square
        n = int(np.ceil(np.sqrt(data.shape[0])))
        padding = (((0, n ** 2 - data.shape[0]),
                    (0, 1), (0, 1))  # add some space between filters
                   + ((0, 0),) * (data.ndim - 3))  # don't pad the last dimension (if there is one)
        data = np.pad(data, padding, mode='constant', constant_values=0)  # pad with ones (white)

        # tile the filters into an image
        data = data.reshape((n, n) + data.shape[1:]).transpose((0, 2, 1, 3) + tuple(range(4, data.ndim + 1)))
        data = data.reshape((n * data.shape[1], n * data.shape[3]) + data.shape[4:])

        # show at display
        #print 'Data shape : ', data.shape , len(data.shape)
        img = 255 * data
        img = cv2.resize(img, (512, 512))
        img = np.array(img, dtype='uint8')
        img_c = cv2.applyColorMap(img, cv2.COLORMAP_JET)
        height, width, byteValue = img_c.shape
        byteValue = byteValue * width
        self.image = QtGui.QImage(img_c.data, width, height, byteValue, QtGui.QImage.Format_RGB888)
        self.ui.labelDisplay.setPixmap(QtGui.QPixmap(self.image))
lineyka_manager.py 文件源码 项目:lineyka 作者: volodya-renderberg 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def tm_make_preview_ui(self):
        self.makePreviewDialog = QtGui.QDialog(self)
        self.makePreviewDialog.setModal(True)
        #self.makePreviewDialog.resize(300, 300)
        self.makePreviewDialog.setWindowTitle(('Make Preview: /// ' + self.current_task['asset']))

        # add widgets
        v_layout = QtGui.QVBoxLayout()
        # -- image Label
        self.makePreviewDialog.imageLabel = QtGui.QLabel()
        self.makePreviewDialog.imageLabel.setFixedSize(300,300)
        v_layout.addWidget(self.makePreviewDialog.imageLabel)

        # -- button
        h__layout = QtGui.QHBoxLayout()
        button_frame = QtGui.QFrame(parent = self.makePreviewDialog)
        cansel_button = QtGui.QPushButton('Cansel', parent = button_frame)
        h__layout.addWidget(cansel_button)
        paste_button = QtGui.QPushButton('Paste', parent = button_frame)
        h__layout.addWidget(paste_button)
        save_button = QtGui.QPushButton('Save', parent = button_frame)
        h__layout.addWidget(save_button)
        button_frame.setLayout(h__layout)

        v_layout.addWidget(button_frame)
        self.makePreviewDialog.setLayout(v_layout)

        # connect buttons
        cansel_button.clicked.connect(partial(self.close_window, self.makePreviewDialog))
        paste_button.clicked.connect(partial(self.tm_paste_image_from_clipboard, self.makePreviewDialog.imageLabel))
        save_button.clicked.connect(partial(self.tm_save_preview_image_action, self.makePreviewDialog))

        # -- load img to label
        img_path = os.path.join(self.db_chat.preview_img_path, (self.current_task['asset'] + '.png'))
        if not os.path.exists(img_path):
            self.makePreviewDialog.imageLabel.setText('No Image')
        else:
            image = QtGui.QImage(img_path)
            self.makePreviewDialog.imageLabel.setPixmap(QtGui.QPixmap.fromImage(image))

        self.makePreviewDialog.show()
lineyka_manager.py 文件源码 项目:lineyka 作者: volodya-renderberg 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def tm_paste_image_from_clipboard(self, img_label):
        rand  = hex(random.randint(0, 1000000000)).replace('0x', '')
        img_path = os.path.normpath(os.path.join(self.db_chat.tmp_folder, ('tmp_image_' + rand + '.png')))

        clipboard = QtGui.QApplication.clipboard()
        img = clipboard.image()
        if img:
            img.save(img_path)
            cmd = '%s %s -resize 300 %s' % (os.path.normpath(self.db_chat.convert_exe), img_path, img_path)
            cmd2 = '%s %s -resize 300x300 %s' % (os.path.normpath(self.db_chat.convert_exe), img_path, img_path)
            cmd3 = '\"%s\" \"%s\" -resize 300 \"%s\"' % (os.path.normpath(self.db_chat.convert_exe), img_path, img_path)
            print(cmd)
            print(cmd2)
            print(cmd3)
            try:
                os.system(cmd)
            except:
                try:
                    os.system(cmd2)
                except:
                    try:
                        os.system(cmd3)
                    except: 
                        return(False, 'in tm_paste_image_from_clipboard - problems with conversion resize.png')
        else:
            self.message('Cannot Image!', 2)
            return(False, 'Cannot Image!')

        image = QtGui.QImage(img_path)
        img_label.setPixmap(QtGui.QPixmap.fromImage(image))
        self.makePreviewDialog.img_path = img_path
lineyka_manager.py 文件源码 项目:lineyka 作者: volodya-renderberg 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def tm_save_preview_image_action(self, window):
        # self.preview_img_path
        if not os.path.exists(self.db_chat.preview_img_path):
            try:
                os.mkdir(self.db_chat.preview_img_path)
            except:
                print(self.db_chat.preview_img_path)

        # copyfile
        save_path = os.path.join(self.db_chat.preview_img_path, (self.current_task['asset'] + '.png'))
        icon_path = os.path.join(self.db_chat.preview_img_path, (self.current_task['asset'] + '_icon.png'))
        tmp_icon_path = window.img_path.replace('.png','_icon.png')
        # -- copy
        shutil.copyfile(window.img_path, save_path)

        # -- resize
        cmd = '%s %s -resize 100 %s' % (os.path.normpath(self.db_chat.convert_exe), window.img_path, tmp_icon_path)
        cmd2 = '%s %s -resize 100x100 %s' % (os.path.normpath(self.db_chat.convert_exe), window.img_path, tmp_icon_path)
        cmd3 = '\"%s\" \"%s\" -resize 100 \"%s\"' % (os.path.normpath(self.db_chat.convert_exe), window.img_path, tmp_icon_path)
        try:
            os.system(cmd)
        except:
            try:
                os.system(cmd2)
            except:
                try:
                    os.system(cmd3)
                except:
                    self.message('problems with conversion _icon.png', 2)
                    return(False, 'in tm_save_preview_image_action - problems with conversion resize.png')

        shutil.copyfile(tmp_icon_path, icon_path)

        # load to preview  image_label
        image = QtGui.QImage(save_path)
        self.myWidget.image_label.setPixmap(QtGui.QPixmap.fromImage(image))

        self.close_window(window)

    # ------ show tz ------------
app.py 文件源码 项目:FitScan 作者: GunfighterJ 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def setupLabelIcons(self):
        self.ui.label_highslot_icon.setPixmap(QtGui.QPixmap(":img/slot_high_small.png"))
        self.ui.label_midslot_icon.setPixmap(QtGui.QPixmap(":img/slot_med_small.png"))
        self.ui.label_lowslot_icon.setPixmap(QtGui.QPixmap(":img/slot_low_small.png"))
        self.ui.label_rig_icon.setPixmap(QtGui.QPixmap(":img/slot_rig_small.png"))
        self.ui.label_subsystem_icon.setPixmap(QtGui.QPixmap(":img/slot_subsystem_small.png"))
app.py 文件源码 项目:FitScan 作者: GunfighterJ 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, parent=None):
        super(InstructionDialog, self).__init__(parent)
        self.setupUi(self)

        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(":img/icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.setWindowIcon(icon)

        self.setWindowFlags(QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint)

        self.pushButton_OK.clicked.connect(self.close)
spool.py 文件源码 项目:kite 作者: pyrocko 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self, scene=None, import_data=None, load_file=None):
        QtGui.QApplication.__init__(self, ['Spool'])
        # self.setStyle('plastique')
        splash_img = QtGui.QPixmap(get_resource('spool_splash.png'))\
            .scaled(QtCore.QSize(400, 250), QtCore.Qt.KeepAspectRatio)
        self.splash = QtGui.QSplashScreen(
            splash_img, QtCore.Qt.WindowStaysOnTopHint)
        self.updateSplashMessage('Scene')
        self.splash.show()
        self.processEvents()

        self.spool_win = SpoolMainWindow()
        self.spool_win.sigLoadingModule.connect(self.updateSplashMessage)

        self.spool_win.actionExit.triggered.connect(self.exit)
        self.aboutToQuit.connect(self.spool_win.model.worker_thread.quit)
        self.aboutToQuit.connect(self.spool_win.model.deleteLater)
        self.aboutToQuit.connect(self.splash.deleteLater)
        self.aboutToQuit.connect(self.deleteLater)

        if scene is not None:
            self.addScene(scene)
        if import_data is not None:
            self.importScene(import_data)
        if load_file is not None:
            self.loadScene(load_file)

        self.splash.finish(self.spool_win)
        self.spool_win.show()
        rc = self.exec_()
        sys.exit(rc)
main.py 文件源码 项目:porn_sieve 作者: PornSieve 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def refresh_images(self):
        try:
            r = requests.get(self.cur_img)
        except:
            return None

        if r.status_code == 200:
            pixmap = QtGui.QPixmap()
            pixmap.loadFromData(r.content)
            pixmap.scaledToWidth(self.preview_size)
            pixmap.scaledToHeight(self.preview_size)
            self.img.setPixmap(pixmap)
            self.img.update()
            self.repaint()
        r.close()
        data = self.db.get(self.cur_vid)

        self.setWindowTitle(data["name"])
        info_str = "dur: {}\n\nviews: {}\n\nprediction: {}\n\ntags: {}"

        n_tags = 15
        tag_str = ""
        if data["tags"]:
            tags = [tag for tag in data["tags"] if len(tag) > 2]
            tags = tags[:min(n_tags, len(data["tags"]))]
            for tag in tags:
                tag_str += "\n" + tag


        info_str = info_str.format(data["dur"],
                                   data["views"],
                                   # old design had an out of 6 scale
                                   round(self.last_pred, 2),
                                   tag_str)
        self.info_box.setText(info_str)
twitterMonitor.py 文件源码 项目:twitterMonitor 作者: birolkuyumcu 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def showWordCloud(self):
        wordcloud = WordCloud(width=800, height=400).generate(self.fullText)
        img = np.array(wordcloud.to_image())
        height, width, byteValue = img.shape
        byteValue = byteValue * width
        image = QtGui.QImage(img.data, width, height, byteValue, QtGui.QImage.Format_RGB888)
        pxmp = QtGui.QPixmap(image)
        self.label.setPixmap(pxmp)
ccspecan.py 文件源码 项目:PandwaRF 作者: ComThings 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def _new_graph(self):
        self._graph = QtGui.QPixmap(self.width(), self.height())
        self._graph.fill(Qt.black)
ccspecan.py 文件源码 项目:PandwaRF 作者: ComThings 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _new_reticle(self):
        self._reticle = QtGui.QPixmap(self.width(), self.height())
        self._reticle.fill(Qt.transparent)
shotManager.py 文件源码 项目:nukeScripts 作者: mlavoy 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def updateShotThumbnail(self,*args):
        if not os.path.exists(self.thumbsPath):
            os.makedirs(self.thumbsPath)
        availthumbs=os.listdir(self.thumbsPath)
        if self.selShot+".jpg" in availthumbs:
            self.iconLabel.setPixmap(QtGui.QPixmap(self.thumbsPath+'/'+self.selShot+'.jpg'))
        else:
            self.iconLabel.setPixmap('')
LShapeRebar.py 文件源码 项目:FreeCAD-Reinforcement 作者: amrit3701 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def getOrientation(self):
        orientation = self.form.orientation.currentText()
        if orientation == "Bottom Right":
            self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] + "/icons/LShapeRebarBR.svg"))
        elif orientation == "Bottom Left":
            self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] + "/icons/LShapeRebarBL.svg"))
        elif orientation == "Top Right":
            self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] + "/icons/LShapeRebarTR.svg"))
        else:
            self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] + "/icons/LShapeRebarTL.svg"))
StraightRebar.py 文件源码 项目:FreeCAD-Reinforcement 作者: amrit3701 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __init__(self, Rebar = None):
        self.CustomSpacing = None
        if not Rebar:
            selected_obj = FreeCADGui.Selection.getSelectionEx()[0]
            self.SelectedObj = selected_obj.Object
            self.FaceName = selected_obj.SubElementNames[0]
        else:
            self.FaceName = Rebar.Base.Support[0][1][0]
            self.SelectedObj = Rebar.Base.Support[0][0]
        self.form = FreeCADGui.PySideUic.loadUi(os.path.splitext(__file__)[0] + ".ui")
        self.form.setWindowTitle(QtGui.QApplication.translate("RebarAddon", "Straight Rebar", None))
        self.form.orientation.addItems(["Horizontal", "Vertical"])
        self.form.coverAlong.addItems(["Bottom Side", "Top Side"])
        self.form.amount_radio.clicked.connect(self.amount_radio_clicked)
        self.form.spacing_radio.clicked.connect(self.spacing_radio_clicked)
        self.form.customSpacing.clicked.connect(lambda: runRebarDistribution(self))
        self.form.removeCustomSpacing.clicked.connect(lambda: removeRebarDistribution(self))
        self.form.PickSelectedFace.setCheckable(True)
        self.form.PickSelectedFace.toggle()
        self.form.PickSelectedFace.clicked.connect(lambda: getSelectedFace(self))
        self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] + "/icons/StraightRebarH.svg"))
        self.form.orientation.currentIndexChanged.connect(self.changeOrientation)
        self.form.coverAlong.currentIndexChanged.connect(self.changeCoverAlong)
        self.form.toolButton.setIcon(self.form.toolButton.style().standardIcon(QtGui.QStyle.SP_DialogHelpButton))
        self.form.toolButton.clicked.connect(lambda: showPopUpImageDialog(os.path.split(os.path.abspath(__file__))[0] + "/icons/StraightRebarDetailed.svg"))
        self.Rebar = Rebar
StraightRebar.py 文件源码 项目:FreeCAD-Reinforcement 作者: amrit3701 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def changeOrientation(self):
        orientation = self.form.orientation.currentText()
        if orientation == "Horizontal":
            self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] + "/icons/StraightRebarH.svg"))
            self.form.r_sideCoverLabel.setText("Right Side Cover")
            self.form.l_sideCoverLabel.setText("Left Side Cover")
            self.form.coverAlong.clear()
            self.form.coverAlong.addItems(["Bottom Side", "Top Side"])
        else:
            self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] + "/icons/StraightRebarV.svg"))
            self.form.r_sideCoverLabel.setText("Top Side Cover")
            self.form.l_sideCoverLabel.setText("Bottom Side Cover")
            self.form.coverAlong.clear()
            self.form.coverAlong.addItems(["Right Side", "Left Side"])
BentShapeRebar.py 文件源码 项目:FreeCAD-Reinforcement 作者: amrit3701 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def getOrientation(self):
        orientation = self.form.orientation.currentText()
        #if orientation == "Bottom":
        #    self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] + "/icons/LShapeRebarBR.svg"))
        #elif orientation == "Top":
        #    self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] + "/icons/LShapeRebarBL.svg"))
        #elif orientation == "Right":
        #    self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] + "/icons/LShapeRebarTR.svg"))
        #else:
        #    self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] + "/icons/LShapeRebarTL.svg"))
RebarDistribution.py 文件源码 项目:FreeCAD-Reinforcement 作者: amrit3701 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self, frontCover, size):
        self.FrontCover = frontCover
        self.ExpandingLength = size
        self.form = FreeCADGui.PySideUic.loadUi(os.path.splitext(__file__)[0] + ".ui")
        self.form.setWindowTitle(QtGui.QApplication.translate("Arch", "Rebar Distribution", None))
        self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] + "/icons/RebarDistribution.svg"))
UShapeRebar.py 文件源码 项目:FreeCAD-Reinforcement 作者: amrit3701 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def getOrientation(self):
        orientation = self.form.orientation.currentText()
        if orientation == "Bottom":
            self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] + "/icons/UShapeRebarBottom.svg"))
        elif orientation == "Top":
            self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] + "/icons/UShapeRebarTop.svg"))
        elif orientation == "Right":
            self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] + "/icons/UShapeRebarRight.svg"))
        else:
            self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] + "/icons/UShapeRebarLeft.svg"))
driveset_reader.py 文件源码 项目:uah_driveset_reader 作者: Eromera 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def startCapture(self):
      global currentSecond
      global delayVideoData
      #cap = self.capturer
      num = 0
      while(self.capturing):
         while (self.paused and self.capturing):
            time.sleep(0.05)

         prevTime = datetime.now()

         if (self.frameNumberChanged):
            newFrameNumber = int(self.sliderVideoFrame.value()*30)
            num = newFrameNumber
            self.frameNumber = newFrameNumber
            self.frameNumberChanged = False

         frame = self.videoReader.get_data(num)
         num = num+1

         if (num >= self.videoReader.get_length()):
            self.frameNumberChanged=True
            self.sliderVideoFrame.setValue(0)
            self.start_button.setText('Start')
            self.video_thread = False
            self.capturing = False      
            break

         self.frameNumber = num
         currentSecond = self.frameNumber/fps   #valor importante para sync datos
         self.labelCurrentVideoSecond.setText("{0:.1f}".format(currentSecond - delayVideoToData))
         if (self.sliderWasReleased):
            self.sliderVideoFrame.setValue(int(self.frameNumber/fps))

         #Convert opencv mat to QImage:
         imageQ = QtGui.QImage(frame.tostring(), frame.shape[1], frame.shape[0], QtGui.QImage.Format_RGB888)

         if (frame.shape[1] != videowidthShow or frame.shape[0] != videoheightShow):
            imageQ = imageQ.scaled(videowidthShow, videoheightShow)  #resize image to fit

         #Convert QImage to pixmap:
         pixmap = QtGui.QPixmap.fromImage(imageQ)
         #Set pixmap to label:
         #self.labelImage.setPixmap(pixmap) #old mode, cuidado porque es un thread outside the GUI, esto da problemas en pyqt
         self.signalUpdatePixmap.emit(pixmap)   #nuevo mode para evitar esos problemas
         self.updateScoreLabels()
         diftime = ((datetime.now()-prevTime).microseconds)/1000000.0
         #print (diftime)
         #print(1/fps - diftime )
         if (diftime < 1/fps):
            time.sleep (1/fps - diftime)
         else:
            time.sleep(0.01)
         app.processEvents()    #prevents app from crashing because of lack of responsiveness


问题


面经


文章

微信
公众号

扫码关注公众号