import os
import shutil
import cv2
from tqdm import tqdm
def calculate(image_dir,label_dir):
small_10_count = 0
small_10_32_count = 0
other_object_count = 0
label_file_list = os.listdir(label_dir)
for label_file in tqdm(label_file_list):
image_path = os.path.join(image_dir,label_file.replace("txt","jpg"))
label_path = os.path.join(label_dir,label_file)
if not os.path.exists(image_path):
continue
image = cv2.imread(image_path)
image_w,image_h = image.shape[1],image.shape[0]
with open(label_path,"r",encoding='utf-8') as f:
labels = f.readlines()
for label in labels:
items = label.split(" ")
if items[0] == '0':
if (float(items[2]) * image_w < 10) or (float(items[3]) * image_h < 10):
small_10_count +=1
elif (float(items[2]) * image_w < 32.0) or (float(items[3]) * image_h < 32.0):
small_10_32_count +=1
else:
other_object_count +=1
return small_10_count,small_10_32_count,other_object_count
if __name__ == "__main__":
image_dir = ''
label_dir = ''
small_10_counts,small_10_32_count,other_counts = calculate(image_dir,label_dir)
print(small_10_counts,small_10_32_count,other_counts)