From 4254110d795febc9d2b3330e7810aece01b297ca Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Mon, 25 Aug 2014 18:43:46 +0200 Subject: yay, bildstabilisierung worx --- test.py | 18 +++++++++++++++--- 1 file 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) ) -- cgit v1.2.3