python从xml读取数据

该博客介绍了一个Python函数,用于从XML文件中读取G3D数据集的骨架数据。它遍历文件夹中的所有XML文件,对每个文件解析骨架跟踪状态和关节位置,特别是关注Spine、ShoulderCenter、ElbowLeft、WristLeft、HandLeft、ElbowRight、WristRight和HandRight等关节,存储24个关节的位置数据。
摘要由CSDN通过智能技术生成
from xml.etree import ElementTree as ET

def getSubDir(path):
    dirname=list()
    for file in os.listdir(path):
        dirname.append(file)
    return dirname

def get_xml_data(path):
    xmlFileNames = getSubDir(path)
    gesturePositionEndCount = 0

    for xmlFileName in xmlFileNames:
        if gesturePositionEndCount < int(str(xmlFileName).split("Skeleton ")[1].split(".xml")[0]):
            gesturePositionEndCount = int(str(xmlFileName).split("Skeleton ")[1].split(".xml")[0])
    gesture = np.zeros((gesturePositionEndCount+1, 24))
    gesturePositionStartCount = gesturePositionEndCount

    for xmlFileName in xmlFileNames:
        xmlPath = path + xmlFileName
        dom=ET.parse(xmlPath)
        TrackStatus=dom.findall('./Skeleton/TrackingState')
        isTracked = False

        for trackStatu in TrackStatus:
            if trackStatu.text=="Tracked":
                isTracked=True
        JointsPosition = np.zeros((24))
        if isTracked==True:
            gestureCount=int(str(xmlFileName).split("Skeleton ")[1].split(".xml")[0])
            if gesturePositionStartCount > gestureCount:
                gesturePositionStartCount = gestureCount
            Joints = dom.findall('./Skeleton/Joints/Joint/Position')
            JointType=dom.findall('./Skeleton/Joints/Joint/JointType'
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值