python - How to find rotation angle of a stabilized video frame on Matlab -
consider have following stabilized video frame stabilization done rotation , translation (no scaling):
as seen in image, right-hand side of image symmetric of previous pixels, i.e black region after rotation filled symmetry. added red line indicate more clearly. 
i'd find rotation angle use later on. have done via surf or sift features, however, in real case scenario, won't have original frame.
i can find angle brute force wonder if there better , more elegant solution. note that, intensity value of symmetric part not precisely same original part. i've checked values, example, upper right pixel of v character on keyboard is [51 49 47] in original part [50 50 47] in symmetric copy means corresponding pixels not guaranteed same rgb value.
i'll implement on matlab or python , video stabilization done using ffmpeg.
edit: have stabilized video, don't have access original video or files produced ffmpeg.
any help/suggestion appreciated,
a pixel (probably) lies on searched symmetry line if
- its (first/second/thrid/...) left , right point equal (=>
dg, figure 1 left) - its (first/second/thrid/...) left (or right) value different (=>
dgs, figure 1 middle)
so, points of interest characterised high values |dgs| - |dg| (=> dgs_dg, figure 1 right)
as can seen on right image of figure 1, lot of false positives still exist. therefore, hough transform (figure 2 left) used detect points corresponding strongest line (figure 2 right). green line indeed searched line.
tuning
changing
n: higher values discard more false positives, excludesnborder pixels. can avoided using lowernborder pixels.changing thresholds: higher threshold on
dgs_dgdiscard more false positives. discarding high values ofdgmay interesting discard edge locations in original image.a priori knowledge of symmetry line: using definition of hough transform, can discard lines passing through center part of image.
the matlab code used generate images is:
i = imread('bnuqb.png'); g = int16(rgb2gray(i)); n = 3; % use first, second , third left/right point dg = int16(zeros(size(g) - [0 2*n+2])); dgs = int16(zeros(size(g) - [0 2*n+2])); i=0:n dg = dg + abs(g(:, 1+n-i:end-2-n-i) - g(:, 3+n+i:end-n+i)); dgs = dgs + abs(g(:, 1+n-i:end-2-n-i) - g(:, 2+n:end-n-1)); end dgs_dg = dgs - dg; dgs_dg(dgs_dg < 0) = 0; figure subplot(1,3,1); imshow(dg, []) subplot(1,3,2); imshow(dgs, []) subplot(1,3,3); imshow(dgs_dg, []) bw = dgs_dg > 0; [h,theta,rho] = hough(bw); p = houghpeaks(h,1); lines = houghlines(bw,theta,rho,p,'fillgap',50000,'minlength',7); figure subplot(1,2,1); imshow(h, []) hold on plot(p(:, 2),p(:, 1),'r.'); subplot(1,2,2); imshow(i(:, n+2:end-n-1, :)) hold on max_len = 0; k = 1:length(lines) xy = [lines(k).point1; lines(k).point2]; plot(xy(:,1),xy(:,2),'g'); end 


Comments
Post a Comment