当前位置:网站首页>[logodetection dataset processing] (4) extract the logo area of each picture
[logodetection dataset processing] (4) extract the logo area of each picture
2022-06-10 14:22:00 【ctrl A_ ctrl C_ ctrl V】
Reference resources :【LogoDetection Dataset processing 】(3) Divide training sets into multiple folders by category
Previously, we have divided the training set into 50 A folder , Each folder has a category of pictures :

In many cases , We need to extract the logo Area .
Original picture :
Extracted logo Area :
From the divided 50 And the picture extraction in the folder logo Area , obtain 50 Category logo We separate 50 In folders .
The code is as follows :
""" Extract the... Of each picture logo Area . """""
import os
import json
import shutil
import cv2
from tqdm import tqdm
categories_list = [
{
"id": 1,
"name": "bingdundun"
},
{
"id": 2,
"name": "sanyo"
},
{
"id": 3,
"name": "Eifini"
},
{
"id": 4,
"name": "PSALTER"
},
{
"id": 5,
"name": "Beaster"
},
{
"id": 6,
"name": "ON"
},
{
"id": 7,
"name": "BYREDO"
},
{
"id": 8,
"name": "Ubras"
},
{
"id": 9,
"name": "Eternelle"
},
{
"id": 10,
"name": "PerfectDiary"
},
{
"id": 11,
"name": "huaxizi"
},
{
"id": 12,
"name": "Clarins"
},
{
"id": 13,
"name": "Loccitane"
},
{
"id": 14,
"name": "Versace"
},
{
"id": 15,
"name": "Mizuno"
},
{
"id": 16,
"name": "Lining"
},
{
"id": 17,
"name": "DoubleStar"
},
{
"id": 18,
"name": "YONEX"
},
{
"id": 19,
"name": "ToryBurch"
},
{
"id": 20,
"name": "Gucci"
},
{
"id": 21,
"name": "LouisVuitton"
},
{
"id": 22,
"name": "CARTELO"
},
{
"id": 23,
"name": "JORDAN"
},
{
"id": 24,
"name": "KENZO"
},
{
"id": 25,
"name": "UNDEFEATED"
},
{
"id": 26,
"name": "BoyLondon"
},
{
"id": 27,
"name": "TREYO"
},
{
"id": 28,
"name": "carhartt"
},
{
"id": 29,
"name": "jierou"
},
{
"id": 30,
"name": "Blancpain"
},
{
"id": 31,
"name": "GXG"
},
{
"id": 32,
"name": "ledin"
},
{
"id": 33,
"name": "Diadora"
},
{
"id": 34,
"name": "TUCANO"
},
{
"id": 35,
"name": "Loewe"
},
{
"id": 36,
"name": "GraniteGear"
},
{
"id": 37,
"name": "DESCENTE"
},
{
"id": 38,
"name": "OSPREY"
},
{
"id": 39,
"name": "Swatch"
},
{
"id": 40,
"name": "erke"
},
{
"id": 41,
"name": "MassimoDutti"
},
{
"id": 42,
"name": "PINKO"
},
{
"id": 43,
"name": "PALLADIUM"
},
{
"id": 44,
"name": "origins"
},
{
"id": 45,
"name": "Trendiano"
},
{
"id": 46,
"name": "yiner"
},
{
"id": 47,
"name": "MonsterGuardians"
},
{
"id": 48,
"name": "fuerjia"
},
{
"id": 49,
"name": "IPSA"
},
{
"id": 50,
"name": "Schwarzkopf"
}
]
# Classified training set paths
data_path = "TrainSet_50Classes"
annoations_path = "dataset/fewshotlogodetection_round1_train_202204/train/annotations/instances_train2017.json"
classdir_list = os.listdir(data_path)
# 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"]
# Create outermost folder
logoarea_dir = "LogoArea_50classes"
isExists_trainset_dir = os.path.exists(logoarea_dir)
if not isExists_trainset_dir:
os.mkdir(logoarea_dir)
# establish 50 Subfolders , as well as class_id A dictionary of folder names .
class_dict = {
}
for i in range(len(categories_list)):
dir_name = categories_list[i]["name"]
dir_name_path = os.path.join(logoarea_dir, dir_name)
class_dict[i + 1] = dir_name_path
isExists = os.path.exists(dir_name_path)
if isExists:
shutil.rmtree(dir_name_path)
os.makedirs(dir_name_path, exist_ok=True)
# extract logo Area
for classdir_name in tqdm(classdir_list,desc="process"):
classdir_path = os.path.join(data_path, classdir_name)
pic_list = os.listdir(classdir_path)
logo_num = 0 # Sequence number for picture naming
for pic_name in pic_list:
pic_path = os.path.join(classdir_path, pic_name)
image = cv2.imread(pic_path)
for i in range(len(images_list)):
if pic_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"]
x0, y0, w, h = bbox
logo_area = image[y0:y0 + h, x0:x0 + w] # extract logo Area
# Picture naming from 000 Start
if logo_num < 10:
save_pic_name = classdir_name + "_00" + str(logo_num) + ".jpg"
elif logo_num < 100:
save_pic_name = classdir_name + "_0" + str(logo_num) + ".jpg"
else:
save_pic_name = classdir_name + "_" + str(logo_num) + ".jpg"
save_pic_path = os.path.join(logoarea_dir, classdir_name, save_pic_name)
cv2.imwrite(save_pic_path, logo_area)
logo_num += 1
Get one LogoArea_50classes The folder is as follows :

