1 | initial version |
your grid is broken, you only save the last horizontal points (only 10 points left in the array, not 100)
for(int i =0; i<10;++i){
for(int j =0; j<10;++j){
float y = float(i * (height/10) + 5);
float x = float(j * (width/10) + 5);
img_corners.push_back(Point2f(x,y));
}
}
then, a grid like that is usually a bad seed for optical flow, rather use goodfeaturestotrack, or ORB/SIFT/whatever keypoints for this task, not a grid (which will have points "in nowwhere" far too often !)
2 | No.2 Revision |
your grid calculation cal is broken, you only save the last horizontal points (only 10 points left in the array, not 100)
for(int i =0; i<10;++i){
for(int j =0; j<10;++j){
float y = float(i * (height/10) + 5);
float x = float(j * (width/10) + 5);
img_corners.push_back(Point2f(x,y));
}
}
then, a grid like that is usually a bad seed for optical flow, rather use goodfeaturestotrack, or ORB/SIFT/whatever keypoints for this task, not a grid (which will have points "in nowwhere" far too often !)
3 | No.3 Revision |
your grid calculation cal is broken, you only save the last horizontal points (only 10 points left in the array, not 100)
for(int i =0; i<10;++i){
for(int j =0; j<10;++j){
float y = float(i * (height/10) + 5);
float x = float(j * (width/10) + 5);
img_corners.push_back(Point2f(x,y));
}
}
then, a grid like that is usually a bad seed for optical flow, rather use goodfeaturestotrack, or ORB/SIFT/whatever keypoints for this task, not a grid (which will have points "in nowwhere" far too often !)
4 | No.4 Revision |
your grid calculation is broken, you only save the last horizontal points (only 10 points left in the array, not 100)
for(int i =0; i<10;++i){
for(int j =0; j<10;++j){
float y = float(i * (height/10) + 5);
float x = float(j * (width/10) + 5);
img_corners.push_back(Point2f(x,y));
}
}
then, a grid like that is usually a bad seed for optical flow, rather use goodfeaturestotrack, or ORB/SIFT/whatever keypoints ORB/SIFT for this task, not a grid (which will have points "in nowwhere" far too often !)
5 | No.5 Revision |
your grid calculation is broken, you only save the last horizontal points (only 10 points left in the array, not 100)100) rather try like this:
for(int i =0; i<10;++i){
i=0; i<10; ++i){
for(int j =0; j<10;++j){
j=0; j<10; ++j){
float y = float(i * (height/10) + 5);
float x = float(j * (width/10) + 5);
img_corners.push_back(Point2f(x,y));
}
}
then, a grid like that is usually a bad seed for optical flow, rather use goodfeaturestotrack, or ORB/SIFT for this task, not a grid (which will have points "in nowwhere" far too often !)