[GIS] Convert land-based camera image pixel x,y to ground lat/long or x,y,z

coordinate systemimagejava

I have a number of cameras at various known locations (x,y,z) and directions that are above ground about 20 feet pointed at different ground locations about 100 feet away from each camera, and whose furthest fields of view (FOV) are about 300 feet. None of the cameras are pointing directly N-S or E-W. Because of the relatively short distance, I don't need to take into consideration the curvature of the Earth.

I am detecting moving objects within the camera FOV and obtaining their image pixel x,y contours and centroids. How can I convert the pixel x,y locations into (initially 'flat') lat long coordinates or relative ground x,y locations? I am obtaining elevation data, so will be adding the ground height (z).

Am trying to do this in Java as much as possible, so any pointers (e.g., algorithms, code libraries, etc) are welcome

Best Answer

This is something I'm working on as well and I need to improve the accuracy of the run. One thing to do is use the opencv library. For instance in Python:

import numpy as np
import cv2
twoD = np.array([[   0.      ,    0.      ],
       [3840.      ,    0.      ],
       [3840.      , 3240.      ],
       [   0.      , 3240.      ]])
threeD = np.array([[-1.9292996 , 94.3841359 ],
       [-2.1339714 , 92.7364367 ],
       [-0.7249805 , 92.5754107 ],
       [-0.568487  , 94.2150297 ]])
pixelcoords = (1051.311157, 3167.13916, 1) # pixel coordinates
H = cv2.findHomography(twoD, threeD, cv2.RANSAC, 5.0)
latlon = H @ pixelcoords
latlon /= latlon[-1]
# latlon = np.array([-0.64319293, 93.78276724,  1.        ])