TransWikia.com

Is there a GDAL function similar to OpenCV's WarpPerspective?

Geographic Information Systems Asked by zuzaanto on October 1, 2020

I’t trying to mosaic a GeoTiff raster against another. Initially, they were both georeferenced in WGS-84 CRS.
Using OpenCV, I calculated a homography transformation (a 3×3 projection matrix), that transforms an image to fit the other – I did it using rasters converted to JPEG images. Then, using OpenCV function warpPerspective, I applied my homography to the image and obtained a JPEG mosaic.

Now, I want to apply that transformation matrix to the GeoTiff raster and warp it along with it’s geospatial information. However, I can’t find an GDAL/osgeo function that would do that: gdal.Warp() seems to be doing something else entirely.

So, my question is: is there a function in GDAL that would accept my raster image and my transformation matrix and output the correctly transformed raster with modified geospatial information?

If not, is there a possible workaround to achieve that?

One Answer

This solution requires using OpenCV 4.x and GDAL in python

You may want to try an affine transform between two images. cv.estimateAffine2D which gives you a 2x3 matrix

Get the transform of the pixel x,y coordinates of the second image to the first

warpedx = A[0,0]*x + A[0,1]*y + A[0,2]
warpedy = A[1,0]*x + A[1,1]*y + A[1,2] 

next you can validate by getting the those pixel coordinates and check if they match the original images pixel coorindates

xoff, a, b, yoff, d, e = ds.GetGeoTransform()
xp = a * x + b * y + xoff
yp = d * x + e * y + yoff

if the two points now match, go ahead and align the images and write the image with an updated geotransform

Answered by Evan O'Keeffe on October 1, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP