在使用GDAL进行jpg文件的地理评论之后,我能知道jpg文件的哪个像素已移至TIF文件的哪个像素?
拳头,我要感谢所有会给我答案的人。
我想获得无人机图像(JPG)每个像素的地理坐标。
因此,我使用GDAL和GCP信息确实在无人机图像(JPG)上进行了地理发行。
而且它还获得了通过地理发射获得TIF文件的每个像素的地理坐标。
但是我想知道的是JPG文件的每个像素的地理坐标。
因此,我必须找到哪个JPG的像素被移至TIF。
我能知道JPG文件的哪个像素已移至TIF文件的哪个像素?
这是代码和倾斜前图像(JPG)和倾斜后图像(TIF)
from osgeo import gdal
import numpy as np
import matplotlib.pyplot as plt
ds = gdal.Open('data/DJI_0165_cali.jpg')
gcp_list = []
gcp = gdal.GCP(392689.698, 294905.073, 0, 3702, 970)
gcp_list.append(gcp)
gcp = gdal.GCP(392727.269, 294776.388, 0, 1981, 996)
gcp_list.append(gcp)
gcp = gdal.GCP(392765.136, 294638.506, 0, 283, 988)
gcp_list.append(gcp)
gcp = gdal.GCP(392732.312, 294639.35, 0, 391, 615)
gcp_list.append(gcp)
gcp = gdal.GCP(392703.634, 294770.92,0, 1996, 698)
gcp_list.append(gcp)
gcp = gdal.GCP(392670.438, 294885.556,0, 3519, 669)
gcp_list.append(gcp)
ds_gcp = gdal.Translate('output.tif', ds, GCPs=gcp_list)
ds_gcp = gdal.Warp('output.tif',ds_gcp, dstSRS='EPSG:3857', dstNodata = np.nan)
def pixel(file,dx,dy):
px = file.GetGeoTransform()[0]
py = file.GetGeoTransform()[3]
rx = file.GetGeoTransform()[1]
ry = file.GetGeoTransform()[5]
x = dx*rx + px
y = dy*ry + py
return x,y
pixel(ds_gcp,1500,1500)
pre-Georeferencing Image(JPG)
tif)
Fist of all, I'd like to say thanks to everyone who will give me answer.
I wanna get the geo-coordinates of each pixel of the drone image(jpg).
So I did georeferencing on drone image(jpg) using GDAL and GCP info.
And it also got the geo-coordinates of each pixel of tif file obtained through georeferencing.
But what I wanna know is the geo-coordinates of each pixel of jpg file.
So I have to find which pixel of jpg was moved to in tif.
Can I know which pixel of the jpg file has been moved to which pixel of the tif file?
Here is the code and pre-georeferencing image (jpg) and post-georeferencing image (tif)
from osgeo import gdal
import numpy as np
import matplotlib.pyplot as plt
ds = gdal.Open('data/DJI_0165_cali.jpg')
gcp_list = []
gcp = gdal.GCP(392689.698, 294905.073, 0, 3702, 970)
gcp_list.append(gcp)
gcp = gdal.GCP(392727.269, 294776.388, 0, 1981, 996)
gcp_list.append(gcp)
gcp = gdal.GCP(392765.136, 294638.506, 0, 283, 988)
gcp_list.append(gcp)
gcp = gdal.GCP(392732.312, 294639.35, 0, 391, 615)
gcp_list.append(gcp)
gcp = gdal.GCP(392703.634, 294770.92,0, 1996, 698)
gcp_list.append(gcp)
gcp = gdal.GCP(392670.438, 294885.556,0, 3519, 669)
gcp_list.append(gcp)
ds_gcp = gdal.Translate('output.tif', ds, GCPs=gcp_list)
ds_gcp = gdal.Warp('output.tif',ds_gcp, dstSRS='EPSG:3857', dstNodata = np.nan)
def pixel(file,dx,dy):
px = file.GetGeoTransform()[0]
py = file.GetGeoTransform()[3]
rx = file.GetGeoTransform()[1]
ry = file.GetGeoTransform()[5]
x = dx*rx + px
y = dy*ry + py
return x,y
pixel(ds_gcp,1500,1500)
pre-georeferencing image (jpg)
post-georeferencing image (tif)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要的内容称为
gdalgcptransform
在C ++ API中:https://gdal.org/doxygen/gdal_erg _8h.html 没有python绑定,但似乎存在于
rasterio
中: https://rasterio.readthedocs.io/en/latest/api/rasterio.transform.html您可以在数据集中运行它,这是
gdal.translate 。
What you need is called
GDALGCPTransform
in the C++ API:https://gdal.org/doxygen/gdal__alg_8h.html
As far as I know there is no Python binding but it seems that it is present in
rasterio
: https://rasterio.readthedocs.io/en/latest/api/rasterio.transform.htmlYou can run it on the dataset that is the output of
gdal.Translate
.