@@ -128,13 +128,27 @@ def __init__(self, defaultFilename=None, defaultPrefdefClassFile=None, defaultSa
128128 useDefaultLabelContainer = QWidget ()
129129 useDefaultLabelContainer .setLayout (useDefaultLabelQHBoxLayout )
130130
131- # Create a widget for edit and diffc button
132- self .diffcButton = QCheckBox (getStr ('useDifficult' ))
133- self .diffcButton .setChecked (False )
134- self .diffcButton .stateChanged .connect (self .btnstate )
135131 self .editButton = QToolButton ()
136132 self .editButton .setToolButtonStyle (Qt .ToolButtonTextBesideIcon )
137133
134+ # Create Flag checkboxes list
135+ self .flagGroupBox = QGroupBox (self )
136+ self .flagGroupBox .setTitle ('Flags' )
137+ flagslayout = QVBoxLayout (self )
138+ self .flagGroupBox .setLayout (flagslayout )
139+ self .flagButtons = []
140+
141+ self .diffcButton = QCheckBox (getStr ('useDifficult' ))
142+ self .diffcButton .setChecked (False )
143+ # calling stateChanged is inappropriate!
144+ self .diffcButton .clicked .connect (self .btnstate )
145+ self .flagButtons .append (self .diffcButton )
146+
147+ self .truncButton = QCheckBox (getStr ('useTruncated' ))
148+ self .truncButton .setChecked (False )
149+ self .truncButton .clicked .connect (self .btnstate )
150+ self .flagButtons .append (self .truncButton )
151+
138152 # *
139153 # * dhzs 2017-12-2 add copy button
140154 # *
@@ -143,9 +157,13 @@ def __init__(self, defaultFilename=None, defaultPrefdefClassFile=None, defaultSa
143157 self .copy_prev_button .clicked .connect (self .copyPreviousBoundingBoxes )
144158 listLayout .addWidget (self .copy_prev_button )
145159
160+ # add flag buttons to flagsGroupBox
161+ for flagbtn in self .flagButtons :
162+ flagslayout .addWidget (flagbtn )
163+
146164 # Add some of widgets to listLayout
147165 listLayout .addWidget (self .editButton )
148- listLayout .addWidget (self .diffcButton )
166+ listLayout .addWidget (self .flagGroupBox )
149167 listLayout .addWidget (useDefaultLabelContainer )
150168
151169 # Create and add combobox for showing unique labels in group
@@ -446,8 +464,6 @@ def getFormatMeta(format):
446464 self .fillColor = None
447465 self .zoom_level = 100
448466 self .fit_window = False
449- # Add Chris
450- self .difficult = False
451467
452468 ## Fix the compatible issue for qt4 and qt5. Convert the QStringList to python list
453469 if settings .get (SETTING_RECENT_FILES ):
@@ -479,8 +495,7 @@ def getFormatMeta(format):
479495 Shape .line_color = self .lineColor = QColor (settings .get (SETTING_LINE_COLOR , DEFAULT_LINE_COLOR ))
480496 Shape .fill_color = self .fillColor = QColor (settings .get (SETTING_FILL_COLOR , DEFAULT_FILL_COLOR ))
481497 self .canvas .setDrawingColor (self .lineColor )
482- # Add chris
483- Shape .difficult = self .difficult
498+ Shape .flags = self .flags
484499
485500 def xbool (x ):
486501 if isinstance (x , QVariant ):
@@ -730,6 +745,20 @@ def fileitemDoubleClicked(self, item=None):
730745 if filename :
731746 self .loadFile (filename )
732747
748+ @property
749+ def flags (self ):
750+ """
751+ Returns
752+ -------
753+ dict
754+ key is a flag name
755+ value is a Bool
756+ """
757+ return {flagbtn .text (): flagbtn .isChecked () for flagbtn in self .flagButtons }
758+
759+ def setFlagsChecked (self , flags ):
760+ pass
761+
733762 # Add chris
734763 def btnstate (self , item = None ):
735764 """ Function to handle difficult examples
@@ -741,16 +770,15 @@ def btnstate(self, item= None):
741770 if not item : # If not selected Item, take the first one
742771 item = self .labelList .item (self .labelList .count ()- 1 )
743772
744- difficult = self .diffcButton . isChecked ()
773+ flags = self .flags
745774
746775 try :
747776 shape = self .itemsToShapes [item ]
748777 except :
749778 pass
750779 # Checked and Update
751780 try :
752- if difficult != shape .difficult :
753- shape .difficult = difficult
781+ if shape .setChangedFlags (flags ):
754782 self .setDirty ()
755783 else : # User probably changed item visibility
756784 self .canvas .setShapeVisible (shape , item .checkState () == Qt .Checked )
@@ -798,7 +826,7 @@ def remLabel(self, shape):
798826
799827 def loadLabels (self , shapes ):
800828 s = []
801- for label , points , line_color , fill_color , difficult in shapes :
829+ for label , points , line_color , fill_color , flags in shapes :
802830 shape = Shape (label = label )
803831 for x , y in points :
804832
@@ -808,7 +836,7 @@ def loadLabels(self, shapes):
808836 self .setDirty ()
809837
810838 shape .addPoint (QPointF (x , y ))
811- shape .difficult = difficult
839+ shape .flags = flags
812840 shape .close ()
813841 s .append (shape )
814842
@@ -848,11 +876,10 @@ def format_shape(s):
848876 line_color = s .line_color .getRgb (),
849877 fill_color = s .fill_color .getRgb (),
850878 points = [(p .x (), p .y ()) for p in s .points ],
851- # add chris
852- difficult = s .difficult )
879+ flags = s .flags )
853880
854881 shapes = [format_shape (shape ) for shape in self .canvas .shapes ]
855- # Can add differrent annotation formats here
882+ # Can add different annotation formats here
856883 try :
857884 if self .labelFileFormat == LabelFileFormat .PASCAL_VOC :
858885 if annotationFilePath [- 4 :].lower () != ".xml" :
@@ -899,9 +926,11 @@ def labelSelectionChanged(self):
899926 self ._noSelectionSlot = True
900927 self .canvas .selectShape (self .itemsToShapes [item ])
901928 shape = self .itemsToShapes [item ]
902- # Add Chris
903- self .diffcButton .setChecked (shape .difficult )
904-
929+ for flagbtn in self .flagButtons :
930+ if hasattr (shape , flagbtn .text ()):
931+ flagbtn .setChecked (getattr (shape , flagbtn .text ()))
932+ else :
933+ flagbtn .setChecked (False )
905934 def labelItemChanged (self , item ):
906935 shape = self .itemsToShapes [item ]
907936 label = item .text ()
@@ -932,8 +961,8 @@ def newShape(self):
932961 else :
933962 text = self .defaultLabelTextLine .text ()
934963
935- # Add Chris
936- self . diffcButton .setChecked (False )
964+ for flagbtn in self . flagButtons :
965+ flagbtn .setChecked (False )
937966 if text is not None :
938967 self .prevLabelText = text
939968 generate_color = generateColorByText (text )
@@ -1283,7 +1312,6 @@ def importDirImages(self, dirpath):
12831312 self .lastOpenDir = dirpath
12841313 self .dirname = dirpath
12851314 self .filePath = None
1286- self .fileListWidget .clear ()
12871315 self .mImgList = self .scanAllImages (dirpath )
12881316 self .openNextImg ()
12891317 for imgPath in self .mImgList :
0 commit comments