将Yolo输出转换为真实世界的坐标系



我们使用Yolo v5在无人机数据上检测到物体,并以相对于卫星数据原点的格式获得边界框坐标(x1,y1,x2,y2)。数据如下所示,并以制表符分隔的文本文件的形式返回。

[ 7953 11025  7978 11052]
[16777 10928 16817 10970]
[15670 10591 15685 10607]

结果附带一个PNG,PGW(世界文件(如下所示:

0.1617903116883119
0
0
-0.1617903116883119
655854.20159515587147325
2716038.70000312989577651

如何将边界框转换为GIS中可用的真实世界全局投影EPSG:4328?任何关于python脚本的提示都将不胜感激。

进入Detect.py并设置gn=1,它将获得未归一化的坐标。附上下面的屏幕截图供您参考

我写了这个简短的函数来将yolo检测转换为真实世界的多边形。需要在没有[]的情况下读取yolodetections.txt

# function to return polygon
def bbox(x1, y1, x2, y2):
# world file content
# Line 1: A: x-component of the pixel width (x-scale)
xscale = 0.1617903116883119
# Line 2: D: y-component of the pixel width (y-skew)
yskew = 0
# Line 3: B: x-component of the pixel height (x-skew)
xskew = 0
# Line 4: E: y-component of the pixel height (y-scale), typically negative
yscale = -0.1617903116883119
# Line 5: C: x-coordinate of the center of the original image's upper left pixel transformed to the map
xpos = 655854.20159515587147325
# Line 6: F: y-coordinate of the center of the original image's upper left pixel transformed to the map
ypos = 2716038.70000312989577651
X_proj = xpos + (xscale * x1) + (xskew * y1)
Y_proj = ypos + (yscale * y1) + (yskew * x1)
X1_proj = xpos + (xscale * x2) + (xskew * y2)
Y1_proj = ypos + (yscale * y2) + (yskew * x2)
return Polygon([[X_proj, Y_proj],
[X1_proj, Y_proj],
[X1_proj, Y1_proj],
[X_proj, Y1_proj]])
outGDF = gpd.GeoDataFrame(geometry = dataset.apply(lambda g: bbox(int(g[0]),int(g[1]),int(g[2]),int(g[3])),axis=1),crs = {'init':'epsg:32638'})

最新更新