我正在尝试从给定的输入中删除长度小于等于 4 的文本。我正在使用 EasyOcr

I'm trying to remove the text which is length less than equal to 4 from the input given. I'm using EasyOcr

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']])

你可以通过列表理解来完成它。

answer = tuple([x for x in bounds if len(bounds[bounds.index(x)][1]) > 4])
print(answer)

使用上面的代码,我创建了一个新的元组,它排除了元素 [i][0] 的长度小于 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'))