Permalink
Browse files

calibrate: use the right argument to cv undistort function

  • Loading branch information...
1 parent 52c3b89 commit a87a667fee14b94968522cbd378f7b62d487d07d @mridley mridley committed with Jul 20, 2012
Showing with 25 additions and 6 deletions.
  1. +21 −1 camera/calibrate.py
  2. +4 −5 lib/cuav_util.py
View
@@ -3,7 +3,7 @@
import cv
import os,sys,string
-from numpy import array,zeros
+from numpy import array, zeros, ones
from cam_params import CameraParams
dims=(10,7)
@@ -109,6 +109,26 @@ def distort(K, D, p):
v_ = y_*K[1,1] + K[1,2]
return (u_, v_)
+def genReversMaps(K, D, C):
+ map_u = -9999*ones(C.yresolution, C.xresolution, dtype=int)
+ map_v = -9999*ones(C.yresolution, C.xresolution, dtype=int)
+
+ # fill what we can by forward lookup
+ for v in range(0, C.yresolution):
+ for u in range(0, C.xresolution):
+ if (map_u[int(v_), int(u_)] == -9999):
+ (u_,v_) = distort(u, v)
+ map_u[int(v_), int(u_)] = u
+ map_v[int(v_), int(u_)] = v
+
+ #something like
+ #for v_ in range(0, C.yresolution):
+ # for u_ in range(0, C.xresolution):
+ # if (map_u[int(v_), int(u_)] == -9999):
+ # (u, v) = solve((u_, v_), distort)
+ # map_u[int(v_), int(u_)] = u
+ # map_v[int(v_), int(u_)] = v
+
def dewarp(imagedir):
# Loading from json file
C = CameraParams()
View
@@ -272,7 +272,7 @@ def pixel_position_matt(xpos, ypos, height, pitch, roll, yaw, C):
return result is a tuple, with meters east and north of current GPS position
'''
- from numpy import array
+ from numpy import array,eye
from uav import uavxfer
from math import pi
@@ -286,14 +286,13 @@ def pixel_position_matt(xpos, ypos, height, pitch, roll, yaw, C):
src = cv.CreateMat(1, 1, cv.CV_64FC2)
src[0,0] = (xpos, ypos)
dst = cv.CreateMat(1, 1, cv.CV_64FC2)
+ R = cv.fromarray(eye(3))
K = cv.fromarray(C.K)
- print C.K
D = cv.fromarray(C.D)
- print C.D
- cv.UndistortPoints(src, dst, K, D)
+ cv.UndistortPoints(src, dst, K, D, R, K)
x = dst[0,0][0]
y = dst[0,0][1]
- print '(', xpos,',', ypos,') -> (', x, ',', y, ')'
+ #print '(', xpos,',', ypos,') -> (', x, ',', y, ')'
# negative scale means camera pointing above horizon
# large scale means a long way away also unreliable
(joe_w, scale) = xfer.imageToWorld(x, y)

0 comments on commit a87a667

Please sign in to comment.