如何处理 python 航拍图中的 gcp 点列表?

How to process list of gcp points from the aerial image in python?

我有从 QGIS 导出的 gcp 点,我想通过使用这些点在 python 中使用 gdal 模块对几张地图进行地理配准。

以下是从csv文件中读取gcp点的代码,它们将用于在gdal函数中转换数据。

import pandas as pd
f=pd.read_csv("/content/drive/MyDrive/00390_00390_modified.tif.points")
keep_col = ['mapX','mapY','pixelX', 'pixelY', 'enable', 'dX','dY', 'residual']
new_f = f[keep_col]
df = new_f.drop(columns=['enable','dX', 'dY', 'residual'])
#df['gcp']='-gcp'
#df['end']='\ '
#print(df)
col=['pixelY','pixelX','mapX','mapY']
modified_df = df[col]
modified_df['pixelY'] = modified_df['pixelY'] + 1200
new_df= modified_df.to_csv('/content/drive/MyDrive/modified.csv', index=False)
print(modified_df[col])

这段代码的输出是,

        pixelY       pixelX          mapX          mapY
0    553.956835    19.352518  6.776477e+06  3.485354e+06
1    879.496403   663.237410  7.781406e+06  4.026885e+06
2   1053.776978   752.446043  7.925402e+06  4.306009e+06
3    751.618705  1047.230216  8.385932e+06  3.806277e+06
4    340.467626   674.208633  7.795048e+06  3.193823e+06

这些将是 !gdaltranslate 函数的输入地面控制点。

有什么方法可以在-gcp和frontslash之间插入坐标吗?

我尝试了很多,但不幸的是,通过 pandas 数据框和 CSV 读取数据和处理它们都不起作用。

!gdal_translate \
-gcp    553.9568345 19.35251799 6776477.033 3485353.556 \
-gcp    879.4964029 663.2374101 7781405.588 4026884.535 \
-gcp    1053.776978 752.4460432 7925401.709 4306008.844 \
-gcp    751.618705  1047.230216 8385931.623 3806277.157 \
-gcp    340.4676259 674.2086331 7795047.763 3193823.491 \
-of GTiff \
/content/drive/MyDrive/00390_00390.tif \
/content/drive/MyDrive/map-with-gcps.tif

好的,我找到了解决方案。我发了。

# Read the coordinates in the CSV file
f=pd.read_csv("/content/drive/MyDrive/Input/00390_00390_modified.tif.points")
keep_col = ['mapX','mapY','pixelX', 'pixelY', 'enable', 'dX','dY', 'residual']
new_f = f[keep_col]
df = new_f.drop(columns=['enable','dX', 'dY', 'residual'])
col=['mapX','mapY', 'pixelX','pixelY']
modified_df = df[col]
modified_df['pixelY'] = modified_df['pixelY'] *(-1) 

# Create an empty GCP list
gcp_list=[]

# GCP coordinates list  
for index, rows in modified_df.iterrows():
   gcps = gdal.GCP(rows.mapX, rows.mapY, 1, rows.pixelX, rows.pixelY )
   gcp_list.append(gcps)
   print(gcps)