Closed frigusgulo closed 4 years ago
First, try to provide a complete code example (including import
statements) and place the code in a code block with the appropriate language tag (i.e. ```python ... ```).
The verdict: Since you are not passing any cam_params
or group_params
to optimize.Cameras
, there are no parameters to optimize. This is the source of the error.
Read on for a discussion of other issues with your code.
Camera
Here is the cleaner equivalent of what you are doing:
import glimpse
import numpy as np
params = dict(
sensorsz=(35.9, 24),
xyz=(393506.713, 6695855.64, 961.3370),
viewdir=(72.08866164934302, -24.53, 0.35382)
)
cam = glimpse.Camera(**params)
All other parameters, like imgsz
and f
, are left at their default, which is probably not what you want!
cam.imgsz
array([100., 100.])
You can use Image
, Exif
, or manually type in the right values:
import glimpse
import numpy as np
params = dict(
sensorsz=(35.9, 24),
xyz=(393506.713, 6695855.64, 961.3370),
viewdir=(72.08866164934302, -24.53, 0.35382),
imgsz=(7360, 4912),
fmm=28
)
cam = glimpse.Camera(**params)
optimize.Cameras
Now let's work our way down to your call to Cameras()
:
uv = np.array([
[5193, 549],
[3101, 642],
[3680, 2456],
[6153.0, 2297.0]
])
xyz = np.array([
[408245.86, 6695847.03, 1560],
[416067.22, 6707259.97, 988],
[393506.713, 6695855.641, 961.337],
[394569.509, 6695550.678, 621.075]
])
points = glimpse.optimize.Points(cam, uv, xyz)
model = glimpse.optimize.Cameras([cam], [points])
params = model.fit()
Since you are not passing any cam_params
or group_params
to optimize.Cameras
, there are no parameters to optimize. This is the source of the error. I am guessing that at the very least, you want to optimize viewdir
:
model = glimpse.optimize.Cameras([cam], [points], dict(viewdir=True))
params = model.fit()
But the residuals (pixel reprojection errors) are way too large to proceed, even after optimization:
model.residuals(params)
array([[ 1998.55743481, -1517.90345026], [ 1147.74632006, 293.201628 ], [-6969.12413606, 2479.49767523], [ 4970.93608408, -1752.52436834]])
Plotting confirms that your initial guess for viewdir
is in the right ballpark:
import matplotlib.pyplot as plt
poly = cam.viewpoly(10e3)
plt.plot(poly[:, 0], poly[:, 1])
plt.plot(cam.xyz[0], cam.xyz[1], 'k.')
plt.plot(points.xyz[:, 0], points.xyz[:, 1], 'r.')
plt.gca().set_aspect('equal')
plt.show()
So there most likely something wrong with your control points or your camera position (cam.xyz
). Once thing I notice is that your third world point is equal to your camera position, which can't be right.
sensorx,sensory = 35.9,24 cam_coords = [393506.713,6695855.64 ,961.3370] #Easting, Northing, Elevation cam_viewdir = [72.08866164934302, -24.53,0.35382] # An intial guess cliff_camera = glimpse.Camera(xyz=cam_coords,viewdir=cam_viewdir,sensorsz (sensorx,sensory)) cliff_imgpts = np.array([[5193, 549],[3101, 642],[3680, 2456],[6153.0, 2297.0]]) cliff_worldpts = np.array([[408245.86,6695847.03,1560 ],[416067.22,6707259.97,988],[393506.713, 6695855.641, 961.337],[394569.509, 6695550.678, 621.075]]) cliff_points = glimpse.optimize.Points(cliff_camera,cliff_imgpts,cliff_worldpts)
cliff_cam_params = glimpse.optimize.Cameras([cliff_camera],[cliff_points]) cliff_cam_params = cliff_cam_params.fit()
Traceback:
ValueError Traceback (most recent call last)