Merging r42394 through r42412 form trunk into soc-2011-tomato
authorSergey Sharybin <sergey.vfx@gmail.com>
Sun, 4 Dec 2011 17:26:35 +0000 (17:26 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Sun, 4 Dec 2011 17:26:35 +0000 (17:26 +0000)
14 files changed:
extern/libmv/libmv-capi.cpp
extern/libmv/libmv-capi.h
extern/libmv/libmv/numeric/tinyvector.cc [new file with mode: 0644]
extern/libmv/libmv/tracking/brute_region_tracker.cc
extern/libmv/libmv/tracking/esm_region_tracker.cc
extern/libmv/libmv/tracking/esm_region_tracker.h
extern/libmv/third_party/ssba/README.libmv [changed mode: 0644->0755]
intern/ghost/intern/GHOST_System.cpp
release/scripts/presets/camera/Nikon_D35.py [new file with mode: 0644]
release/scripts/startup/bl_ui/space_clip.py
source/blender/blenkernel/intern/tracking.c
source/blender/editors/interface/interface_draw.c
source/blender/makesdna/DNA_tracking_types.h
source/blender/makesrna/intern/rna_tracking.c

index ed89f8cbfb3e089fbaad6d9a5581ea8b0db6a0eb..e83a826e640d793132555c1937442717b2cf918c 100644 (file)
@@ -111,12 +111,13 @@ void libmv_setLoggingVerbosity(int verbosity)
 
 /* ************ RegionTracker ************ */
 
-libmv_RegionTracker *libmv_pyramidRegionTrackerNew(int max_iterations, int pyramid_level, int half_window_size)
+libmv_RegionTracker *libmv_pyramidRegionTrackerNew(int max_iterations, int pyramid_level, int half_window_size, double minimum_correlation)
 {
        libmv::EsmRegionTracker *esm_region_tracker = new libmv::EsmRegionTracker;
        esm_region_tracker->half_window_size = half_window_size;
        esm_region_tracker->max_iterations = max_iterations;
        esm_region_tracker->min_determinant = 1e-4;
+       esm_region_tracker->minimum_correlation = minimum_correlation;
 
        libmv::PyramidRegionTracker *pyramid_region_tracker =
                new libmv::PyramidRegionTracker(esm_region_tracker, pyramid_level);
@@ -124,12 +125,13 @@ libmv_RegionTracker *libmv_pyramidRegionTrackerNew(int max_iterations, int pyram
        return (libmv_RegionTracker *)pyramid_region_tracker;
 }
 
-libmv_RegionTracker *libmv_hybridRegionTrackerNew(int max_iterations, int half_window_size)
+libmv_RegionTracker *libmv_hybridRegionTrackerNew(int max_iterations, int half_window_size, double minimum_correlation)
 {
        libmv::EsmRegionTracker *esm_region_tracker = new libmv::EsmRegionTracker;
        esm_region_tracker->half_window_size = half_window_size;
        esm_region_tracker->max_iterations = max_iterations;
        esm_region_tracker->min_determinant = 1e-4;
+       esm_region_tracker->minimum_correlation = minimum_correlation;
 
        libmv::BruteRegionTracker *brute_region_tracker = new libmv::BruteRegionTracker;
   brute_region_tracker->half_window_size = half_window_size;
index c5e61d69c56cdd2180e6faaabf250ad1147780b3..e10d4ef842ae3d80bddc1cb187b06275249f3344 100644 (file)
@@ -43,8 +43,8 @@ void libmv_startDebugLogging(void);
 void libmv_setLoggingVerbosity(int verbosity);
 
 /* RegionTracker */
-struct libmv_RegionTracker *libmv_pyramidRegionTrackerNew(int max_iterations, int pyramid_level, int half_window_size);
-struct libmv_RegionTracker *libmv_hybridRegionTrackerNew(int max_iterations, int half_window_size);
+struct libmv_RegionTracker *libmv_pyramidRegionTrackerNew(int max_iterations, int pyramid_level, int half_window_size, double minimum_correlation);
+struct libmv_RegionTracker *libmv_hybridRegionTrackerNew(int max_iterations, int half_window_size, double minimum_correlation);
 int libmv_regionTrackerTrack(struct libmv_RegionTracker *libmv_tracker, const float *ima1, const float *ima2,
                        int width, int height, double  x1, double  y1, double *x2, double *y2);
 void libmv_regionTrackerDestroy(struct libmv_RegionTracker *libmv_tracker);
diff --git a/extern/libmv/libmv/numeric/tinyvector.cc b/extern/libmv/libmv/numeric/tinyvector.cc
new file mode 100644 (file)
index 0000000..e69de29
index c33432b7fd7492b7df90dad18b8ec8258ec715ad..29b0fc5ff38af972664b5a935990f5434a165393 100644 (file)
 
 #ifndef __APPLE__
 // Needed for memalign on Linux and _aligned_alloc on Windows.
-#ifdef FREE_WINDOWS
-/* make sure _aligned_malloc is included */
-#ifdef __MSVCRT_VERSION__
-#undef __MSVCRT_VERSION__
-#endif
-
-#define __MSVCRT_VERSION__ 0x0700
-#endif
-
 #include <malloc.h>
 #else
 // Apple's malloc is 16-byte aligned, and does not have malloc.h, so include
index 844b5ff3cb9853e52110f341db4eb3845551675e..9784b61c0684fb615a4c8650cc6b171865029583 100644 (file)
@@ -273,10 +273,30 @@ bool EsmRegionTracker::Track(const FloatImage &image1,
 
     // If the step was accepted, then check for termination.
     if (d.squaredNorm() < min_update_squared_distance) {
-      if (new_error > reasonable_error) {
-        LG << "Update size shrank but reasonable error ("
-           << reasonable_error << ") not achieved; failing.";
-        return true; // XXX
+      // Compute the Pearson product-moment correlation coefficient to check
+      // for sanity.
+      // TODO(keir): Put this somewhere smarter.
+      double sX=0,sY=0,sXX=0,sYY=0,sXY=0;
+      for (int r = 0; r < width; ++r) {
+        for (int c = 0; c < width; ++c) {
+          double x = image_and_gradient1_sampled(r, c, 0);
+          double y = image_and_gradient2_sampled[new_image](r, c, 0);
+          sX += x;
+          sY += y;
+          sXX += x*x;
+          sYY += y*y;
+          sXY += x*y;
+        }
+      }
+      double N = width*width;
+      sX /= N, sY /= N, sXX /= N, sYY /= N, sXY /= N;
+      double correlation = (sXY-sX*sY)/sqrt(double((sXX-sX*sX)*(sYY-sY*sY)));
+      LG << "Final correlation: " << correlation;
+
+      if (correlation < minimum_correlation) {
+        LG << "Correlation " << correlation << " greater than "
+           << minimum_correlation << "; bailing.";
+        return false;
       }
       LG << "Successful track in " << (i + 1) << " iterations.";
       return true;
index c63417201ad8058b975fe2ef8b7a8d7432a82080..602b32f16754c7836714182109fe558401f92e97 100644 (file)
@@ -38,7 +38,8 @@ struct EsmRegionTracker : public RegionTracker {
         max_iterations(16),
         min_determinant(1e-6),
         min_update_squared_distance(1e-4),
-        sigma(0.9) {}
+        sigma(0.9),
+        minimum_correlation(0.78) {}
   
   virtual ~EsmRegionTracker() {}
 
@@ -54,6 +55,7 @@ struct EsmRegionTracker : public RegionTracker {
   double min_determinant;
   double min_update_squared_distance;
   double sigma;
+  double minimum_correlation;
 };
 
 }  // namespace libmv
old mode 100644 (file)
new mode 100755 (executable)
index 839e014aff6d4fbad16ffcbfad3cd5e9373a1741..afc54d3c6a025139d33653365a29cf116decf3be 100644 (file)
@@ -136,7 +136,7 @@ bool GHOST_System::validWindow(GHOST_IWindow* window)
 
 
 GHOST_TSuccess GHOST_System::beginFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow** window,
-                                                                                        const bool stereoVisual, const GHOST_TUns16 numOfAASamples)
+                                                                                        const bool stereoVisual)
 {
        GHOST_TSuccess success = GHOST_kFailure;
        GHOST_ASSERT(m_windowManager, "GHOST_System::beginFullScreen(): invalid window manager")
@@ -148,7 +148,7 @@ GHOST_TSuccess GHOST_System::beginFullScreen(const GHOST_DisplaySetting& setting
                        success = m_displayManager->setCurrentDisplaySetting(GHOST_DisplayManager::kMainDisplay, setting);
                        if (success == GHOST_kSuccess) {
                                //GHOST_PRINT("GHOST_System::beginFullScreen(): creating full-screen window\n");
-                               success = createFullScreenWindow((GHOST_Window**)window, stereoVisual, numOfAASamples);
+                               success = createFullScreenWindow((GHOST_Window**)window, stereoVisual);
                                if (success == GHOST_kSuccess) {
                                        m_windowManager->beginFullScreen(*window, stereoVisual);
                                }
@@ -330,7 +330,7 @@ GHOST_TSuccess GHOST_System::exit()
 }
 
 
-GHOST_TSuccess GHOST_System::createFullScreenWindow(GHOST_Window** window, const bool stereoVisual, const GHOST_TUns16 numOfAASamples)
+GHOST_TSuccess GHOST_System::createFullScreenWindow(GHOST_Window** window, const bool stereoVisual)
 {
        GHOST_TSuccess success;
        GHOST_ASSERT(m_displayManager, "GHOST_System::createFullScreenWindow(): invalid display manager")
@@ -344,8 +344,7 @@ GHOST_TSuccess GHOST_System::createFullScreenWindow(GHOST_Window** window, const
                                        0, 0, settings.xPixels, settings.yPixels,
                                        GHOST_kWindowStateFullScreen,
                                        GHOST_kDrawingContextTypeOpenGL,
-                                       stereoVisual,
-                                       numOfAASamples);
+                                       stereoVisual);
                success = *window == 0 ? GHOST_kFailure : GHOST_kSuccess;
        }
        return success;
diff --git a/release/scripts/presets/camera/Nikon_D35.py b/release/scripts/presets/camera/Nikon_D35.py
new file mode 100644 (file)
index 0000000..e6dc62d
--- /dev/null
@@ -0,0 +1,4 @@
+import bpy
+bpy.context.object.data.sensor_width = 36.0
+bpy.context.object.data.sensor_height = 23.9
+bpy.context.object.data.sensor_fit = 'HORIZONTAL'
index 5cdd1de547f4874c1165ee62243f74941f93868b..c7511174e988fe3a179c9ae7ab5fad63723c6720 100644 (file)
@@ -129,8 +129,7 @@ class CLIP_PT_tools_marker(Panel):
 
             if settings.default_tracker == 'KLT':
                 col.prop(settings, "default_pyramid_levels")
-            elif settings.default_tracker == 'SAD':
-                col.prop(settings, "default_correlation_min")
+            col.prop(settings, "default_correlation_min")
 
             col.separator()
 
@@ -353,9 +352,15 @@ class CLIP_PT_track(Panel):
         layout.template_track(sc, "scopes")
 
         row = layout.row(align=True)
-        row.prop(act_track, "use_red_channel", text="R", toggle=True)
-        row.prop(act_track, "use_green_channel", text="G", toggle=True)
-        row.prop(act_track, "use_blue_channel", text="B", toggle=True)
+        sub = row.row()
+        sub.prop(act_track, "use_red_channel", text="R", toggle=True)
+        sub.prop(act_track, "use_green_channel", text="G", toggle=True)
+        sub.prop(act_track, "use_blue_channel", text="B", toggle=True)
+
+        row.separator()
+
+        sub = row.row()
+        sub.prop(act_track, "use_grayscale_preview", text="B/W", toggle=True)
 
         layout.separator()
 
@@ -497,8 +502,7 @@ class CLIP_PT_track_settings(Panel):
 
             if active.tracker == 'KLT':
                 col.prop(active, "pyramid_levels")
-            elif active.tracker == 'SAD':
-                col.prop(active, "correlation_min")
+            col.prop(active, "correlation_min")
 
             col.separator()
             col.prop(active, "frames_limit")
index 4b5dc917cb6b49f4482459f9e5c0be6131a18e36..60d5c19bff73807bfb31a12c283da94abb467024 100644 (file)
@@ -77,7 +77,6 @@ void BKE_tracking_init_settings(MovieTracking *tracking)
        tracking->camera.units= CAMERA_UNITS_MM;
 
        tracking->settings.default_tracker= TRACKER_KLT;
-       tracking->settings.default_pyramid_levels= 2;
        tracking->settings.default_minimum_correlation= 0.75;
        tracking->settings.default_pattern_size= 11;
        tracking->settings.default_search_size= 51;
@@ -810,9 +809,9 @@ MovieTrackingContext *BKE_tracking_context_new(MovieClip *clip, MovieClipUser *u
                                                        int level= MIN2(track->pyramid_levels, max_pyramid_levels);
 
                                                        if(track->tracker==TRACKER_KLT)
-                                                               track_context.region_tracker= libmv_pyramidRegionTrackerNew(100, level, MAX2(wndx, wndy));
+                                                               track_context.region_tracker= libmv_pyramidRegionTrackerNew(100, level, MAX2(wndx, wndy), track->minimum_correlation);
                                                        else
-                                                               track_context.region_tracker= libmv_hybridRegionTrackerNew(100, MAX2(wndx, wndy));
+                                                               track_context.region_tracker= libmv_hybridRegionTrackerNew(100, MAX2(wndx, wndy), track->minimum_correlation);
                                                }
                                                else if(track->tracker==TRACKER_SAD) {
                                                        track_context.pattern_size= MAX2(patx, paty);
@@ -862,29 +861,53 @@ void BKE_tracking_context_free(MovieTrackingContext *context)
        MEM_freeN(context);
 }
 
-static void disable_imbuf_channels(ImBuf *ibuf, MovieTrackingTrack *track)
+/* zap channels from the imbuf that are disabled by the user. this can lead to
+ * better tracks sometimes. however, instead of simply zeroing the channels
+ * out, do a partial grayscale conversion so the display is better. */
+static void disable_imbuf_channels(ImBuf *ibuf, MovieTrackingTrack *track, int grayscale)
 {
        int x, y;
+       float scale;
 
-       if((track->flag&(TRACK_DISABLE_RED|TRACK_DISABLE_GREEN|TRACK_DISABLE_BLUE))==0)
+       if((track->flag&(TRACK_DISABLE_RED|TRACK_DISABLE_GREEN|TRACK_DISABLE_BLUE))==0 && !grayscale)
                return;
 
+       /* If only some components are selected, it's important to rescale the result
+        * appropriately so that e.g. if only blue is selected, it's not zeroed out. */
+       scale = ((track->flag&TRACK_DISABLE_RED  ) ? 0.0f : 0.2126f) +
+               ((track->flag&TRACK_DISABLE_GREEN) ? 0.0f : 0.7152f) +
+               ((track->flag&TRACK_DISABLE_BLUE)  ? 0.0f : 0.0722f);
+
        for(y= 0; y<ibuf->y; y++) {
                for (x= 0; x<ibuf->x; x++) {
                        int pixel= ibuf->x*y + x;
 
                        if(ibuf->rect_float) {
                                float *rrgbf= ibuf->rect_float + pixel*4;
-
-                               if(track->flag&TRACK_DISABLE_RED)       rrgbf[0]= 0;
-                               if(track->flag&TRACK_DISABLE_GREEN)     rrgbf[1]= 0;
-                               if(track->flag&TRACK_DISABLE_BLUE)      rrgbf[2]= 0;
+                               float r = (track->flag&TRACK_DISABLE_RED)   ? 0.0f : rrgbf[0];
+                               float g = (track->flag&TRACK_DISABLE_GREEN) ? 0.0f : rrgbf[1];
+                               float b = (track->flag&TRACK_DISABLE_BLUE)  ? 0.0f : rrgbf[2];
+                               if (grayscale) {
+                                       float gray = (0.2126f*r + 0.7152f*g + 0.0722f*b) / scale;
+                                       rrgbf[0] = rrgbf[1] = rrgbf[2] = gray;
+                               } else {
+                                       rrgbf[0] = r;
+                                       rrgbf[1] = g;
+                                       rrgbf[2] = b;
+                               }
                        } else {
                                char *rrgb= (char*)ibuf->rect + pixel*4;
-
-                               if(track->flag&TRACK_DISABLE_RED)       rrgb[0]= 0;
-                               if(track->flag&TRACK_DISABLE_GREEN)     rrgb[1]= 0;
-                               if(track->flag&TRACK_DISABLE_BLUE)      rrgb[2]= 0;
+                               char r = (track->flag&TRACK_DISABLE_RED)   ? 0 : rrgb[0];
+                               char g = (track->flag&TRACK_DISABLE_GREEN) ? 0 : rrgb[1];
+                               char b = (track->flag&TRACK_DISABLE_BLUE)  ? 0 : rrgb[2];
+                               if (grayscale) {
+                                       float gray = (0.2126f*r + 0.7152f*g + 0.0722f*b) / scale;
+                                       rrgb[0] = rrgb[1] = rrgb[2] = gray;
+                               } else {
+                                       rrgb[0] = r;
+                                       rrgb[1] = g;
+                                       rrgb[2] = b;
+                               }
                        }
                }
        }
@@ -926,7 +949,12 @@ static ImBuf *get_area_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTracki
                origin[1]= y1-margin;
        }
 
-       disable_imbuf_channels(tmpibuf, track);
+       if ((track->flag & TRACK_PREVIEW_GRAYSCALE) ||
+                       (track->flag & TRACK_DISABLE_RED)       ||
+                       (track->flag & TRACK_DISABLE_GREEN)     ||
+                       (track->flag & TRACK_DISABLE_BLUE) ) {
+               disable_imbuf_channels(tmpibuf, track, 1 /* grayscale */);
+       }
 
        return tmpibuf;
 }
@@ -955,7 +983,7 @@ static float *get_search_floatbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieT
        height= (track->search_max[1]-track->search_min[1])*ibuf->y;
 
        tmpibuf= BKE_tracking_get_search_imbuf(ibuf, track, marker, 0, 0, pos, origin);
-       disable_imbuf_channels(tmpibuf, track);
+       disable_imbuf_channels(tmpibuf, track, 0 /* don't grayscale */);
 
        *width_r= width;
        *height_r= height;
@@ -967,14 +995,11 @@ static float *get_search_floatbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieT
 
                        if(tmpibuf->rect_float) {
                                float *rrgbf= tmpibuf->rect_float + pixel*4;
-
                                *fp= 0.2126*rrgbf[0] + 0.7152*rrgbf[1] + 0.0722*rrgbf[2];
                        } else {
                                unsigned char *rrgb= (unsigned char*)tmpibuf->rect + pixel*4;
-
                                *fp= (0.2126*rrgb[0] + 0.7152*rrgb[1] + 0.0722*rrgb[2])/255.0f;
                        }
-
                        fp++;
                }
        }
@@ -996,14 +1021,11 @@ static unsigned char *get_ucharbuf(ImBuf *ibuf)
 
                        if(ibuf->rect_float) {
                                float *rrgbf= ibuf->rect_float + pixel*4;
-
                                *cp= FTOCHAR(0.2126f*rrgbf[0] + 0.7152f*rrgbf[1] + 0.0722f*rrgbf[2]);
                        } else {
                                unsigned char *rrgb= (unsigned char*)ibuf->rect + pixel*4;
-
                                *cp= 0.2126f*rrgb[0] + 0.7152f*rrgb[1] + 0.0722f*rrgb[2];
                        }
-
                        cp++;
                }
        }
