Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
labels/
raw_images/
save_image/

3 changes: 1 addition & 2 deletions classes.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
NoMask
Mask
ship
9 changes: 4 additions & 5 deletions draw_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ def draw_box_on_image(image_name, classes, colors, LABEL_FOLDER, RAW_IMAGE_FOLDE
"""
txt_path = os.path.join(LABEL_FOLDER, '%s.txt' %
(image_name)) # 本次检测结果txt路径
print(image_name)
if image_name == '.DS_Store':
return 0
print('\n',image_name)
image_path = os.path.join(RAW_IMAGE_FOLDER, '%s.jpg' %
(image_name)) # 本次原始图片jpg路径

save_file_path = os.path.join(
OUTPUT_IMAGE_FOLDER, '%s.jpg' % (image_name)) # 本次保存图片jpg路径

# flag_people_or_car_data = 0 #变量 代表类别
source_file = open(txt_path) if os.path.exists(txt_path) else []
source_file = list(open(txt_path)) if os.path.exists(txt_path) else []
image = cv2.imread(image_path)
try:
height, width, channels = image.shape
Expand All @@ -52,6 +50,7 @@ def draw_box_on_image(image_name, classes, colors, LABEL_FOLDER, RAW_IMAGE_FOLDE
return 0

box_number = 0
print(f"Source: {source_file}")
for line in source_file: # 例遍 txt文件得每一行
staff = line.split() # 对每行内容 通过以空格为分隔符对字符串进行切片
class_idx = int(staff[0])
Expand Down Expand Up @@ -102,7 +101,7 @@ def make_name_list(RAW_IMAGE_FOLDER, IMAGE_NAME_LIST_PATH):

box_total = 0
image_total = 0
for image_name in image_names: # 遍历图片名称
for image_name in image_names:
box_num = draw_box_on_image(
image_name, classes, colors, LABEL_FOLDER, RAW_IMAGE_FOLDER, OUTPUT_IMAGE_FOLDER) # 对图片画框
box_total += box_num
Expand Down