[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54622] trunk/blender/source/blender: Correction to r54600

Sergey Sharybin sergey.vfx at gmail.com
Mon Feb 18 11:12:44 CET 2013


Revision: 54622
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54622
Author:   nazgul
Date:     2013-02-18 10:12:44 +0000 (Mon, 18 Feb 2013)
Log Message:
-----------
Correction to r54600

Calculate dependent area based on distortion model rather than
using 15% of image resolution for this.

Some assumptions here:

- We're assuming real-life camera calibration is used here
- Maximal undistortion delta would be achieved on frame boundary
- Distortion fully goes inside frame

This makes it possible to approximate margin for distortion by
checking undistortion delta across frame boundary and use it
for dependent area of interest.

We do not use any formula-based equation here because we're likely
support other distortion models and in that case it'll be stupid
to try detecting formula here.

Revision Links:
--------------
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54600

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_tracking.h
    trunk/blender/source/blender/blenkernel/intern/tracking.c
    trunk/blender/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_MovieDistortionOperation.h

Modified: trunk/blender/source/blender/blenkernel/BKE_tracking.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_tracking.h	2013-02-18 03:36:10 UTC (rev 54621)
+++ trunk/blender/source/blender/blenkernel/BKE_tracking.h	2013-02-18 10:12:44 UTC (rev 54622)
@@ -46,6 +46,7 @@
 struct Camera;
 struct Object;
 struct Scene;
+struct rcti;
 
 /* **** Common functions **** */
 
@@ -156,6 +157,8 @@
 struct ImBuf *BKE_tracking_distort_frame(struct MovieTracking *tracking, struct ImBuf *ibuf,
                                          int calibration_width, int calibration_height, float overscan);
 
+void BKE_tracking_max_undistortion_delta_across_bound(struct MovieTracking *tracking, struct rcti *rect, float delta[2]);
+
 /* **** Image sampling **** */
 struct ImBuf *BKE_tracking_sample_pattern(int frame_width, int frame_height,
                                           struct ImBuf *struct_ibuf, struct MovieTrackingTrack *track,

Modified: trunk/blender/source/blender/blenkernel/intern/tracking.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/tracking.c	2013-02-18 03:36:10 UTC (rev 54621)
+++ trunk/blender/source/blender/blenkernel/intern/tracking.c	2013-02-18 10:12:44 UTC (rev 54622)
@@ -1605,6 +1605,67 @@
 	                                    calibration_height, overscan, FALSE);
 }
 
+void BKE_tracking_max_undistortion_delta_across_bound(MovieTracking *tracking, rcti *rect, float delta[2])
+{
+	int a;
+	float pos[2], warped_pos[2];
+	const int coord_delta = 5;
+
+	delta[0] = delta[1] = -FLT_MAX;
+
+	for (a = rect->xmin; a <= rect->xmax + coord_delta; a += coord_delta) {
+		if (a > rect->xmax)
+			a = rect->xmax;
+
+		/* bottom edge */
+		pos[0] = a;
+		pos[1] = rect->ymin;
+
+		BKE_tracking_undistort_v2(tracking, pos, warped_pos);
+
+		delta[0] = max_ff(delta[0], fabs(pos[0] - warped_pos[0]));
+		delta[1] = max_ff(delta[1], fabs(pos[1] - warped_pos[1]));
+
+		/* top edge */
+		pos[0] = a;
+		pos[1] = rect->ymax;
+
+		BKE_tracking_undistort_v2(tracking, pos, warped_pos);
+
+		delta[0] = max_ff(delta[0], fabs(pos[0] - warped_pos[0]));
+		delta[1] = max_ff(delta[1], fabs(pos[1] - warped_pos[1]));
+
+		if (a >= rect->xmax)
+			break;
+	}
+
+	for (a = rect->ymin; a <= rect->ymax + coord_delta; a += coord_delta) {
+		if (a > rect->ymax)
+			a = rect->ymax;
+
+		/* left edge */
+		pos[0] = rect->xmin;
+		pos[1] = a;
+
+		BKE_tracking_undistort_v2(tracking, pos, warped_pos);
+
+		delta[0] = max_ff(delta[0], fabs(pos[0] - warped_pos[0]));
+		delta[1] = max_ff(delta[1], fabs(pos[1] - warped_pos[1]));
+
+		/* right edge */
+		pos[0] = rect->xmax;
+		pos[1] = a;
+
+		BKE_tracking_undistort_v2(tracking, pos, warped_pos);
+
+		delta[0] = max_ff(delta[0], fabs(pos[0] - warped_pos[0]));
+		delta[1] = max_ff(delta[1], fabs(pos[1] - warped_pos[1]));
+
+		if (a >= rect->ymax)
+			break;
+	}
+}
+
 /*********************** Image sampling *************************/
 
 static void disable_imbuf_channels(ImBuf *ibuf, MovieTrackingTrack *track, int grayscale)

Modified: trunk/blender/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp	2013-02-18 03:36:10 UTC (rev 54621)
+++ trunk/blender/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp	2013-02-18 10:12:44 UTC (rev 54622)
@@ -75,9 +75,31 @@
 		                                            calibration_width, calibration_height, this->m_distortion);
 		s_cache.push_back(newC);
 		this->m_cache = newC;
+
+		if (this->m_distortion) {
+			float delta[2];
+			rcti full_frame;
+			full_frame.xmin = full_frame.ymin = 0;
+			full_frame.xmax = this->m_width;
+			full_frame.ymax = this->m_height;
+			BKE_tracking_max_undistortion_delta_across_bound(&this->m_movieClip->tracking, &full_frame, delta);
+
+			/* 5 is just in case we didn't hit real max of distortion in
+			 * BKE_tracking_max_undistortion_delta_across_bound
+			 */
+			m_margin[0] = delta[0] + 5;
+			m_margin[1] = delta[1] + 5;
+		}
+		else {
+			/* undistortion with sane distortion coefficients would be mapped inside
+			 * of each tile, should be no need in margin in this case
+			 */
+			m_margin[0] = m_margin[1] = 0;
+		}
 	}
 	else {
 		this->m_cache = NULL;
+		m_margin[0] = m_margin[1] = 0;
 	}
 }
 
@@ -115,13 +137,10 @@
 
 bool MovieDistortionOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
 {
-	const int marginX = this->m_width * 0.15;
-	const int marginY = this->m_height * 0.15;
-
 	rcti newInput;
-	newInput.xmin = input->xmin - marginX;
-	newInput.ymin = input->ymin - marginY;
-	newInput.xmax = input->xmax + marginX;
-	newInput.ymax = input->ymax + marginY;
+	newInput.xmin = input->xmin - m_margin[0];
+	newInput.ymin = input->ymin - m_margin[1];
+	newInput.xmax = input->xmax + m_margin[0];
+	newInput.ymax = input->ymax + m_margin[1];
 	return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
 }

Modified: trunk/blender/source/blender/compositor/operations/COM_MovieDistortionOperation.h
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_MovieDistortionOperation.h	2013-02-18 03:36:10 UTC (rev 54621)
+++ trunk/blender/source/blender/compositor/operations/COM_MovieDistortionOperation.h	2013-02-18 10:12:44 UTC (rev 54622)
@@ -148,6 +148,7 @@
 	DistortionCache *m_cache;
 	SocketReader *m_inputOperation;
 	MovieClip *m_movieClip;
+	int m_margin[2];
 
 protected:
 	bool m_distortion;




More information about the Bf-blender-cvs mailing list