当前位置:网站首页>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 !")
边栏推荐
- SuperMap iclient for leaflet loads Gauss Kruger projection three-dimensional zonation CGCS2000 geodetic coordinate system WMTs service
- JSON数据传递参数&日期型参数传递
- Outline design specification
- LeetCode 69. x 的平方根
- Learn about Pinia state getters actions plugins
- 概率论与数理统计
- 目标检测网络R-CNN 系列
- 7-25 0-1 backpack (50 points)
- With 8 years of product experience, I have summarized these practical experience of continuous and efficient research and development
- 【开源之美】nanomsg(2) :req/rep 模式
猜你喜欢

Ultimate doll 2.0 | cloud native delivery package

【Oauth2】五、OAuth2LoginAuthenticationFilter

Tianjin emergency response Bureau and central enterprises in Tianjin signed an agreement to deepen the construction of emergency linkage mechanism

This article explains the FS file module and path module in nodejs in detail

Learn about Pinia state getters actions plugins

2022年,我们只用一个月就“送走”了这么多互联网产品

算法--连续数列(Kotlin)

【花雕动手做】有趣好玩的音乐可视化系列小项目(13)---有机棒立柱灯

Activity.onStop() 延迟10秒?精彩绝伦的排查历程

Student examination system based on C #
随机推荐
白帽子揭秘:互联网千亿黑产吓退马斯克
估值15亿美元的独角兽被爆裁员,又一赛道遇冷?
多线程使用不当导致的 OOM
[flower carving hands-on] fun music visualization series small project (12) -- meter tube fast rhythm light
Leetcode 2119. number reversed twice
Target detection network r-cnn series
Outline design specification
Solve the problem that the remote host cannot connect to the MySQL database
AI theory knowledge map 1 Foundation
Probability theory and mathematical statistics
Basic sentence structure of English ----- origin
时间复杂度和空间复杂度
B+树索引使用(7)匹配列前缀,匹配值范围(十九)
从标注好的xml文件中截取坐标点(人脸框四个点坐标)人脸图像并保存在指定文件夹
[flower carving hands-on] interesting and fun music visualization series small project (13) -- organic rod column lamp
How to build a customer-centric product blueprint: suggestions from the chief technology officer
Tupu 3D visual national style design | collision between technology and culture "cool" spark“
This article explains the FS file module and path module in nodejs in detail
MySQL data directory (3) -- table data structure MyISAM (XXVI)
Feixin, which lasted 15 years and had 500million users, was completely dead