@@ -1018,7 +1040,7 @@ static unsigned char *get_search_bytebuf(ImBuf *ibuf, MovieTrackingTrack *track,
        unsigned char *pixels;
 
        tmpibuf= BKE_tracking_get_search_imbuf(ibuf, track, marker, 0, 0, pos, origin);
-       disable_imbuf_channels(tmpibuf, track);
+       disable_imbuf_channels(tmpibuf, track, 0 /* don't grayscale */);
 
        *width_r= tmpibuf->x;
        *height_r= tmpibuf->y;
index da94fd9237a8967c21b2153f67fc6e5c540863c3..12187283470e78002c3b09e28427f2c7429c568c 100644 (file)
@@ -1475,18 +1475,18 @@ static ImBuf *scale_trackpreview_ibuf(ImBuf *ibuf, float zoomx, float zoomy)
 {
        ImBuf *scaleibuf;
        int x, y, w= ibuf->x*zoomx, h= ibuf->y*zoomy;
+
        scaleibuf= IMB_allocImBuf(w, h, 32, IB_rect);
 
        for(y= 0; y<scaleibuf->y; y++) {
                for (x= 0; x<scaleibuf->x; x++) {
-                       int pixel= scaleibuf->x*y + x;
-                       int orig_pixel= ibuf->x*(int)(((float)y)/zoomy) + (int)(((float)x)/zoomx);
-                       char *rrgb= (char*)scaleibuf->rect + pixel*4;
-                       char *orig_rrgb= (char*)ibuf->rect + orig_pixel*4;
-                       rrgb[0]= orig_rrgb[0];
-                       rrgb[1]= orig_rrgb[1];
-                       rrgb[2]= orig_rrgb[2];
-                       rrgb[3]= orig_rrgb[3];
+                       float src_x= ((float)x)/zoomx;
+                       float src_y= ((float)y)/zoomy;
+
+                       CLAMP(src_x, 0, ibuf->x-1.0f);
+                       CLAMP(src_y, 0, ibuf->y-1.0f);
+
+                       bilinear_interpolation(ibuf, scaleibuf, src_x, src_y, x, y);
                }
        }
 
index 82ccbf87c0b5508875332b6da78e6d3e9ca56727..9058e82b36722a2b3cf8cc2607c36285b78b3ff6 100644 (file)
@@ -207,6 +207,7 @@ enum {
 #define TRACK_LOCKED           (1<<6)
 #define TRACK_CUSTOMCOLOR      (1<<7)
 #define TRACK_USE_2D_STAB      (1<<8)
+#define TRACK_PREVIEW_GRAYSCALE        (1<<9)
 
 /* MovieTrackingTrack->tracker */
 #define TRACKER_KLT            0
index 5a2ef54cfc1ef8b1d28486b67e4f678650246a49..f06c020400d3688247f18567b4de6d3cd72a9cbb 100644 (file)
@@ -673,6 +673,12 @@ static void rna_def_trackingTrack(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Use Blue Channel", "Use blue channel from footage for tracking");
        RNA_def_property_update(prop, NC_MOVIECLIP|ND_DISPLAY, NULL);
 
+       /* preview_grayscale */
+       prop= RNA_def_property(srna, "use_grayscale_preview", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACK_PREVIEW_GRAYSCALE);
+       RNA_def_property_ui_text(prop, "Grayscale", "Display what the tracking algorithm sees in the preview");
+       RNA_def_property_update(prop, NC_MOVIECLIP|ND_DISPLAY, NULL);
+
        /* has bundle */
        prop= RNA_def_property(srna, "has_bundle", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACK_HAS_BUNDLE);