Skip to content

Instantly share code, notes, and snippets.

@delagreen-v2
Last active May 28, 2024 13:22
Show Gist options
  • Select an option

  • Save delagreen-v2/931cc5384faa0be55a4f68a396851a61 to your computer and use it in GitHub Desktop.

Select an option

Save delagreen-v2/931cc5384faa0be55a4f68a396851a61 to your computer and use it in GitHub Desktop.
delete_empty_boxes
import os
import icecream
path = '/home/astraadmin/Desktop/rep/drawing_text_recognition/new/tesseract-tutorial/tesstrain/data/OKBM_NX-ground-truth'
def delete_empty_boxes(path):
for i, file_name in enumerate(os.listdir(path)):
if (i+1)%3==0:
full_path_box = path + '/' + file_name
#print(file_name)
if (os.stat(full_path_box).st_size == 0):
os.remove(full_path_box)
print(f'removed{full_path_box}')
full_path_gttxt = path + '/' + file_name.split('.')[0] + '.gt.txt'
full_path_tif = path + '/' + file_name.split('.')[0] + '.tif'
if os.path.exists(full_path_gttxt):
os.remove(full_path_gttxt)
print(f'removed{full_path_gttxt}')
if os.path.exists(full_path_tif):
os.remove(full_path_tif)
print(f'removed{full_path_tif}')
#delete_empty_boxes(path)
def delete_files(path):
list_files = os.listdir(path)#[10000:]
#list_files.sort()
icecream.ic(list_files)
for i, file_name in enumerate(list_files):
full_path_box = path + '/' + file_name
full_path_gttxt = path + '/' + file_name.split('.')[0] + '.gt.txt'
full_path_tif = path + '/' + file_name.split('.')[0] + '.tif'
full_path_lstm = path + '/' + file_name.split('.')[0] + '.lstmf'
#if not os.path.exists(full_path_lstm):
if os.path.exists(full_path_box):
os.remove(full_path_box)
print(f'removed: {full_path_box}')
if os.path.exists(full_path_gttxt):
os.remove(full_path_gttxt)
print(f'removed: {full_path_gttxt}')
if os.path.exists(full_path_tif):
os.remove(full_path_tif)
print(f'removed: {full_path_tif}')
#delete_files(path)
#list_files = os.listdir(path)
#print(list_files)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment