[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41039] branches/soc-2011-tomato: Camera tracking integration
Sergey Sharybin
g.ulairi at gmail.com
Sat Oct 15 21:30:51 CEST 2011
Revision: 41039
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41039
Author: nazgul
Date: 2011-10-15 19:30:51 +0000 (Sat, 15 Oct 2011)
Log Message:
-----------
Camera tracking integration
===========================
Some improvements for feature detectors:
- Sort features by score when filtering features by
distance using FAST library.
- Added option to place markers only in areas outlined
by grease pencil.
Modified Paths:
--------------
branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/detect.cc
branches/soc-2011-tomato/extern/libmv/patches/detect.patch
branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h
branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c
Modified: branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/detect.cc
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/detect.cc 2011-10-15 19:20:34 UTC (rev 41038)
+++ branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/detect.cc 2011-10-15 19:30:51 UTC (rev 41039)
@@ -35,6 +35,14 @@
typedef unsigned int uint;
+int featurecmp(const void *a_v, const void *b_v)
+{
+ Feature *a = (Feature*)a_v;
+ Feature *b = (Feature*)b_v;
+
+ return b->score - a->score;
+}
+
std::vector<Feature> DetectFAST(const unsigned char* data, int width, int height, int stride,
int min_trackness, int min_distance) {
std::vector<Feature> features;
@@ -54,21 +62,43 @@
// TODO(MatthiasF): A resolution independent parameter would be better than distance
// e.g. a coefficient going from 0 (no minimal distance) to 1 (optimal circle packing)
// FIXME(MatthiasF): this method will not necessarily give all maximum markers
- if(num_features) features.reserve(num_features);
- for(int i = 0; i < num_features; ++i) {
- xy xy = nonmax[i];
- Feature a = { xy.x, xy.y, scores[i], 7 };
- // compare each feature against filtered set
- for(int j = 0; j < features.size(); j++) {
- Feature& b = features[j];
- if ( (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y) < min_distance*min_distance ) {
- // already a nearby feature
- goto skip;
+ if(num_features) {
+ Feature *all_features = new Feature[num_features];
+
+ for(int i = 0; i < num_features; ++i) {
+ Feature a = { nonmax[i].x, nonmax[i].y, scores[i], 0 };
+ all_features[i] = a;
+ }
+
+ qsort((void *)all_features, num_features, sizeof(Feature), featurecmp);
+
+ features.reserve(num_features);
+
+ int prev_score = all_features[0].score;
+ for(int i = 0; i < num_features; ++i) {
+ bool ok = true;
+ Feature a = all_features[i];
+ if(a.score>prev_score)
+ abort();
+ prev_score = a.score;
+
+ // compare each feature against filtered set
+ for(int j = 0; j < features.size(); j++) {
+ Feature& b = features[j];
+ if ( (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y) < min_distance*min_distance ) {
+ // already a nearby feature
+ ok = false;
+ break;
+ }
}
+
+ if(ok) {
+ // add the new feature
+ features.push_back(a);
+ }
}
- // otherwise add the new feature
- features.push_back(a);
- skip: ;
+
+ delete [] all_features;
}
free(scores);
free(nonmax);
Modified: branches/soc-2011-tomato/extern/libmv/patches/detect.patch
===================================================================
--- branches/soc-2011-tomato/extern/libmv/patches/detect.patch 2011-10-15 19:20:34 UTC (rev 41038)
+++ branches/soc-2011-tomato/extern/libmv/patches/detect.patch 2011-10-15 19:30:51 UTC (rev 41039)
@@ -1,8 +1,8 @@
diff --git a/src/libmv/simple_pipeline/detect.cc b/src/libmv/simple_pipeline/detect.cc
-index 6fc0cdd..b316f42 100644
+index 6fc0cdd..8ac42ab 100644
--- a/src/libmv/simple_pipeline/detect.cc
+++ b/src/libmv/simple_pipeline/detect.cc
-@@ -23,15 +23,59 @@
+@@ -23,15 +23,89 @@
****************************************************************************/
#include "libmv/simple_pipeline/detect.h"
@@ -19,6 +19,14 @@
typedef unsigned int uint;
++int featurecmp(const void *a_v, const void *b_v)
++{
++ Feature *a = (Feature*)a_v;
++ Feature *b = (Feature*)b_v;
++
++ return b->score - a->score;
++}
++
+std::vector<Feature> DetectFAST(const unsigned char* data, int width, int height, int stride,
+ int min_trackness, int min_distance) {
+ std::vector<Feature> features;
@@ -38,21 +46,43 @@
+ // TODO(MatthiasF): A resolution independent parameter would be better than distance
+ // e.g. a coefficient going from 0 (no minimal distance) to 1 (optimal circle packing)
+ // FIXME(MatthiasF): this method will not necessarily give all maximum markers
-+ if(num_features) features.reserve(num_features);
-+ for(int i = 0; i < num_features; ++i) {
-+ xy xy = nonmax[i];
-+ Feature a = { xy.x, xy.y, scores[i], 7 };
-+ // compare each feature against filtered set
-+ for(int j = 0; j < features.size(); j++) {
-+ Feature& b = features[j];
-+ if ( (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y) < min_distance*min_distance ) {
-+ // already a nearby feature
-+ goto skip;
++ if(num_features) {
++ Feature *all_features = new Feature[num_features];
++
++ for(int i = 0; i < num_features; ++i) {
++ Feature a = { nonmax[i].x, nonmax[i].y, scores[i], 0 };
++ all_features[i] = a;
++ }
++
++ qsort((void *)all_features, num_features, sizeof(Feature), featurecmp);
++
++ features.reserve(num_features);
++
++ int prev_score = all_features[0].score;
++ for(int i = 0; i < num_features; ++i) {
++ bool ok = true;
++ Feature a = all_features[i];
++ if(a.score>prev_score)
++ abort();
++ prev_score = a.score;
++
++ // compare each feature against filtered set
++ for(int j = 0; j < features.size(); j++) {
++ Feature& b = features[j];
++ if ( (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y) < min_distance*min_distance ) {
++ // already a nearby feature
++ ok = false;
++ break;
++ }
+ }
++
++ if(ok) {
++ // add the new feature
++ features.push_back(a);
++ }
+ }
-+ // otherwise add the new feature
-+ features.push_back(a);
-+ skip: ;
++
++ delete [] all_features;
+ }
+ free(scores);
+ free(nonmax);
@@ -64,7 +94,7 @@
static uint SAD(const ubyte* imageA, const ubyte* imageB, int strideA, int strideB) {
__m128i a = _mm_setzero_si128();
for(int i = 0; i < 16; i++) {
-@@ -52,7 +96,7 @@ static uint SAD(const ubyte* imageA, const ubyte* imageB, int strideA, int strid
+@@ -52,7 +126,7 @@ static uint SAD(const ubyte* imageA, const ubyte* imageB, int strideA, int strid
}
#endif
Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h 2011-10-15 19:20:34 UTC (rev 41038)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h 2011-10-15 19:30:51 UTC (rev 41039)
@@ -34,6 +34,7 @@
* \author Sergey Sharybin
*/
+struct bGPDlayer;
struct ImBuf;
struct MovieTrackingTrack;
struct MovieTrackingMarker;
@@ -87,8 +88,12 @@
void BKE_tracking_apply_intrinsics(struct MovieTracking *tracking, float co[2], float nco[2]);
void BKE_tracking_invert_intrinsics(struct MovieTracking *tracking, float co[2], float nco[2]);
-void BKE_tracking_detect(struct MovieTracking *tracking, struct ImBuf *imbuf, int framenr, int margin, int min_trackness, int count, int min_distance, int fast);
+void BKE_tracking_detect_fast(struct MovieTracking *tracking, struct ImBuf *imbuf,
+ int framenr, int margin, int min_trackness, int min_distance, struct bGPDlayer *layer);
+void BKE_tracking_detect_moravec(struct MovieTracking *tracking, struct ImBuf *imbuf,
+ int framenr, int margin, int count, int min_distance, struct bGPDlayer *layer);
+
struct MovieTrackingTrack *BKE_tracking_indexed_bundle(struct MovieTracking *tracking, int bundlenr);
void BKE_tracking_stabilization_data(struct MovieTracking *tracking, int framenr, int width, int height, float loc[2], float *scale, float *angle);
Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c 2011-10-15 19:20:34 UTC (rev 41038)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c 2011-10-15 19:30:51 UTC (rev 41039)
@@ -37,6 +37,7 @@
#include "MEM_guardedalloc.h"
+#include "DNA_gpencil_types.h"
#include "DNA_movieclip_types.h"
#include "DNA_object_types.h" /* SELECT */
#include "DNA_scene_types.h"
@@ -1495,7 +1496,6 @@
}
#ifdef WITH_LIBMV
-/* flips upside-down */
static unsigned char *acquire_ucharbuf(ImBuf *ibuf)
{
int x, y;
@@ -1504,18 +1504,16 @@
fp= pixels= MEM_callocN(ibuf->x*ibuf->y*sizeof(unsigned char), "tracking ucharBuf");
for(y= 0; y<ibuf->y; y++) {
for (x= 0; x<ibuf->x; x++) {
- int pixel= ibuf->x*(ibuf->y-y-1) + x;
+ int pixel= ibuf->x*y + x;
if(ibuf->rect_float) {
float *rrgbf= ibuf->rect_float + pixel*4;
- //*fp= 0.2126f*rrgbf[0] + 0.7152f*rrgbf[1] + 0.0722f*rrgbf[2];
- *fp= (11*rrgbf[0]+16*rrgbf[1]+5*rrgbf[2])/32;
+ *fp= 0.2126f*rrgbf[0] + 0.7152f*rrgbf[1] + 0.0722f*rrgbf[2];
} else {
char *rrgb= (char*)ibuf->rect + pixel*4;
- //*fp= 0.2126f*rrgb[0] + 0.7152f*rrgb[1] + 0.0722f*rrgb[2];
- *fp= (11*rrgb[0]+16*rrgb[1]+5*rrgb[2])/32;
+ *fp= 0.2126f*rrgb[0] + 0.7152f*rrgb[1] + 0.0722f*rrgb[2];
}
fp++;
@@ -1526,37 +1524,111 @@
}
#endif
-void BKE_tracking_detect(MovieTracking *tracking, ImBuf *ibuf, int framenr, int margin, int min_trackness, int count, int min_distance, int fast)
+static int point_in_stroke(bGPDstroke *stroke, float x, float y)
{
+ int i, prev;
+ int count= 0;
+ bGPDspoint *points= stroke->points;
+
+ prev= stroke->totpoints-1;
+
+ for(i= 0; i<stroke->totpoints; i++) {
+ if((points[i].y<y && points[prev].y>=y) || (points[prev].y<y && points[i].y>=y)) {
+ float fac= (y-points[i].y)/(points[prev].y-points[i].y);
+
+ if (points[i].x+fac*(points[prev].x-points[i].x)<x)
+ count++;
+ }
+
+ prev= i;
+ }
+
+ return count%2;
+}
+
+static int point_in_layer(bGPDlayer *layer, float x, float y)
+{
+ bGPDframe *frame= layer->frames.first;
+
+ while(frame) {
+ bGPDstroke *stroke= frame->strokes.first;
+ while(stroke) {
+ if(point_in_stroke(stroke, x, y))
+ return 1;
+
+ stroke= stroke->next;
+ }
+ frame= frame->next;
+ }
+
+ return 0;
+}
+
+static void retrive_libmv_features(MovieTracking *tracking, struct libmv_Features *features,
+ int framenr, int width, int height, bGPDlayer *layer)
+{
#ifdef WITH_LIBMV
- struct libmv_Features *features;
- unsigned char *pixels= acquire_ucharbuf(ibuf);
int a;
- if(fast)
- features= libmv_detectFeaturesFAST(pixels, ibuf->x, ibuf->y, ibuf->x, margin, min_trackness, min_distance);
- else
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list