欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PyQt5實(shí)現(xiàn)簡(jiǎn)單數(shù)據(jù)標(biāo)注工具

 更新時(shí)間:2019年03月18日 09:38:04   作者:York1996  
這篇文章主要為大家詳細(xì)介紹了PyQt5實(shí)現(xiàn)簡(jiǎn)單數(shù)據(jù)標(biāo)注工具,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了PyQt5實(shí)現(xiàn)簡(jiǎn)單數(shù)據(jù)標(biāo)注工具的具體代碼,分類(lèi)用,供大家參考,具體內(nèi)容如下

第一個(gè)最大的圖片是當(dāng)前要標(biāo)注的類(lèi)別,接下來(lái)的兩個(gè)圖片是對(duì)接下來(lái)會(huì)出現(xiàn)的圖片的預(yù)覽(方便連續(xù)點(diǎn)好幾個(gè))。分類(lèi)之后的會(huì)保存到和按鈕名字一樣的文件夾里面,如果文件夾不存在就會(huì)自動(dòng)新建一個(gè)(makedirs)。如果中斷了標(biāo)注,可以修改代碼中的self.idx屬性,從某個(gè)位置開(kāi)始。

視頻效果:地址鏈接

接下來(lái)是代碼:

from PyQt5.QtWidgets import QApplication,QPushButton,QLabel,QMainWindow
from PyQt5.QtGui import QFont,QPixmap
import sys,os
import shutil
 
def copyfile(srcfile, dstfile):#用來(lái)復(fù)制文件,源文件會(huì)保留
 
  if not os.path.isfile(srcfile):
    print("%s not exist!" % srcfile)
  else:
    f_path, f_name = os.path.split(dstfile) # 分離文件名和路徑
    if not os.path.exists(f_path):
      os.makedirs(f_path) # 創(chuàng)建路徑
    shutil.copyfile(srcfile, dstfile) # 復(fù)制文件
    print("copy %s -> %s" % (srcfile, dstfile))
class mainForm(QMainWindow):
  def __init__(self):
    super(mainForm, self).__init__()
 
    self.img_path="faces/" #文件夾和py文件要再同一個(gè)目錄下面
    self.img_list=os.listdir(self.img_path) #獲取目錄下的所有文件
    self.idx=0#可以改這里,選擇程序運(yùn)行的時(shí)候第一個(gè)顯示的圖片是哪一個(gè)
 
    self.initUI()
    self.show()
  def initUI(self):
    font=QFont()
    font.setPixelSize(20)#新建一個(gè)字體控件
 
    self.setWindowTitle("label_me")#設(shè)置窗體的標(biāo)題
    self.setGeometry(0,0,900,600)#位置和大小
 
    button_list=["Chandler","Phoebe","Joey","Monica","Rachel","Ross","Others","Thing",]#這里是顯示的按鈕們,也是可能的類(lèi)別數(shù)
 
    for idx, label_name in enumerate(button_list):
 
      button=QPushButton(label_name,self)
      button.move(idx*110+20,500)
      button.setFont(font)
      button.setFixedHeight(35)
 
      button.clicked.connect(self.classify)#動(dòng)態(tài)控件綁定同一個(gè)事件,根據(jù)事件的sender判斷是哪個(gè)按鈕按下
 
    self.lbl_list=[]#存放顯示圖片的label 的list
    for i in range(self.get_remainder()):
 
      self.pix = QPixmap(self.img_path+self.img_list[self.idx+i])
      label_img = QLabel(self)
      label_img.setGeometry(360*i+10, 400-100*(3-i)+40, 100*(3-i)+40,100*(3-i)+40)
      label_img.setStyleSheet("border:2px solid red")
      label_img.setPixmap(self.pix)#設(shè)置label控件要顯示的圖片
      label_img.setScaledContents(True)
      self.lbl_list.append(label_img)
 
  def get_remainder(self):#打算是要顯示3個(gè)label圖片,如果是到了最后,顯示不了那么多了。
    r=len(self.img_list)-self.idx
    if r>3:
      r=3
    return r
  def clear_lbls(self):#最后的時(shí)候會(huì)用到,不顯示某些label
    for i in range(len(self.lbl_list)):
      self.lbl_list[i].hide()
 
  def classify(self):
 
    sender = self.sender()
    dir_path=sender.text()+"/"#獲取按鈕的text屬性
 
    current_img_path=self.img_list[self.idx]#獲取剛剛被分類(lèi)的圖片的路徑
    copyfile(self.img_path+current_img_path , dir_path+current_img_path)
    self.idx +=1#下一個(gè)圖片
    img_full_path = [self.img_path + self.img_list[self.idx + i]  for i in range(self.get_remainder())]
 
    self.clear_lbls()
    for i in range(self.get_remainder()):
 
      pix = QPixmap(img_full_path[i])
      self.lbl_list[i].setPixmap(pix)
      self.lbl_list[i].show()
    self.setWindowTitle("當(dāng)前是第 %d 個(gè)圖片"%self.idx)
 
app=QApplication(sys.argv)
f=mainForm()
sys.exit(app.exec())

如果有什么需要完善的地方,請(qǐng)?zhí)岢觥?br />

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論