# Revision history [back]

no idea, if it will work in your case, but you could try to seperate foreground / background motion like in the paper mentioned above:

            // 3.1 Step 3: Camera/background motion estimation

vector<Point2f> foreground;
// points[0]==prev, points[1]==cur
Mat H = findHomography(points[0], points[1], RANSAC);
cerr << H << endl;
for(size_t i=0; i<points[1].size(); i++)
{
Point2f p0 = points[0][i];
Point2f p1 = points[1][i];
Mat_<double> col(3, 1);
col << p0.x, p0.y, 1;
col = H * col;
col /= col.at<double>(2);
double dist = sqrt(pow(col(0) - p1.x, 2) +
pow(col(1) - p1.y, 2));
if (dist >= 1.5)  // some heuristical threshold value
{
foreground.push_back(p1);
}
}
cerr << "fg " << points[1].size() << " " << foreground.size()  << endl;


no idea, if it will work in your case, but you could try to seperate foreground / background motion like in the paper mentioned above:

            // 3.1 Step 3: Camera/background motion estimation
// pointsPrev, pointsCur are vector<Point2f> from LK

vector<Point2f> foreground;
// points[0]==prev, points[1]==cur
Mat H = findHomography(points[0], points[1], findHomography(pointsPrev, pointsCur, RANSAC);
cerr << H << endl;
// now, backproject the points, and see, how far off they are:
for(size_t i=0; i<points[1].size(); i<pointsCur.size(); i++)
{
Point2f p0 = points[0][i];
pointsPrev[i];
Point2f p1 = points[1][i];
pointsCur[i];
Mat_<double> col(3, 1);
col << p0.x, p0.y, 1;
col = H * col;
col /= col.at<double>(2);
double dist = sqrt(pow(col(0) - p1.x, 2) +
pow(col(1) - p1.y, 2));
// small distance == inlier == camera motion
// large distance == outlier == object motion
if (dist >= 1.5)  // some heuristical threshold value
{
foreground.push_back(p1);
}
}
cerr << "fg " << points[1].size() pointsCur.size() << " " << foreground.size()  << endl;


no idea, if it will work in your case, but you could try to seperate foreground / background motion like in the paper mentioned above:

            // 3.1 Step 3: Camera/background motion estimation
// pointsPrev, pointsCur are vector<Point2f> from LK

vector<Point2f> foreground;
Mat H = findHomography(pointsPrev, pointsCur, RANSAC);
cerr << H << endl;
// now, backproject the points, and see, how far off they are:
for(size_t i=0; i<pointsCur.size(); i++)
{
Point2f p0 = pointsPrev[i];
Point2f p1 = pointsCur[i];
// homogeneous point for mult:
Mat_<double> col(3, 1);
col << p0.x, p0.y, 1;
col = H * col;
col /= col.at<double>(2);
col(2); // divide by W
double dist = sqrt(pow(col(0) - p1.x, 2) +
pow(col(1) - p1.y, 2));
// small distance == inlier == camera motion
// large distance == outlier == object motion
if (dist >= 1.5)  // some heuristical threshold value
{
foreground.push_back(p1);
}
}
cerr << "fg " << pointsCur.size() << " " << foreground.size()  << endl;