python矢量图形和对应的图片坐标变换
python矢量图形和对应的图片坐标换算
import os import numpy as np import re from pathlib import Path output_folder='./data' filename_lineEdge = r'./data/fx0022/dom1lines_Edge.txt' filename_jgw = r'./data/fx0022/test/dom1.jgw' #读取线段文件 data = [] i = 0 with open(filename_lineEdge, 'r') as f: lines = f.readlines() for item in lines: #print(item.strip()) out = re.sub(r"\s{2,}", " ", item).strip() #print(out) res = out.split(" ") if i == 0: data = np.expand_dims(res, axis=0) i = i + 1 else: data = np.concatenate((data, np.expand_dims(res, axis=0)), axis=0) data = np.array(data).astype(np.float64) print(data.shape) #读取jgw文件 if os.path.isfile(filename_jgw): with open(filename_jgw, 'r') as fjpw: lines_jgw = fjpw.readlines() resolution = float(lines_jgw[0]) topleftX = float(lines_jgw[4]) topleftY = float( lines_jgw[5]) else: resolution = 1.0 topleftX = 0 topleftY = 0 print(resolution) print(topleftX) print(topleftY) #坐标变换 f_newEdge= output_folder+'/{}{}'.format(str(Path(filename_lineEdge).stem),'_edge.txt') with open(f_newEdge,'w' ) as newlineEdgeFile: for element in data: print(element) fromX=topleftX+element[2]*resolution fromY=topleftY-element[0]*resolution toX=topleftX+element[3]*resolution toY=topleftY-element[1]*resolution new_Line=[fromX, fromY, toX, toY] print('转换后{}'.format(new_Line)) newlineEdgeFile.writelines('{} {} {} {}\n'.format(fromY,toY,fromX,toX))
作者:太一吾鱼水
文章未经说明均属原创,学习笔记可能有大段的引用,一般会注明参考文献。
欢迎大家留言交流,转载请注明出处。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· Vue3状态管理终极指南:Pinia保姆级教程
2021-07-18 CC+VS2015编译
2018-07-18 ROS学习备忘
2013-07-18 分页显示
2013-07-18 xsd