当前位置:网站首页>[logodetection data set processing] (2) draw the label box of the training set picture
[logodetection data set processing] (2) draw the label box of the training set picture
2022-06-10 14:22:00 【ctrl A_ ctrl C_ ctrl V】
Data set introduction reference :【LogoDetection Dataset processing 】(1) The data set is divided into training set and verification set
To view the training set annotation , We need to draw the callout box of the training set picture . The code is as follows :
""" Draw the callout box of the training set picture """""
import os
import json
import cv2
import numpy as np
from tqdm import tqdm
# _COLORS Yes 70 Elements , If the number of categories is greater than 70, be _COLORS Need to increase the
_COLORS = np.array(
[
0.000, 0.447, 0.741,
0.850, 0.325, 0.098,
0.929, 0.694, 0.125,
0.494, 0.184, 0.556,
0.466, 0.674, 0.188,
0.301, 0.745, 0.933,
0.635, 0.078, 0.184,
0.300, 0.300, 0.300,
0.600, 0.600, 0.600,
1.000, 0.000, 0.000,
1.000, 0.500, 0.000,
0.749, 0.749, 0.000,
0.000, 1.000, 0.000,
0.000, 0.000, 1.000,
0.667, 0.000, 1.000,
0.333, 0.333, 0.000,
0.333, 0.667, 0.000,
0.333, 1.000, 0.000,
0.667, 0.333, 0.000,
0.667, 0.667, 0.000,
0.667, 1.000, 0.000,
1.000, 0.333, 0.000,
1.000, 0.667, 0.000,
1.000, 1.000, 0.000,
0.000, 0.333, 0.500,
0.000, 0.667, 0.500,
0.000, 1.000, 0.500,
0.333, 0.000, 0.500,
0.333, 0.333, 0.500,
0.333, 0.667, 0.500,
0.333, 1.000, 0.500,
0.667, 0.000, 0.500,
0.667, 0.333, 0.500,
0.667, 0.667, 0.500,
0.667, 1.000, 0.500,
1.000, 0.000, 0.500,
1.000, 0.333, 0.500,
1.000, 0.667, 0.500,
1.000, 1.000, 0.500,
0.000, 0.333, 1.000,
0.000, 0.667, 1.000,
0.000, 1.000, 1.000,
0.333, 0.000, 1.000,
0.333, 0.333, 1.000,
0.333, 0.667, 1.000,
0.333, 1.000, 1.000,
0.667, 0.000, 1.000,
0.667, 0.333, 1.000,
0.667, 0.667, 1.000,
0.667, 1.000, 1.000,
1.000, 0.000, 1.000,
1.000, 0.333, 1.000,
1.000, 0.667, 1.000,
0.333, 0.000, 0.000,
0.500, 0.000, 0.000,
0.667, 0.000, 0.000,
0.833, 0.000, 0.000,
1.000, 0.000, 0.000,
0.000, 0.167, 0.000,
0.000, 0.333, 0.000,
0.000, 0.500, 0.000,
0.000, 0.667, 0.000,
0.000, 0.833, 0.000,
0.000, 1.000, 0.000,
0.000, 0.000, 0.167,
0.000, 0.000, 0.333,
0.000, 0.000, 0.500,
0.000, 0.000, 0.667,
0.000, 0.000, 0.833,
0.000, 0.000, 1.000,
0.000, 0.000, 0.000,
0.143, 0.143, 0.143,
0.286, 0.286, 0.286,
0.429, 0.429, 0.429,
0.571, 0.571, 0.571,
0.714, 0.714, 0.714,
0.857, 0.857, 0.857,
0.000, 0.447, 0.741,
0.314, 0.717, 0.741,
0.50, 0.5, 0
]
).astype(np.float32).reshape(-1, 3)
# Mark... On the training set picture bbox
def visual(img_path, bbox, cls_id, class_names):
img = cv2.imread(img_path)
color = (_COLORS[cls_id] * 255).astype(np.uint8).tolist()
text = '{}'.format(class_names[cls_id - 1])
txt_color = (0, 0, 0) if np.mean(_COLORS[cls_id]) > 0.5 else (255, 255, 255)
font = cv2.FONT_HERSHEY_SIMPLEX
txt_size = cv2.getTextSize(text, font, 0.4, 1)[0]
txt_bk_color = (_COLORS[cls_id] * 255 * 0.7).astype(np.uint8).tolist()
x_min = bbox[0]
y_min = bbox[1]
width = bbox[2]
height = bbox[3]
cv2.rectangle(img, (x_min, y_min), (x_min + width, y_min + height), color, thickness=2)
cv2.rectangle(img, (x_min, y_min - int(1.5 * txt_size[1])), (x_min + txt_size[0] + 1, y_min), txt_bk_color, -1)
cv2.putText(img, text, (x_min, y_min - 3), font, 0.4, txt_color, thickness=1)
cv2.imwrite(img_path, img)
if __name__=='__main__':
# Raw data path
data_path = "dataset/fewshotlogodetection_round1_train_202204/train"
annoations_path = os.path.join(data_path, "annotations/instances_train2017.json")
images_path = os.path.join(data_path, "images")
# Read annoations Of json file
with open(annoations_path, 'r', encoding='utf-8') as f:
annoations_dict = json.load(f)
images_list = annoations_dict["images"]
annotations_list = annoations_dict["annotations"]
categories_list = annoations_dict["categories"]
# visualization
images_name = os.listdir(images_path)
for image_name in tqdm(images_name,desc="visual process"):
image_path=os.path.join(images_path,image_name)
for i in range(len(images_list)):
pic_file_name = os.path.basename(image_path)
if pic_file_name == images_list[i]["file_name"]:
image_id = images_list[i]["id"]
for j in range(len(annotations_list)):
if image_id == annotations_list[j]["image_id"]:
bbox = annotations_list[j]["bbox"]
cls_id = annotations_list[j]["category_id"]
visual(image_path, bbox, cls_id, categories_list)
Take a look at the visualization results :

