Esempio n. 1
0
    def newSet(self, prev=False):
        for text in self.texts:
            text.setPixmap(None)
        if prev:
            self.image, self.trimaps, self.final, self.imgName = self.imageList.previous(
            )
            if len(self.trimaps) == 1:
                self.trimap = self.trimaps[0]
                self.saveStatus = 1
            else:
                self.trimap = self.openSelectDialog(self.image, self.trimaps,
                                                    self.imgName)
                self.saveStatus = 0
        else:
            try:
                self.image, self.trimaps, self.final, self.imgName = self.imageList(
                )
            except:
                return None
            if len(self.trimaps) == 1:
                self.trimap = self.trimaps[0]
                self.saveStatus = 1
            else:
                self.trimap = self.openSelectDialog(self.image, self.trimaps,
                                                    self.imgName)
                self.saveStatus = 0

        if len(self.trimap.shape) == 2:
            self.trimap = np.stack([self.trimap] * 3, axis=2)
        assert self.image.shape == self.trimap.shape

        h, w = self.image.shape[:2]
        imgw, imgh = self.scale
        self.f = min(imgw / w, imgh / h)

        self.rawSize = (w, h)
        self.rawImage = self.image
        self.background = config.getBackground((h, w), self.bgid)
        self.image = cv2.resize(self.image, None, fx=self.f, fy=self.f)
        self.trimap = cv2.resize(self.trimap,
                                 None,
                                 fx=self.f,
                                 fy=self.f,
                                 interpolation=cv2.INTER_NEAREST)

        self.history = []
        self.alphaHistory = []
        self.outputs = []

        self.run()

        self.setSet()
        self.setFinal()
        self.getGradient()
        self.setWindowTitle(self.imgName)

        QApplication.processEvents()
Esempio n. 2
0
    def newSet(self, prev=False):
        for text in self.texts:
            text.setPixmap(None)
        if prev:
            self.image, self.trimaps, self.final, self.imgName, self.cnt, self.len = self.imageList.previous(
            )
            if len(self.trimaps) == 1:
                self.trimap = self.trimaps[0]
            else:
                self.trimap = self.openSelectDialog(self.image, self.trimaps,
                                                    self.imgName)
        else:
            self.image, self.trimaps, self.final, self.imgName, self.cnt, self.len = self.imageList(
            )
            if len(self.trimaps) == 1:
                self.trimap = self.trimaps[0]
            else:
                self.trimap = self.openSelectDialog(self.image, self.trimaps,
                                                    self.imgName)
        if len(self.trimap.shape) == 2:
            self.trimap = np.stack([self.trimap] * 3, axis=2)
        try:
            assert self.image.shape == self.trimap.shape
        except:
            return

        h, w = self.image.shape[:2]
        if h <= 400 and w <= 400:
            imgw, imgh = (w, h)
        else:
            imgw, imgh = self.scale
        self.f = min(imgw / w, imgh / h)
        self.rawSize = (w, h)
        self.rawImage = self.image
        self.background = config.getBackground((h, w), self.bgid)
        self.image = cv2.resize(self.image, None, fx=self.f, fy=self.f)
        self.trimap = cv2.resize(self.trimap,
                                 None,
                                 fx=self.f,
                                 fy=self.f,
                                 interpolation=cv2.INTER_NEAREST)

        self.history = []
        self.alphaHistory = []
        self.outputs = []

        # self.run()
        self.setSet()
        self.pageLabel.setText('%s/%s' % (int(self.cnt) + 1, self.len))
        QApplication.processEvents()
        self.setFinal()
        self.getGradient()
        self.setWindowTitle(self.imgName.split('/')[-1])
        if self.selectDialog.selectId == 5:
            self.newSet()
            self.selectDialog.selectId = 0
Esempio n. 3
0
    def newSet(self, prev=False):
        for text in self.texts:
            text.setPixmap(None)
        if prev:
            self.image, self.trimap, self.final = self.imageList.previous()
        else:
            self.image, self.trimap, self.final = self.imageList()

        if len(self.trimap.shape) == 2:
            self.trimap = np.stack([self.trimap] * 3, axis=2)
        assert self.image.shape == self.trimap.shape

        h, w = self.image.shape[:2]
        imgw, imgh = self.scale
        self.f = min(imgw / w, imgh / h)

        # self.splitArrX = [self.image.shape[0]]
        # self.splitArrY = [self.image.shape[1]]
        # self.resultTool.setArr(self.splitArrX, self.splitArrY)
        # for i in range(config.defaultSplit):
        #     self.splitUp()

        self.rawSize = (w, h)
        self.rawImage = self.image
        self.background = config.getBackground((h, w), self.bgid)
        self.image = cv2.resize(self.image, None, fx=self.f, fy=self.f)
        self.trimap = cv2.resize(self.trimap,
                                 None,
                                 fx=self.f,
                                 fy=self.f,
                                 interpolation=cv2.INTER_NEAREST)

        self.history = []
        self.alphaHistory = []
        self.outputs = []

        self.run()

        self.setSet()
        self.setFinal()
        self.getGradient()
