labelImg.py
def loadFile(self, filePath=None):

        """Load the specified file, or the last opened file if None."""
        self.preProcessPath = self.preProcessTextLine.text()
        self.make_path_id_dictionary()
        self.make_subject_dictionary()
        self.update_embeding()
        self.w.close()
        self.resetState()
        self.canvas.setEnabled(False)
        if filePath is None:
            filePath = self.settings.get(SETTING_FILENAME)

        # Make sure that filePath is a regular python string, rather than QString
        filePath = ustr(filePath)

        # Fix bug: An  index error after select a directory when open a new file.
        unicodeFilePath = ustr(filePath)
        unicodeFilePath = os.path.abspath(unicodeFilePath)
        # Tzutalin 20160906 : Add file list and dock to move faster
        # Highlight the file item
        if unicodeFilePath and self.fileListWidget.count() > 0:
            if unicodeFilePath in self.mImgList:
                index = self.mImgList.index(unicodeFilePath)
                fileWidgetItem = self.fileListWidget.item(index)
                fileWidgetItem.setSelected(True)
            else:
                self.fileListWidget.clear()
                self.mImgList.clear()

        if unicodeFilePath and os.path.exists(unicodeFilePath):
            if LabelFile.isLabelFile(unicodeFilePath):
                try:
                    self.labelFile = LabelFile(unicodeFilePath)
                except LabelFileError as e:
                    self.errorMessage(u'Error opening file',
                                      (u"<p><b>%s</b></p>"
                                       u"<p>Make sure <i>%s</i> is a valid label file.")
                                      % (e, unicodeFilePath))
                    self.status("Error reading %s" % unicodeFilePath)
                    return False
                self.imageData = self.labelFile.imageData
                self.lineColor = QColor(*self.labelFile.lineColor)
                self.fillColor = QColor(*self.labelFile.fillColor)
                self.canvas.verified = self.labelFile.verified
            else:
                # Load image:
                # read data first and store for saving into label file.
                self.imageData = read(unicodeFilePath, None)
                self.labelFile = None
                self.canvas.verified = False

            if isinstance(self.imageData, QImage):
                image = self.imageData
            else:
                image = QImage.fromData(self.imageData)
            if image.isNull():
                self.errorMessage(u'Error opening file',
                                  u"<p>Make sure <i>%s</i> is a valid image file." % unicodeFilePath)
                self.status("Error reading %s" % unicodeFilePath)
                return False
            self.status("Loaded %s" % os.path.basename(unicodeFilePath))
            self.image = image
            self.filePath = unicodeFilePath
            self.canvas.loadPixmap(QPixmap.fromImage(image))
            if self.labelFile:
                self.loadLabels(self.labelFile.shapes)
            self.setClean()
            self.canvas.setEnabled(True)
            self.adjustScale(initial=True)
            self.paintCanvas()
            self.addRecentFile(self.filePath)
            self.toggleActions(True)
            self.showBoundingBoxFromAnnotationFile(self.filePath)

            self.setWindowTitle(__appname__ + ' ' + filePath)

            # Default : select last item if there is at least one item
            if self.labelList.count():
                self.labelList.setCurrentItem(self.labelList.item(self.labelList.count() - 1))
                self.labelList.item(self.labelList.count() - 1).setSelected(True)

            self.canvas.setFocus(True)
            if self.recommenderMode.isChecked() and not self.saved_label_exist:
                try:
                    self.box_recommender.detect(image_path=self.filePath)
                    self.drawPoints(self.box_recommender.points)
                except:
                    print("there isn't any recommended box or there is something wrong with the image")
            self.saved_label_exist = False
            return True
        return False
Load the specified file, or the last opened file if None.
Load the specified file, or the last opened file if None.
Load the specified file or the last opened file if None .
def loadFile(self, filePath=None):
        self.preProcessPath = self.preProcessTextLine.text()
        self.make_path_id_dictionary()
        self.make_subject_dictionary()
        self.update_embeding()
        self.w.close()
        self.resetState()
        self.canvas.setEnabled(False)
        if filePath is None:
            filePath = self.settings.get(SETTING_FILENAME)
        filePath = ustr(filePath)
        unicodeFilePath = ustr(filePath)
        unicodeFilePath = os.path.abspath(unicodeFilePath)
        if unicodeFilePath and self.fileListWidget.count() > 0:
            if unicodeFilePath in self.mImgList:
                index = self.mImgList.index(unicodeFilePath)
                fileWidgetItem = self.fileListWidget.item(index)
                fileWidgetItem.setSelected(True)
            else:
                self.fileListWidget.clear()
                self.mImgList.clear()
        if unicodeFilePath and os.path.exists(unicodeFilePath):
            if LabelFile.isLabelFile(unicodeFilePath):
                try:
                    self.labelFile = LabelFile(unicodeFilePath)
                except LabelFileError as e:
                    self.errorMessage(u'Error opening file',
                                      (u"<p><b>%s</b></p>"
                                       u"<p>Make sure <i>%s</i> is a valid label file.")
                                      % (e, unicodeFilePath))
                    self.status("Error reading %s" % unicodeFilePath)
                    return False
                self.imageData = self.labelFile.imageData
                self.lineColor = QColor(*self.labelFile.lineColor)
                self.fillColor = QColor(*self.labelFile.fillColor)
                self.canvas.verified = self.labelFile.verified
            else:
                self.imageData = read(unicodeFilePath, None)
                self.labelFile = None
                self.canvas.verified = False
            if isinstance(self.imageData, QImage):
                image = self.imageData
            else:
                image = QImage.fromData(self.imageData)
            if image.isNull():
                self.errorMessage(u'Error opening file',
                                  u"<p>Make sure <i>%s</i> is a valid image file." % unicodeFilePath)
                self.status("Error reading %s" % unicodeFilePath)
                return False
            self.status("Loaded %s" % os.path.basename(unicodeFilePath))
            self.image = image
            self.filePath = unicodeFilePath
            self.canvas.loadPixmap(QPixmap.fromImage(image))
            if self.labelFile:
                self.loadLabels(self.labelFile.shapes)
            self.setClean()
            self.canvas.setEnabled(True)
            self.adjustScale(initial=True)
            self.paintCanvas()
            self.addRecentFile(self.filePath)
            self.toggleActions(True)
            self.showBoundingBoxFromAnnotationFile(self.filePath)
            self.setWindowTitle(__appname__ + ' ' + filePath)
            if self.labelList.count():
                self.labelList.setCurrentItem(self.labelList.item(self.labelList.count() - 1))
                self.labelList.item(self.labelList.count() - 1).setSelected(True)
            self.canvas.setFocus(True)
            if self.recommenderMode.isChecked() and not self.saved_label_exist:
                try:
                    self.box_recommender.detect(image_path=self.filePath)
                    self.drawPoints(self.box_recommender.points)
                except:
                    print("there isn't any recommended box or there is something wrong with the image")
            self.saved_label_exist = False
            return True
        return False
