Label: 61, Position: (1633, 1394), Size: 28 x 17 Label: 62, Position: (1576, 1395), Size: 19 x 29 Label: 63, Position: (1592, 1402), Size: 25 x 20 Label: 64, Position: (1651, 1403), Size: 25 x 23 Label: 65, Position: (1519, 1404), Size: 24 x 30转换为(x,y,w,h)的形式
时间: 2024-04-02 07:37:18 浏览: 20
Label 61: (1633, 1394, 28, 17)
Label 62: (1576, 1395, 19, 29)
Label 63: (1592, 1402, 25, 20)
Label 64: (1651, 1403, 25, 23)
Label 65: (1519, 1404, 24, 30)
相关问题
Label: 1, Position: (0, 0), Size: 2212 x 1578 Label: 2, Position: (1596, 1281), Size: 28 x 17 Label: 3, Position: (1578, 1286), Size: 25 x 18 Label: 4, Position: (1619, 1288), Size: 42 x 43 Label: 5, Position: (1534, 1289), Size: 44 x 11给每一行两边加上分号
你可以使用字符串操作和循环来实现这个转换。下面是一个示例代码:
```python
string = "Label: 1, Position: (0, 0), Size: 2212 x 1578\nLabel: 2, Position: (1596, 1281), Size: 28 x 17\nLabel: 3, Position: (1578, 1286), Size: 25 x 18\nLabel: 4, Position: (1619, 1288), Size: 42 x 43\nLabel: 5, Position: (1534, 1289), Size: 44 x 11"
lines = string.split("\n")
new_lines = []
for line in lines:
new_line = f"; {line} ;"
new_lines.append(new_line)
result = "\n".join(new_lines)
print(result)
```
这个代码会输出以下结果:
```
; Label: 1, Position: (0, 0), Size: 2212 x 1578 ;
; Label: 2, Position: (1596, 1281), Size: 28 x 17 ;
; Label: 3, Position: (1578, 1286), Size: 25 x 18 ;
; Label: 4, Position: (1619, 1288), Size: 42 x 43 ;
; Label: 5, Position: (1534, 1289), Size: 44 x 11 ;
```
注意,这个代码假设输入的字符串格式都相同。如果输入的字符串格式不同,可能需要对代码进行相应的修改。
Label: 2, Position: (1596, 1281), Size: 28 x 17 Label: 3, Position: (1578, 1286), Size: 25 x 18改为(1596,1281,28,17)的形式
这里有两个字符串需要转换,你可以使用循环来处理它们。下面是一个示例代码:
```python
strings = ["Label: 2, Position: (1596, 1281), Size: 28 x 17", "Label: 3, Position: (1578, 1286), Size: 25 x 18"]
new_strings = []
for string in strings:
label, position, size = string.split(", ")
x, y = position.strip("()").split(", ")
w, h = size.split(" x ")
new_string = f"{x}, {y}, {w}, {h}"
new_strings.append(f"{label}, Position: ({new_string})")
result = " ".join(new_strings)
print(result)
```
这个代码会输出以下结果:
```
Label: 2, Position: (1596, 1281, 28, 17) Label: 3, Position: (1578, 1286, 25, 18)
```
注意,这个代码假设输入的字符串格式都相同。如果输入的字符串格式不同,可能需要对代码进行相应的修改。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)