边栏推荐
- Celery 异步调用方法改动记录
- 碰撞检测 Unity实验代码
- 2022年制冷与空调设备运行操作理论题库模拟考试平台操作
- Why should the R & D effectiveness team of Internet companies be independent? When is independence?
- 自适应功能简略
- 微信小程序 关闭当前页面
- 【离散数学期复习系列】一、命题逻辑
- 二叉树和图1
- Flutter Icon Stack LIsttitle...学习总结3
- CVPR 2022 | frame by frame motion representation of long video based on sequence contrast learning
猜你喜欢

Flutter Icon Stack LIsttitle... Learning summary 3

CentOS Linux 已死!Oracle Linux 可能是它的更好替代品

22.6.7成功使用doc2vec模型生成嵌入向量

Flutter drawer learning summary 6

Review summary of final examination of software architecture principles, methods and practices, Second Edition

【离散数学期复习系列】三、集合的概念及运算

Anaconda installs opencv (CV2) and uses it in the jupyter notebook

Mutual transformation among lists, arrays and tensors
![[discrete mathematics review series] III. concept and operation of sets](/img/b5/5c7d077490875dbe0ff4777f6b0a7a.png)
[discrete mathematics review series] III. concept and operation of sets

【Vue/js】通过localStorage浏览器实现变量和对象的本地缓存(图文+完整源代码)
随机推荐
[note] the environment for setting up get injectedthread script supplemented by shellcode in Windows Security III and its use
软件智能:aaas系统 度量衡及文法的形式规则
C multithreading learning note 4
lua 表操作
Flyter page Jump to transfer parameters, tabbar learning summary 5
Primary master-slave table integration process development process
P3379 [template] nearest common ancestor (LCA)
[vue/js] realize local caching of variables and objects through localstorage browser (text + full source code)
焱融看|混合云环境下,如何实现数据湖最优存储解决方案
Implementation of VGA protocol based on FPGA
what‘t the meaning of “de facto“
Yanrong looks at how to realize the optimal storage solution of data Lake in a hybrid cloud environment
[discrete mathematics review series] v. some special charts
QT 基于QScrollArea的界面嵌套移动
Main features of IIC bus / communication process / read / write process
CVPR 2022 | frame by frame motion representation of long video based on sequence contrast learning
IIC总线的主要特点/通信过程/读写过程
Simulated 100 questions and online simulated examination for safety production management personnel of hazardous chemical production units in 2022
Design tools and skills for beginners to build their own blog
博主自白