def loadFile ( self , filePath = None ) : self . preProcessPath = self . preProcessTextLine . text ( ) self . make_path_id_dictionary ( ) self . make_subject_dictionary ( ) self . update_embeding ( ) self . w . close ( ) self . resetState ( ) self . canvas . setEnabled ( False ) if filePath is None : filePath = self . settings . get ( SETTING_FILENAME ) filePath = ustr ( filePath ) unicodeFilePath = ustr ( filePath ) unicodeFilePath = os . path . abspath ( unicodeFilePath ) if unicodeFilePath and self . fileListWidget . count ( ) > 0 : if unicodeFilePath in self . mImgList : index = self . mImgList . index ( unicodeFilePath ) fileWidgetItem = self . fileListWidget . item ( index ) fileWidgetItem . setSelected ( True ) else : self . fileListWidget . clear ( ) self . mImgList . clear ( ) if unicodeFilePath and os . path . exists ( unicodeFilePath ) : if LabelFile . isLabelFile ( unicodeFilePath ) : try : self . labelFile = LabelFile ( unicodeFilePath ) except LabelFileError as e : self . errorMessage ( u'Error opening file' , ( u"<p><b>%s</b></p>" u"<p>Make sure <i>%s</i> is a valid label file." ) % ( e , unicodeFilePath ) ) self . status ( "Error reading %s" % unicodeFilePath ) return False self . imageData = self . labelFile . imageData self . lineColor = QColor ( * self . labelFile . lineColor ) self . fillColor = QColor ( * self . labelFile . fillColor ) self . canvas . verified = self . labelFile . verified else : self . imageData = read ( unicodeFilePath , None ) self . labelFile = None self . canvas . verified = False if isinstance ( self . imageData , QImage ) : image = self . imageData else : image = QImage . fromData ( self . imageData ) if image . isNull ( ) : self . errorMessage ( u'Error opening file' , u"<p>Make sure <i>%s</i> is a valid image file." % unicodeFilePath ) self . status ( "Error reading %s" % unicodeFilePath ) return False self . status ( "Loaded %s" % os . path . basename ( unicodeFilePath ) ) self . image = image self . filePath = unicodeFilePath self . canvas . loadPixmap ( QPixmap . fromImage ( image ) ) if self . labelFile : self . loadLabels ( self . labelFile . shapes ) self . setClean ( ) self . canvas . setEnabled ( True ) self . adjustScale ( initial = True ) self . paintCanvas ( ) self . addRecentFile ( self . filePath ) self . toggleActions ( True ) self . showBoundingBoxFromAnnotationFile ( self . filePath ) self . setWindowTitle ( __appname__ + ' ' + filePath ) if self . labelList . count ( ) : self . labelList . setCurrentItem ( self . labelList . item ( self . labelList . count ( ) - 1 ) ) self . labelList . item ( self . labelList . count ( ) - 1 ) . setSelected ( True ) self . canvas . setFocus ( True ) if self . recommenderMode . isChecked ( ) and not self . saved_label_exist : try : self . box_recommender . detect ( image_path = self . filePath ) self . drawPoints ( self . box_recommender . points ) except : print ( "there isn't any recommended box or there is something wrong with the image" ) self . saved_label_exist = False return True return False
Load the specified file, or the last opened file if None.
Load the specified file or the last opened file if None .
"""Load the specified file, or the last opened file if None.""" # Make sure that filePath is a regular python string, rather than QString # Fix bug: An  index error after select a directory when open a new file. # Tzutalin 20160906 : Add file list and dock to move faster # Highlight the file item # Load image: # read data first and store for saving into label file. # Default : select last item if there is at least one item
self
filePath