当前位置:网站首页>Intercept the coordinate points (four point coordinates of the face frame) face image from the marked XML file and save it in the specified folder
Intercept the coordinate points (four point coordinates of the face frame) face image from the marked XML file and save it in the specified folder
2022-07-26 13:30:00 【Pay to work hard】
In target detection , Datasets are often used labelimg mark , Will generate xml file . The purpose of this article is according to xml Label the file to crop the target , In order to remove the background information .
Detailed connection :
details
import cv2
import xml.etree.ElementTree as ET
import os
img_path = r'Y:\V47\Indoor\BWPhoto\Normal\2203181450_Indoor_Normal' # Picture path
xml_path = r'Y:\V47\Indoor\BWPhoto\Normal\2203181450_Indoor_Normal' # Tag path
obj_img_path = r'D:/cut' # Target clipping image storage path
for img_file in os.listdir(img_path): # Traverse the picture folder
if img_file[-4:] in ['.bmp', '.jpg', '.png']: # Determine whether the file is in picture format
img_filename = os.path.join(img_path, img_file) # Mosaic the image path with the image name
img_cv = cv2.imread(img_filename) # Read the picture
img_name = (os.path.splitext(img_file)[0]) # Split the image name
img_name_ = img_name.split('_')[1]
# Find the label xml File pathname
xml_name = xml_path + '\\' + '%s.xml' % ('PADRecord_'+ img_name_) # Using tag paths 、 Picture name 、xml Complete path name suffix
print(xml_name)
if os.path.exists(xml_name): # Determine whether a label with the same name as the picture exists , Because not all the pictures are marked
root = ET.parse(xml_name).getroot() # utilize ET Read xml file
count = 0 # Statistics of the number of target boxes , Prevent the target file from overwriting
for obj in root.iter('LocalizedFaces'): # Traverse all target boxes
name = obj.find('LocalizedFace').text # Get the name of the target box , namely label name
xmlbox = obj.find('LocalizedFace') # Find the box target
x0 = xmlbox.find('JFace').text # Take out the four vertex coordinates of the box target
y0 = xmlbox.find('IFace').text
x1 = xmlbox.find('WidthFace').text
y1 = xmlbox.find('HeightFace').text
obj_img = img_cv[int(y0):int(y0)+int(y1), int(x0):int(x0)+int(x1)] # cv2 Crop out the picture in the target box
# cv2.imshow("image", obj_img) # Display images
# cv2.waitKey(0)
# cv2.destroyAllWindows()
cv2.imwrite(obj_img_path + '\\' + '%s_%s' % (img_name, count) + '.jpg', obj_img) # Save cut pictures
count += 1 # The statistical value of the target box increases automatically 1
print(" Crop complete !")
边栏推荐
- 421. 数组中两个数的最大异或值
- B+ tree index use (6) leftmost principle -- MySQL from entry to proficiency (18)
- 解决方案丨5G技术助力搭建智慧园区
- MySQL data directory (2) -- table data structure (XXV)
- Unity中序列化类为json格式
- Basic sentence structure of English ----- origin
- 历时15年、拥有5亿用户的飞信,彻底死了
- Analysis on the current situation and optimization strategy of customer experience management in banking industry
- B+ tree (4) joint index -- MySQL from entry to proficiency (16)
- Sword finger offer (VII): Fibonacci sequence
猜你喜欢

从其他文件触发pytest.main()注意事项

Time complexity and space complexity

AI-理论-知识图谱1-基础

解决方案丨5G技术助力搭建智慧园区

HCIP第十一天比较(BGP的配置、发布)

官宣!艾德韦宣集团与百度希壤达成深度共创合作

A college archives management system based on asp.net

panic: Error 1045: Access denied for user ‘root‘@‘117.61.242.215‘ (using password: YES)

Precautions for triggering pytest.main() from other files

This article explains the FS file module and path module in nodejs in detail
随机推荐
从标注好的xml文件中截取坐标点(人脸框四个点坐标)人脸图像并保存在指定文件夹
Win11+VS2019配置YOLOX
Multi objective optimization series 1 --- explanation of non dominated sorting function of NSGA2
算法--连续数列(Kotlin)
[flower carving hands-on] fun music visualization series small project (12) -- meter tube fast rhythm light
Tupu 3D visual national style design | collision between technology and culture "cool" spark“
Leetcode 2119. number reversed twice
HCIP第十二天笔记整理(BGP联邦、选路规则)
冒泡排序的时间复杂度分析
B+树索引使用(6)最左原则 --mysql从入门到精通(十八)
B+树索引使用(7)匹配列前缀,匹配值范围(十九)
Extra (5) - MySQL execution plan (51)
How to build a customer-centric product blueprint: suggestions from the chief technology officer
Ultimate doll 2.0 | cloud native delivery package
Mysql数据目录(1)---数据库结构(二十四)
How to realize the reality of temporary graphic elements
Learn about Pinia state getters actions plugins
【C语言学习者必会的题目集锦1】巩固基础,稳步提高
Team research and development from ants' foraging process (Reprint)
Tianjin emergency response Bureau and central enterprises in Tianjin signed an agreement to deepen the construction of emergency linkage mechanism