简体   繁体   English

如何在Matlab上找到稳定视频帧的旋转角度

[英]How to find rotation angle of a stabilized video frame on Matlab

Consider I have the following a stabilized video frame where stabilization is done by only rotation and translation (no scaling): 考虑我有一个稳定的视频帧,其中稳定只通过旋转和平移(没有缩放):

ORI

As seen in the image, Right-hand side of the image is symmetric of the previous pixels, ie the black region after rotation is filled with symmetry . 如图所示,图像的右侧是先前像素的对称, 即旋转后的黑色区域被对称填充 I added a red line to indicate it more clearly. 我添加了一条红线,表明它更清楚。 红线

I'd like to find the rotation angle which I will use later on. 我想找到我稍后会使用的旋转角度。 I could have done this via SURF or SIFT features, however, in real case scenario, I won't have the original frame. 我可以通过SURF或SIFT功能完成此操作,但是,在实际情况下,我不会有原始帧。

I probably can find the angle by brute force but I wonder if there is any better and more elegant solution. 我可能会通过蛮力找到角度,但我想知道是否有更好更优雅的解决方案。 Note that, the intensity value of the symmetric part is not precisely the same as the original part. 注意,对称部分的强度值与原始部分的精度值不完全相同。 I've checked some values, for example, upper right pixel of V character on the keyboard is [51 49 47] in original part but [50 50 47] in symmetric copy which means corresponding pixels are not guaranteed to be the same RGB value. 我检查了一些值,例如, 键盘上V字符的右上角像素原始部分 [51 49 47]但在对称拷贝中是[50 50 47] ,这意味着相应的像素不能保证是相同的RGB值。

I'll implement this on Matlab or python and the video stabilization is done using ffmpeg . 我将在Matlab或python上实现它,并使用ffmpeg完成视频稳定。

EDIT : I only have stabilized video, don't have access to original video or files produced by ffmpeg. 编辑 :我只有稳定的视频,无法访问原始视频或由ffmpeg生成的文件。

Any help/suggestion is appreciated, 任何帮助/建议表示赞赏,

A pixel (probably) lies on the searched symmetry line if 如果像素(可能)位于搜索的对称线上

  • Its (first/second/thrid/...) left and right point are equal (=> dG , Figure 1 left) 它(第一/第二/第三/ ......)左右点相等(=> dG ,图1左)
  • Its (first/second/thrid/...) left (or right) value is different (=> dGs , Figure 1 middle) 它(第一/第二/第三/ ......)左(或右)值不同(=> dGs ,图1中间)

So, the points of interest are characterised by high values for |dGs| - |dG| 因此,兴趣点的特征是|dGs| - |dG|值高 |dGs| - |dG| (=> dGs_dG , Figure 1 right) (=> dGs_dG ,图1右)

As can be seen on the right image of Figure 1, a lot of false positives still exist. 从图1的右图可以看出,仍然存在许多误报。 Therefore, the Hough transform (Figure 2 left) will be used to detect all the points corresponding to the strongest line (Figure 2 right). 因此,Hough变换(图2左)将用于检测与最强线对应的所有点(图2右)。 The green line is indeed the searched line. 绿线确实是搜索线。

Tuning 调音

  • Changing n : Higher values will discard more false positives, but also excludes n border pixels. 更改n :更高的值会丢弃更多的误报,但也会排除n边框像素。 This can be avoided by using a lower n for the border pixels. 通过使用较低的n作为边界像素可以避免这种情况。

  • Changing thresholds: A higher threshold on dGs_dG will discard more false positives. 更改阈值: dGs_dG上的更高阈值将丢弃更多误报。 Discarding high values of dG may also be interesting to discard edge locations in the original image. 丢弃高dG值对于丢弃原始图像中的边缘位置也可能是有趣的。

  • A priori knowledge of symmetry line: using the definition of the hough transform, you can discard all lines passing through the center part of the image. 对称线的先验知识:使用霍夫变换的定义,您可以丢弃通过图像中心部分的所有线。

在此输入图像描述

在此输入图像描述

The matlab code used to generate the images is: 用于生成图像的matlab代码是:

I = imread('bnuqb.png');
G = int16(rgb2gray(I));

n = 3; % use the first, second and third left/right point
dG = int16(zeros(size(G) - [0 2*n+2]));
dGs = int16(zeros(size(G) - [0 2*n+2]));
for 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;
for k = 1:length(lines)
   xy = [lines(k).point1; lines(k).point2];
   plot(xy(:,1),xy(:,2),'g');
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM