summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Jung <flo@windfisch.org>2014-09-02 01:30:36 +0200
committerFlorian Jung <flo@windfisch.org>2014-09-02 01:30:36 +0200
commit5469a20a66d19484614b020e663fa6d2cce8c186 (patch)
tree4e832a012a6ea4c30b2dc2c7a1a9111ebd29b36e
parentaffc1dfb6ad0acf3a94cf47e243f28127d33164c (diff)
mehr zylindrisch. besser.HEADmaster
-rw-r--r--stabilize.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/stabilize.py b/stabilize.py
index 50d064b..b0c5c1a 100644
--- a/stabilize.py
+++ b/stabilize.py
@@ -1,7 +1,7 @@
import cv2
import math
import numpy
-from math import sin,cos
+from math import sin,cos,tan,sqrt
cap = cv2.VideoCapture("../vid.mp4")
writer = cv2.VideoWriter("../outvid.avi",cv2.cv.CV_FOURCC(*'MP42'),25,(1600,600),1)
@@ -40,6 +40,14 @@ def get_maps(xres,yres):
constant2= 1./(math.sqrt((1280/2)**2+(720/2)**2))*(92/2)/180*math.pi
foo = math.tan( 92/2/math.sqrt(16**2+9**2)*16. ) * constant / math.tan(1280/2 * constant2)
+
+ d = 18. # distance from center to camera
+ r = 200. # distance from center to recorded objects
+ alpha = 92/2/math.sqrt(16**2+9**2)*16. # angle over x axis
+ lam = -d * cos(alpha) + math.sqrt(d**2 * (cos(alpha))**2 - d**2 + r**2)
+ dist_canvas = d + lam*cos(alpha)
+ width_canvas = lam*sin(alpha) * 2
+ beta = math.atan(width_canvas/2./dist_canvas) # viewing angle as calculated from center of camera. depends from object distance, because camera is not at the center.
for y in xrange(0,yres):
xtmp=[]
@@ -47,7 +55,10 @@ def get_maps(xres,yres):
yy=(y-yres/2.)/xres # yes, xres.
for x in xrange(0,xres):
- xx=math.tan((x-xres/2.)/xres*foo)/foo
+ #xx= tan((x-xres/2.)/xres*2.*beta) * dist_canvas / width_canvas
+ #xx= tan((x-xres/2.)/xres*width_canvas/dist_canvas) * dist_canvas / width_canvas
+ xx= tan((x-xres/2.)/xres*2.*beta) /2./beta
+ # derivative of this at location 0 should be 1.0/xres
dist = math.sqrt(xx**2 + yy**2)