Esempio n. 4
0
    def __init__(self, widget, image, imageResult):
        super(SelectDialog, self).__init__()
        self.widget = widget
        self.image = image.copy()
        self.candidateResults = imageResult
        labelW = 200  #控制图片大小
        h, w = self.image.shape[:2]
        if w > labelW:
            ratio = float(labelW) / float(w)
        else:
            labelW = w
            ratio = 1
        labelH = int(h * ratio)
        self.image = cv2.resize(self.image, (labelW, labelH),
                                cv2.INTER_NEAREST)
        for i in range(len(self.candidateResults)):
            self.candidateResults[i] = cv2.resize(self.candidateResults[i],
                                                  (labelW, labelH))
        # self.resize(labelW * 3 + 150, 800)
        #设置图片宽高结束
        # self.selectTrue = False
        self.Vlayout = QVBoxLayout()  #整体布局
        self.Vlayout.setAlignment(Qt.AlignCenter)
        image_label = QLabel()
        image_label.setFixedSize(QSize(labelW, labelH))
        image_label.setPixmap(numpytoPixmap(self.image))
        size = self.image.shape[:2]
        self.firstImageLayout = QHBoxLayout()  #原图的布局
        self.firstImageLayout.addWidget(image_label)
        self.Vlayout.addLayout(self.firstImageLayout)  #插入原图布局
        self.buttonGroup = QButtonGroup()
        id = 0
        self.resultLayout = QHBoxLayout()  #四个结果图的布局
        self.selectAlphas = []
        for i, alpha in enumerate(self.candidateResults):
            bg = config.getBackground(size, 2)
            b, g, r, a = cv2.split(alpha)
            bgr = np.stack([b, g, r], axis=2)
            a = np.stack([a] * 3, axis=2) / 255.0
            alpha = self.changeBackground(bgr, a, bg)
            self.selectAlphas.append([bgr, a])
            final_label = BtnLabel(self, i)  # 自动以Label类
            final_label.setFixedSize(QSize(labelW, labelH))
            final_label.setPixmap(numpytoPixmap(alpha))
            final_label.setCursor(QCursor(Qt.PointingHandCursor))
            radioButton = QRadioButton(str(id))  # 创建单选按钮
            self.buttonGroup.addButton(radioButton, id)
            id += 1
            self.Hlayout = QVBoxLayout()  # 一张图和一个radio的布局
            self.Hlayout.addWidget(final_label)
            self.Hlayout.addWidget(radioButton)
            self.resultLayout.addLayout(self.Hlayout)

        self.Vlayout.addLayout(self.resultLayout)  # 插入四个结果布局

        self.abandonlayout = QHBoxLayout()  #放弃按钮布局
        abandonButton = BtnLabel(self, 5)
        abandonButton.setText('放弃')
        abandonButton.setAlignment(Qt.AlignCenter)
        abandonButton.setFixedWidth(200)
        abandonButton.setStyleSheet(
            "QLabel{color:rgb(255,255,255);font-size:18px;}"
            "QLabel{width:200}"
            "QLabel:hover{background-color:#871926}"
            "QLabel{background-color:#871926;}"
            "QLabel{border:2px}"
            "QLabel{border-radius:4px}"
            "QLabel{padding:5px 4px}")
        # abandonButton.clicked.connect(self.abandonClick)
        self.abandonlayout.addWidget(abandonButton)
        self.Vlayout.addLayout(self.abandonlayout)

        self.setLayout(self.Vlayout)

        self.buttonGroup.button(0).setChecked(True)
Esempio n. 5
0
 def changeBG(self, bgid):
     # self.bgid += 1
     self.bgid = bgid
     self.background = config.getBackground(self.rawSize[::-1], self.bgid)
     self.setFinal()
Esempio n. 6
0
 def changeBG(self, bgid):
     # self.bgid += 1
     self.bgid = bgid
     self.background = config.getBackground(self.rawSize[::-1], self.bgid)
     QApplication.processEvents()
     self.setFinal()