[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [44788] trunk/blender/source/blender/ blenkernel/intern/tracking.c: Finally 2D stabilization auto scale factor should be calculated perfectly
Sergey Sharybin
sergey.vfx at gmail.com
Sat Mar 10 17:31:13 CET 2012
Revision: 44788
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44788
Author: nazgul
Date: 2012-03-10 16:31:12 +0000 (Sat, 10 Mar 2012)
Log Message:
-----------
Finally 2D stabilization auto scale factor should be calculated perfectly
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/intern/tracking.c
Modified: trunk/blender/source/blender/blenkernel/intern/tracking.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/tracking.c 2012-03-10 16:21:48 UTC (rev 44787)
+++ trunk/blender/source/blender/blenkernel/intern/tracking.c 2012-03-10 16:31:12 UTC (rev 44788)
@@ -2487,12 +2487,14 @@
MovieTrackingStabilization *stab= &tracking->stabilization;
float aspect= tracking->camera.pixel_aspect;
+ printf("\n%s\n", __func__);
+
if(stab->ok)
return stab->scale;
if(stabilization_median_point(tracking, 1, firstmedian)) {
int sfra= INT_MAX, efra= INT_MIN, cfra;
- float scalex= 1.0f, scaley= 1.0f;
+ float scale= 1.0f;
MovieTrackingTrack *track;
stab->scale= 1.0f;
@@ -2510,18 +2512,24 @@
for(cfra=sfra; cfra<=efra; cfra++) {
float median[2];
- float loc[2], scale, angle;
+ float loc[2], angle, tmp_scale;
int i;
float mat[4][4];
float points[4][2]={{0.0f, 0.0f}, {0.0f, height}, {width, height}, {width, 0.0f}};
+ float si, co;
+ if(cfra != 208)
+ continue;
+
stabilization_median_point(tracking, cfra, median);
- calculate_stabdata(tracking, cfra, width, height, firstmedian, median,
- loc, &scale, &angle);
+ calculate_stabdata(tracking, cfra, width, height, firstmedian, median, loc, &tmp_scale, &angle);
- BKE_tracking_stabdata_to_mat4(width, height, aspect, loc, scale, angle, mat);
+ BKE_tracking_stabdata_to_mat4(width, height, aspect, loc, 1.0f, angle, mat);
+ si = sin(angle);
+ co = cos(angle);
+
for(i= 0; i<4; i++) {
int j;
float a[3]= {0.0f, 0.0f, 0.0f}, b[3]= {0.0f, 0.0f, 0.0f};
@@ -2540,21 +2548,48 @@
sub_v3_v3v3(v2, point, a);
if(cross_v2v2(v1, v2) >= 0.0f) {
- float dist= dist_to_line_v2(point, a, b), cur_scale;
+ const float rotDx[4][2] = {{1.0f, 0.0f}, {0.0f, -1.0f}, {-1.0f, 0.0f}, {0.0f, 1.0f}};
+ const float rotDy[4][2] = {{0.0f, 1.0f}, {1.0f, 0.0f}, {0.0f, -1.0f}, {-1.0f, 0.0f}};
- if(i%2==0) {
- cur_scale= 0.5f * (float)width / (0.5f * (float)width - dist);
- scalex= MAX2(scalex, cur_scale);
- } else {
- cur_scale= 0.5f * (float)height / (0.5f * (float)height - dist);
- scaley= MAX2(scaley, cur_scale);
+ float dx = loc[0] * rotDx[j][0] + loc[1] * rotDx[j][1],
+ dy = loc[0] * rotDy[j][0] + loc[1] * rotDy[j][1];
+
+ float w, h, E, F, G, H, I, J, K, S;
+
+ if(j % 2) {
+ w = (float)height / 2.0f;
+ h = (float)width / 2.0f;
}
+ else {
+ w = (float)width / 2.0f;
+ h = (float)height / 2.0f;
+ }
+
+ E = -w*co + h*si;
+ F = -h*co - w*si;
+
+ if ((i % 2) == (j % 2)) {
+ G = -w*co - h*si;
+ H = h*co - w*si;
+ }
+ else {
+ G = w*co + h*si;
+ H = -h*co + w*si;
+ }
+
+ I = F - H;
+ J = G - E;
+ K = G*F - E*H;
+
+ S = (-w*I - h*J) / (dx*I + dy*J + K);
+
+ scale = MAX2(scale, S);
}
}
}
}
- stab->scale= MAX2(scalex, scaley);
+ stab->scale= scale;
if(stab->maxscale>0.0f)
stab->scale= MIN2(stab->scale, stab->maxscale);
More information about the Bf-blender-cvs
mailing list