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)产出如下:
([[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我试图删除长度小于4的文本。
预期产出必须是:
([[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']])发布于 2020-12-01 08:49:20
你可以通过理解列表来完成它。
answer = tuple([x for x in bounds if len(bounds[bounds.index(x)][1]) > 4])
print(answer)使用上面的代码,我创建了一个新的元组,它排除了所有元素长度小于4的项。
输出
(([[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'))https://stackoverflow.com/questions/65086561
复制相似问题