边栏推荐
- [note] the environment for setting up get injectedthread script supplemented by shellcode in Windows Security III and its use
- Simulated 100 questions and online simulated examination for safety production management personnel of hazardous chemical production units in 2022
- How to build Haojing technology when the computing power network is brought into reality?
- P3379 [template] nearest common ancestor (LCA)
- 2022 Shandong Province safety officer C certificate retraining question bank and online simulation examination
- 【离散数学期复习系列】四、图
- C#多线程学习笔记三
- What is CAS and ABA in CAS
- C multithreading learning note 3
- 大厂面试上午10:00面试,10:09就出来了 ,问的实在是太...
猜你喜欢

Microsoft Word 教程,如何在 Word 中更改页边距、创建新闻稿栏?

【原创】POI 5.x XSSF和HSSF使用自定义字体颜色

Flutter Listview, Column, Row学习个人总结2

技术分享| 快对讲,全球对讲

【解决】每次加载已经训练好的模型,生成的向量会有不同
![[original] poi 5 X xssf and HSSF use custom font colors](/img/fc/0d983205784f3c3118bf4d2a73f842.png)
[original] poi 5 X xssf and HSSF use custom font colors
![[discrete mathematics review series] VI. tree](/img/ec/2755c9328a04483080789b366f2d96.png)
[discrete mathematics review series] VI. tree

C multithreading learning note 2

【LogoDetection 数据集处理】(3)将训练集按照类别划分为多个文件夹

Still saying that university rankings are a joke? The latest regulation: Top50 universities in the world can be directly settled in Shanghai!
随机推荐
Basic concept of data warehouse
【LogoDetection 数据集处理】(1)将数据集切分为训练集和验证集
Do you understand all these difficult memory problems?
Leetcode 2293. Minimax game (yes. One pass)
[notes] notes on C language array pointer, structure + two-dimensional array pointer
C#多线程学习笔记二
【LogoDetection 数据集处理】(3)将训练集按照类别划分为多个文件夹
微信小程序 返回上一页并传参
Cell asynchronously invokes method change records
微信小程序 日期比较,计算天数
Leetcode 2293. 极大极小游戏(可以.一次过)
什么是CAS 以及 CAS 中的 ABA 问题
[discrete mathematics review series] VI. tree
NC | Wang Jun / song Mozhi combined with third-generation sequencing to analyze the structural variation and function of intestinal flora
Main features of IIC bus / communication process / read / write process
还在说大学排名是笑话?最新规定:世界top50大学可以直接落户上海!
Review summary of final examination of software architecture principles, methods and practices, Second Edition
CVPR 2022 Oral | SCI:实现快速、灵活与稳健的低光照图像增强
一次主从表集成流程开发过程
博主自白