[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40000] branches/soc-2011-tomato/source/ blender: Camera tracking integration
Sergey Sharybin
g.ulairi at gmail.com
Wed Sep 7 10:09:56 CEST 2011
Revision: 40000
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40000
Author: nazgul
Date: 2011-09-07 08:09:56 +0000 (Wed, 07 Sep 2011)
Log Message:
-----------
Camera tracking integration
===========================
- Fix for pixel aspect: solver supposed claibration was made against
aspected image, manual calibration worked in non-aspected image.
- Fixed incorrect usage of sensor size when creating projection matrix
for tracking structure.
Modified Paths:
--------------
branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw.c
Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c 2011-09-07 08:09:50 UTC (rev 39999)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c 2011-09-07 08:09:56 UTC (rev 40000)
@@ -1403,24 +1403,25 @@
void BKE_tracking_projection_matrix(MovieTracking *tracking, int framenr, int winx, int winy, float mat[4][4])
{
MovieReconstructedCamera *camera;
- float lens= tracking->camera.focal*32.0f/(float)winx;
+ float lens= tracking->camera.focal*tracking->camera.sensor_width/(float)winx;
float viewfac, pixsize, left, right, bottom, top, clipsta, clipend;
float winmat[4][4];
+ float ycor= 1.f/tracking->camera.pixel_aspect;
clipsta= 0.1f;
clipend= 1000.0f;
if(winx >= winy)
- viewfac= (lens*winx)/32.0f;
+ viewfac= (lens*winx)/tracking->camera.sensor_width;
else
- viewfac= (lens*winy)/32.0f;
+ viewfac= (ycor*lens*winy)/tracking->camera.sensor_width;
pixsize= clipsta/viewfac;
left= -0.5f*(float)winx*pixsize;
- bottom= -0.5f*(float)winy*pixsize;
+ bottom= -0.5f*ycor*(float)winy*pixsize;
right= 0.5f*(float)winx*pixsize;
- top= 0.5f*(float)winy*pixsize;
+ top= 0.5f*ycor*(float)winy*pixsize;
perspective_m4(winmat, left, right, bottom, top, clipsta, clipend);
@@ -1439,12 +1440,13 @@
#ifdef WITH_LIBMV
double x, y;
+ float aspy= 1.f/tracking->camera.pixel_aspect;
/* normalize coords */
x= (co[0]-camera->principal[0]) / camera->focal;
- y= (co[1]-camera->principal[1]) / camera->focal;
+ y= (co[1]-camera->principal[1] * aspy) / camera->focal;
- libmv_applyCameraIntrinsics(camera->focal, camera->principal[0], camera->principal[1],
+ libmv_applyCameraIntrinsics(camera->focal, camera->principal[0], camera->principal[1] * aspy,
camera->k1, camera->k2, camera->k3, x, y, &x, &y);
/* result is in image coords already */
@@ -1459,12 +1461,13 @@
#ifdef WITH_LIBMV
double x= co[0], y= co[1];
+ float aspy= 1.f/tracking->camera.pixel_aspect;
- libmv_InvertIntrinsics(camera->focal, camera->principal[0], camera->principal[1],
+ libmv_InvertIntrinsics(camera->focal, camera->principal[0], camera->principal[1] * aspy,
camera->k1, camera->k2, camera->k3, x, y, &x, &y);
nco[0]= x * camera->focal + camera->principal[0];
- nco[1]= y * camera->focal + camera->principal[1];
+ nco[1]= y * camera->focal + camera->principal[1] * aspy;
#endif
}
Modified: branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw.c 2011-09-07 08:09:50 UTC (rev 39999)
+++ branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw.c 2011-09-07 08:09:56 UTC (rev 40000)
@@ -872,7 +872,7 @@
glPointSize(3.0f);
aspy= 1.f/clip->tracking.camera.pixel_aspect;
- BKE_tracking_projection_matrix(tracking, framenr, width, height*aspy, mat);
+ BKE_tracking_projection_matrix(tracking, framenr, width, height, mat);
track= tracking->tracks.first;
while(track) {
@@ -886,20 +886,23 @@
mul_v4_m4v4(pos, mat, vec);
pos[0]= (pos[0]/(pos[3]*2.0f)+0.5f)*width;
- pos[1]= (pos[1]/(pos[3]*2.0f)+0.5f)*height;
+ pos[1]= (pos[1]/(pos[3]*2.0f)+0.5f)*height*aspy;
- BKE_tracking_apply_intrinsics(tracking, pos, pos);
+ if(pos[0]>=0.f && pos[1]>=0.f && pos[0]<=width && pos[1]<=height*aspy) {
+ BKE_tracking_apply_intrinsics(tracking, pos, pos);
- vec[0]= (marker->pos[0]+track->offset[0])*width;
- vec[1]= (marker->pos[1]+track->offset[1])*height;
- sub_v2_v2(vec, pos);
+ vec[0]= (marker->pos[0]+track->offset[0])*width;
+ vec[1]= (marker->pos[1]+track->offset[1])*height*aspy;
- if(len_v2(vec)<3) glColor3f(0.0f, 1.0f, 0.0f);
- else glColor3f(1.0f, 0.0f, 0.0f);
+ sub_v2_v2(vec, pos);
- glBegin(GL_POINTS);
- glVertex3f(pos[0]/width, pos[1]/height, 0);
- glEnd();
+ if(len_v2(vec)<3) glColor3f(0.0f, 1.0f, 0.0f);
+ else glColor3f(1.0f, 0.0f, 0.0f);
+
+ glBegin(GL_POINTS);
+ glVertex3f(pos[0]/width, pos[1]/(height*aspy), 0);
+ glEnd();
+ }
}
}
@@ -939,8 +942,9 @@
const int n= 10;
int i, j, a;
float pos[2], tpos[2], grid[11][11][2];
- float dx= (float)width/n, dy= (float)height/n;
MovieTracking *tracking= &clip->tracking;
+ float aspy= 1.f/tracking->camera.pixel_aspect;
+ float dx= (float)width/n, dy= (float)height/n*aspy;
if(sc->mode!=SC_MODE_DISTORTION)
return;
@@ -1016,7 +1020,7 @@
BKE_tracking_apply_intrinsics(tracking, pos, grid[i][j]);
grid[i][j][0]/= width;
- grid[i][j][1]/= height;
+ grid[i][j][1]/= height*aspy;
pos[0]+= dx;
}
@@ -1066,10 +1070,10 @@
int steps;
pos[0]= stroke->points[i].x*width;
- pos[1]= stroke->points[i].y*height;
+ pos[1]= stroke->points[i].y*height*aspy;
npos[0]= stroke->points[i+1].x*width;
- npos[1]= stroke->points[i+1].y*height;
+ npos[1]= stroke->points[i+1].y*height*aspy;
len= len_v2v2(pos, npos);
steps= ceil(len/5.f);
@@ -1085,7 +1089,7 @@
for(j= 0; j<steps; j++) {
BKE_tracking_apply_intrinsics(tracking, pos, tpos);
- glVertex2f(tpos[0]/width, tpos[1]/height);
+ glVertex2f(tpos[0]/width, tpos[1]/(height*aspy));
add_v2_v2(pos, dpos);
}
More information about the Bf-blender-cvs
mailing list