当前位置:网站首页>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 !")
边栏推荐
- 2022年,我们只用一个月就“送走”了这么多互联网产品
- (Reprint) creation methods of various points in ArcGIS Engine
- How to write the introduction of GIS method journals and papers?
- LeetCode 69. x 的平方根
- Chat system based on webrtc and websocket
- Target detection network r-cnn series
- Photoshop (cc2020) unfinished
- B+树(3)聚簇索引,二级索引 --mysql从入门到精通(十五)
- Hcip day 11 comparison (BGP configuration and release)
- [turn] judge the relationship between two geometries in ArcGIS
猜你喜欢

WPS凭什么拒绝广告?

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

We were tossed all night by a Kong performance bug

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

Implementation of SAP ABAP daemon

Feixin, which lasted 15 years and had 500million users, was completely dead

Concept and handling of exceptions

JSON data transfer parameters & date type parameter transfer
Control the probability of random winning [C | random]

Multi objective optimization series 1 --- explanation of non dominated sorting function of NSGA2
随机推荐
Uncover the secret of white hat: 100 billion black products on the Internet scare musk away
Ultimate doll 2.0 | cloud native delivery package
算法--连续数列(Kotlin)
周伟:寻找非共识性投资机会,陪伴延迟满足的创始团队
冒泡排序的时间复杂度分析
Multi objective optimization series 1 --- explanation of non dominated sorting function of NSGA2
同站攻击(相关域攻击)论文阅读 Can I Take Your Subdomain?Exploring Same-Site Attacks in the Modern Web
.NET WebAPI 使用 GroupName 对 Controller 分组呈现 Swagger UI
历时15年、拥有5亿用户的飞信,彻底死了
Exploration on cache design optimization of community like business
HCIP第十一天比较(BGP的配置、发布)
How to build a customer-centric product blueprint: suggestions from the chief technology officer
Precautions for triggering pytest.main() from other files
概率论与数理统计
Time complexity analysis of bubble sorting
key&key_ Len & ref & filtered (4) - MySQL execution plan (50)
官宣!艾德韦宣集团与百度希壤达成深度共创合作
【开源之美】nanomsg(2) :req/rep 模式
How to realize the reality of temporary graphic elements
Emotion analysis model based on Bert