1
Good Afternoon,
I am currently creating an interface, for an application, but I have a problem, with the function I created.
def contornos(self):
    self.im = cv2.imread(self.imagem)
    im_copia = self.im.copy()
    imagem_cinza = cv2.cvtColor(im_copia, cv2.COLOR_BGR2GRAY) # Transforma a imagem em tons de cinza
    _,thresh = cv2.threshold(imagem_cinza,self.minThresh,255,cv2.THRESH_TOZERO_INV) # Limiarização
    res = cv2.bitwise_and(im_copia,im_copia,mask = thresh)
    res_cinza = cv2.cvtColor(res, cv2.COLOR_BGR2GRAY)
    _,thresht = cv2.threshold(res_cinza,0,255,cv2.THRESH_BINARY|cv2.THRESH_OTSU)
    _, self.contorno, _= cv2.findContours(thresht, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) 
    cv2.drawContours(im_copia,self.contorno,-1,(255,255,255),3)
    (self.contorno, _) = contours.sort_contours(self.contorno)    
    plt.imshow(cv2.cvtColor(im_copia, cv2.COLOR_BGR2RGB))
    plt.show()
When I call this from the main program, the interface is locked and not responsive.
self.threshold_slice.valueChanged.connect(self.segmenta_foto)
this is the method the widget activates:
def segmenta_foto(self):
    if self.diretorio_imagem.text() == '':
        self.msg = QtGui.QMessageBox()
        self.msg.setIcon(QtGui.QMessageBox.Critical)
        self.msg.setText("Erro: Não há imagem selecionada")
        self.msg.setInformativeText("Favor inserir uma imagem apertando o botão de OK")
        self.msg.setWindowTitle("Erro - 01")
        retval = self.msg.exec_()
    else:
        valor = self.threshold_slice.value()
        self.threshold_indicador.setText(str(valor))
        imagem = Tratamento_imagem(self.diretorio_imagem.text(),int(valor))
        imagem.contornos()
Is there any way to improve this code, so that it gets faster? sorry for any wrong term, I program in python a short time.