在使用GDAL进行jpg文件的地理评论之后,我能知道jpg文件的哪个像素已移至TIF文件的哪个像素?

发布于 2025-01-29 16:50:46 字数 1506 浏览 2 评论 0原文

拳头,我要感谢所有会给我答案的人。

我想获得无人机图像(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)

enter image description here

post-georeferencing image (tif)

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风疏影 2025-02-05 16:50:47

您需要的内容称为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.html

You can run it on the dataset that is the output of gdal.Translate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文