21
21
import platform
22
22
import subprocess
23
23
import sys
24
+ import traceback
25
+
24
26
import xlrd
25
27
from functools import partial
26
28
@@ -536,6 +538,8 @@ def __init__(self,
536
538
537
539
lock = action (getStr ("lockBox" ), self .lockSelectedShape ,
538
540
None , "lock" , getStr ("lockBoxDetail" ), enabled = False )
541
+ expand = action (getStr ("expandBox" ), self .expandSelectedShape ,
542
+ "Ctrl+K" , "expand" , getStr ("expandBoxDetail" ), enabled = False )
539
543
540
544
self .editButton .setDefaultAction (edit )
541
545
self .newButton .setDefaultAction (create )
@@ -598,14 +602,14 @@ def __init__(self,
598
602
fitWindow = fitWindow , fitWidth = fitWidth ,
599
603
zoomActions = zoomActions , saveLabel = saveLabel , change_cls = change_cls ,
600
604
undo = undo , undoLastPoint = undoLastPoint , open_dataset_dir = open_dataset_dir ,
601
- rotateLeft = rotateLeft , rotateRight = rotateRight , lock = lock , exportJSON = exportJSON ,
605
+ rotateLeft = rotateLeft , rotateRight = rotateRight , lock = lock , exportJSON = exportJSON ,expand = expand ,
602
606
fileMenuActions = (opendir , open_dataset_dir , saveLabel , exportJSON , resetAll , quit ),
603
607
beginner = (), advanced = (),
604
608
editMenu = (createpoly , edit , copy , delete , singleRere , cellreRec , None , undo , undoLastPoint ,
605
- None , rotateLeft , rotateRight , None , color1 , self .drawSquaresOption , lock ,
609
+ None , rotateLeft , rotateRight , None , color1 , self .drawSquaresOption , lock ,expand ,
606
610
None , change_cls ),
607
611
beginnerContext = (
608
- create , createpoly , edit , copy , delete , singleRere , cellreRec , rotateLeft , rotateRight , lock , change_cls ),
612
+ create , createpoly , edit , copy , delete , singleRere , cellreRec , rotateLeft , rotateRight , lock ,expand , change_cls ),
609
613
advancedContext = (createMode , editMode , edit , copy ,
610
614
delete , shapeLineColor , shapeFillColor ),
611
615
onLoadActive = (create , createpoly , createMode , editMode ),
@@ -1093,6 +1097,7 @@ def shapeSelectionChanged(self, selected_shapes):
1093
1097
self .actions .edit .setEnabled (n_selected == 1 )
1094
1098
self .actions .lock .setEnabled (n_selected )
1095
1099
self .actions .change_cls .setEnabled (n_selected )
1100
+ self .actions .expand .setEnabled (n_selected )
1096
1101
1097
1102
def addLabel (self , shape ):
1098
1103
shape .paintLabel = self .displayLabelOption .isChecked ()
@@ -1259,8 +1264,8 @@ def copySelectedShape(self):
1259
1264
# self.shapeSelectionChanged(True)
1260
1265
1261
1266
def move_scrollbar (self , value ):
1262
- self .labelListBar .setValue (value )
1263
- self .indexListBar .setValue (value )
1267
+ self .labelListBar .setValue (int ( value ) )
1268
+ self .indexListBar .setValue (int ( value ) )
1264
1269
1265
1270
def labelSelectionChanged (self ):
1266
1271
if self ._noSelectionSlot :
@@ -1405,9 +1410,9 @@ def _update_shape_color(self, shape):
1405
1410
shape .line_color = QColor (r , g , b )
1406
1411
shape .vertex_fill_color = QColor (r , g , b )
1407
1412
shape .hvertex_fill_color = QColor (255 , 255 , 255 )
1408
- shape .fill_color = QColor (r , g , b , 128 )
1413
+ shape .fill_color = QColor (r , g , b , 32 )
1409
1414
shape .select_line_color = QColor (255 , 255 , 255 )
1410
- shape .select_fill_color = QColor (r , g , b , 155 )
1415
+ shape .select_fill_color = QColor (r , g , b , 32 )
1411
1416
1412
1417
def _get_rgb_by_label (self , label , kie_mode ):
1413
1418
shift_auto_shape_color = 2 # use for random color
@@ -1422,17 +1427,17 @@ def _get_rgb_by_label(self, label, kie_mode):
1422
1427
def scrollRequest (self , delta , orientation ):
1423
1428
units = - delta / (8 * 15 )
1424
1429
bar = self .scrollBars [orientation ]
1425
- bar .setValue (bar .value () + bar .singleStep () * units )
1430
+ bar .setValue (int ( bar .value () + bar .singleStep () * units ) )
1426
1431
1427
1432
def setZoom (self , value ):
1428
1433
self .actions .fitWidth .setChecked (False )
1429
1434
self .actions .fitWindow .setChecked (False )
1430
1435
self .zoomMode = self .MANUAL_ZOOM
1431
- self .zoomWidget .setValue (value )
1436
+ self .zoomWidget .setValue (int ( value ) )
1432
1437
1433
1438
def addZoom (self , increment = 10 ):
1434
- self .setZoom (self .zoomWidget .value () + increment )
1435
- self .imageSlider .setValue (self .zoomWidget .value () + increment ) # set zoom slider value
1439
+ self .setZoom (int ( self .zoomWidget .value () + increment ) )
1440
+ self .imageSlider .setValue (int ( self .zoomWidget .value () + increment ) ) # set zoom slider value
1436
1441
1437
1442
def zoomRequest (self , delta ):
1438
1443
# get the current scrollbar positions
@@ -1483,8 +1488,8 @@ def zoomRequest(self, delta):
1483
1488
new_h_bar_value = h_bar .value () + move_x * d_h_bar_max
1484
1489
new_v_bar_value = v_bar .value () + move_y * d_v_bar_max
1485
1490
1486
- h_bar .setValue (new_h_bar_value )
1487
- v_bar .setValue (new_v_bar_value )
1491
+ h_bar .setValue (int ( new_h_bar_value ) )
1492
+ v_bar .setValue (int ( new_v_bar_value ) )
1488
1493
1489
1494
def setFitWindow (self , value = True ):
1490
1495
if value :
@@ -1957,10 +1962,11 @@ def deleteImg(self):
1957
1962
deleteInfo = self .deleteImgDialog ()
1958
1963
if deleteInfo == QMessageBox .Yes :
1959
1964
if platform .system () == 'Windows' :
1960
- from win32com .shell import shell , shellcon
1961
- shell .SHFileOperation ((0 , shellcon .FO_DELETE , deletePath , None ,
1962
- shellcon .FOF_SILENT | shellcon .FOF_ALLOWUNDO | shellcon .FOF_NOCONFIRMATION ,
1963
- None , None ))
1965
+ # from win32com import shell, shellcon
1966
+ # shell.SHFileOperation((0, shellcon.FO_DELETE, deletePath, None,
1967
+ # shellcon.FOF_SILENT | shellcon.FOF_ALLOWUNDO | shellcon.FOF_NOCONFIRMATION,
1968
+ # None, None))
1969
+ os .remove (deletePath )
1964
1970
# linux
1965
1971
elif platform .system () == 'Linux' :
1966
1972
cmd = 'trash ' + deletePath
@@ -2659,18 +2665,20 @@ def saveRecResult(self):
2659
2665
for key in self .fileStatedict :
2660
2666
idx = self .getImglabelidx (key )
2661
2667
try :
2662
- img = cv2 .imread ( key )
2668
+ img = cv2 .imdecode ( np . fromfile ( key , dtype = np . uint8 ), - 1 )
2663
2669
for i , label in enumerate (self .PPlabel [idx ]):
2664
2670
if label ['difficult' ]:
2665
2671
continue
2666
2672
img_crop = get_rotate_crop_image (img , np .array (label ['points' ], np .float32 ))
2667
2673
img_name = os .path .splitext (os .path .basename (idx ))[0 ] + '_crop_' + str (i ) + '.jpg'
2668
- cv2 .imwrite ( crop_img_dir + img_name , img_crop )
2674
+ cv2 .imencode ( ".jpg" , img_crop )[ 1 ]. tofile ( crop_img_dir + img_name )
2669
2675
f .write ('crop_img/' + img_name + '\t ' )
2670
2676
f .write (label ['transcription' ] + '\n ' )
2677
+ except KeyError as e :
2678
+ pass
2671
2679
except Exception as e :
2672
2680
ques_img .append (key )
2673
- print ( "Can not read image " , e )
2681
+ traceback . print_exc ( )
2674
2682
if ques_img :
2675
2683
QMessageBox .information (self ,
2676
2684
"Information" ,
@@ -2780,6 +2788,23 @@ def format_shape(s):
2780
2788
self .setDirty ()
2781
2789
self .actions .save .setEnabled (True )
2782
2790
2791
+ def expandSelectedShape (self ):
2792
+ img = cv2 .imdecode (np .fromfile (self .filePath , dtype = np .uint8 ), 1 )
2793
+ for shape in self .canvas .selectedShapes :
2794
+ box = [[int (p .x ()), int (p .y ())] for p in shape .points ]
2795
+ if len (box ) > 4 :
2796
+ box = self .gen_quad_from_poly (np .array (box ))
2797
+ assert len (box ) == 4
2798
+ box = boxPad (box , img .shape , 3 )
2799
+ shape .points = [QPointF (box [0 ][0 ], box [0 ][1 ]),
2800
+ QPointF (box [1 ][0 ], box [1 ][1 ]),
2801
+ QPointF (box [2 ][0 ], box [2 ][1 ]),
2802
+ QPointF (box [3 ][0 ], box [3 ][1 ])]
2803
+ print (shape .points )
2804
+ self .updateBoxlist ()
2805
+ self .setDirty ()
2806
+
2807
+
2783
2808
2784
2809
def inverted (color ):
2785
2810
return QColor (* [255 - v for v in color .getRgb ()])
0 commit comments