summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Jung <flo@windfisch.org>2014-08-25 18:43:46 +0200
committerFlorian Jung <flo@windfisch.org>2014-08-25 18:43:46 +0200
commit4254110d795febc9d2b3330e7810aece01b297ca (patch)
tree8f6f4bf05d2ca630aa4cb59cae4ff9092815d468
parentf7ed04bd99f77bb9f6754ce9a2a2d0404a744a65 (diff)
yay, bildstabilisierung worx
-rw-r--r--test.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/test.py b/test.py
index e711096..325ffec 100644
--- a/test.py
+++ b/test.py
@@ -25,6 +25,8 @@ total_y=0
while(cap.isOpened()):
ret, frame = cap.read()
+ height, width, bpp = frame.shape
+
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
@@ -53,13 +55,23 @@ while(cap.isOpened()):
mat = cv2.estimateRigidTransform(gray,oldgray,False)
angle = math.atan2(mat[0,1],mat[0,0])
stretch = int((math.sqrt(mat[0,1]**2+mat[0,0]**2)-1)*100)
- print angle/3.141592654*180,'deg\t',stretch,"%\t", mat[0,2],'\t',mat[1,2]
- height, width, bpp = frame.shape
+
+ # calculate shift_x and _y is if one would rotate-and-stretch around the center of the image, not the topleft corner
+ shift_x = mat[0,2] - width/2 + ( mat[0,0]*width/2 + mat[0,1]*height/2 )
+ shift_y = mat[1,2] - height/2 + ( mat[1,0]*width/2 + mat[1,1]*height/2 )
+
+ total_x = total_x + shift_x
+ total_y = total_y + shift_y
+ total_angle=total_angle+angle
+
+ print angle/3.141592654*180,'deg\t',stretch,"%\t", shift_x,'\t',shift_y
+
frame2=frame.copy()
mat2=cv2.getRotationMatrix2D((width/2,height/2), total_angle/3.141593654*180, 1.)
+ mat2[0,2] = mat2[0,2]+total_x
+ mat2[1,2] = mat2[1,2]+total_y
print mat2.__repr__()
- total_angle=total_angle+angle
# mat2=numpy.array([[cos(total_angle), sin(total_angle), total_x], [-sin(total_angle),cos(total_angle),total_y]])
frame2= cv2.warpAffine(frame2, mat2, (width,height) )