简体   繁体   English

我们如何通过xml得到形状的坐标?

[英]How do we get the coordinates of the shape through xml?

Reading mouse coordinate values was successful.读取鼠标坐标值成功。 But I need to read the stored coordinate values through the xml.但是我需要通过xml读取存储的坐标值。

Value was retrieved using ElementTree.使用 ElementTree 检索值。 But once you've put it in an array, the shape of the coordinates is x,y, so the comma in the middle prevents integer conversion.但是一旦你把它放在一个数组中,坐标的形状就是 x,y,所以中间的逗号会阻止 integer 转换。 And it's a string, so it's apostrophe on both ends, so you can't convert it.而且它是一个字符串,所以两端都是撇号,所以不能转换。 Please advise me.请给我提意见。

<?xml version='1.0' encoding='utf-8'?>
<DA>
    <DetectionAreas>2</DetectionAreas>
    <DetectArea>
        <Point>0,0</Point>
        <Point>1280,0</Point>
        <Point>1280,720</Point>
        <Point>0,720</Point>
    </DetectArea>
    <Loitering>
        <Point>625,564</Point>
        <Point>625,0</Point>
        <Point>1280,0</Point>
        <Point>1280,631</Point>
    </Loitering>
</DA>

import xml.etree.ElementTree as ET

tree = ET.parse('./MapFile/C001101.map')
root = tree.getroot()
DetectPoint = root.getchildren()[1]
LoiteringPoint = root.getchildren()[2] 
IntrusionPoint = root.getchildren()[2]
Ipointvalue = []
Lpointvalue = []
Dpointvalue = []


if DetectPoint.tag == 'DetectArea' :
    for DPoint in root.findall("DetectArea/Point") :
        Dpointvalue.append(DPoint.text)
if LoiteringPoint.tag == 'Loitering' :
    for LPoint in root.findall("Loitering/Point") :        
        Lpointvalue.append(LPoint.text)
elif IntrusionPoint.tag == 'Intrusion' :
    for IPoint in root.findall("Intrusion/Point") :
        Ipointvalue.append(IPoint.text) 

ip = len(Ipointvalue)
lp = len(Lpointvalue)
dp = len(Dpointvalue)

for i in range(dp): 
    Dpointvalue[i]
    print(Dpointvalue[i])
for i in range(lp):
    Lpointvalue[i]
    print(Lpointvalue[i])
for i in range(ip):
    Ipointvalue[i]
    print(Ipointvalue[i])   

'
'
'
    def onMouseCallback(self, event, x, y, flags, idx):
        if self.view_state == 'intrusion append' or self.view_state == 'loitering append' or self.view_state == 'counting append':
            if event == cv2.EVENT_LBUTTONUP and flags == cv2.EVENT_FLAG_LBUTTON:
                works[idx].area_tmp.append([x, y])
                #print(works[idx].area_tmp)
                #print(Dpointvalue)

To create a polyline The coordinate values I wanted were x and y, but I want to ask for advice because it was recognized like this 'x,y'.创建折线 我想要的坐标值是 x 和 y,但我想征求意见,因为它被识别为这样的 'x,y'。

Define a 'namedtuple' named Point.定义一个名为 Point 的“namedtuple”。 This object has two int properties x and y.这个 object 有两个 int 属性 x 和 y。 There is a helper method that will help you to translate the data you have (x and y as string) to a Point object有一个辅助方法可以帮助您将您拥有的数据(x 和 y 作为字符串)转换为点 object

See below见下文

from collections import namedtuple

Point = namedtuple('Point','x y')

def make_point(point_str):
    parts = point_str.split(',')
    return Point(int(parts[0]),int(parts[1]))


point_str = '3,4'
point = make_point(point_str)
print(point)
print(point.x)
print(point.y)

output output

Point(x=3, y=4)
3
4

Now your code may look like:现在您的代码可能如下所示:

...
Lpointvalue.append(make_point(LPoint.text))
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我们如何使用带有 tensorflow 的蛋白化获得正确的形状尺寸 - How do we get correct shape dimensions using albumentation with tensorflow 如何在matplotlib树图中获取形状坐标? - How to get coordinates of shape in matplotlib treemap? 如何获取代表轮廓形状的向量的坐标,该轮廓形状存储为 2D numpy 像素数组? - How do I get the coordinates of the vectors that represent a contour shape which I have stores as a 2D numpy array of pixels? 我们如何塑造 Xarray 数据数组? - How do we shape Xarray data-array? 我们如何借助行进距离和运动方向获得坐标? - How can we get the coordinates with the help of distance traveled and direction of movement? 如何在 VTK 中获得正确的坐标 - How do I get the right coordinates in VTK pygame,如何获取图形的坐标? - pygame, how do you get coordinates of a graphic? 这个Numpy形状是什么意思? - What do we mean by this Numpy shape? Python-使用Minidom进行xml解析-如何迭代每个 <parent> 并得到一个清单 <child> 为了那个原因 <parent> ? - Python - xml parsing with Minidom - How do I iterate through each <parent> and get a list of <child> for that <parent>? 我们如何使用python连接器连接雪花,我们如何通过它查询多个sql语句? - How do we connect to snowflake using python connector and how do we query multiple sql statements through it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM