bounds = reader.readtext(np.array(images[0]), min_size=0, slope_ths=0.2, ycenter_ths=0.7, height_ths=0.6, width_ths=0.8,decoder='beamsearch', beamWidth=10)
print(bounds)
Output is:
([[768, 1314], [802, 1314], [802, 1342], [768, 1342]],
'20',
0.5509253740310669),
([[320, 1316], [486, 1316], [486, 1346], [320, 1346]],
'CABC (SCB4)',
0.38597309589385986),
([[318, 1340], [559, 1340], [559, 1376], [318, 1376]],
'2Y05008-3322G001',
0.1479869782924652),
([[1278, 1728], [1431, 1728], [1431, 1760], [1278, 1760]],
'1V1?134,540']])
#######
print(bounds[0][1]) gives output 20
I'm trying to remove the text which length is less than equal to 4.
The expected output must be:
([[320, 1316], [486, 1316], [486, 1346], [320, 1346]],
'CABC (SCB4)',
0.38597309589385986),
([[318, 1340], [559, 1340], [559, 1376], [318, 1376]],
'2Y05008-3322G001',
0.1479869782924652),
([[1278, 1728], [1431, 1728], [1431, 1760], [1278, 1760]],
'1V1?134,540']])
You can get it done with list comprehension.
answer = tuple([x for x in bounds if len(bounds[bounds.index(x)][1]) > 4])
print(answer)
With the code above, I'm creating a new tuple that excludes all item whose length of element[i][0] is less than 4.
Output
(([[320, 1316], [486, 1316], [486, 1346], [320, 1346]], 'CABC (SCB4)', 0.38597309589385986), ([[318, 1340], [559, 1340], [559, 1376], [318, 1376]], '2Y05008-3322G001', 0.1479869782924652), ([[1278, 1728], [1431, 1728], [1431, 1760], [1278, 1760]], '1V1?134,540'))