uzh-rpg / vilib

CUDA Visual Library by RPG
Other
425 stars 89 forks source link

Does the starting trace of a point start with an integer? #19

Closed ThinkPig826 closed 3 years ago

ThinkPig826 commented 3 years ago

I add the code. std::cout<<"firstpos: "<<track.firstpos[0]<<", "<<track.firstpos[1]<<std::endl; std::cout<<"curpos : "<<track.curpos[0]<<", "<<track.curpos[1]<<std::endl;
Get the following results. firstpos: 698, 36 curpos : 694.986, 33.3397 firstpos: 708, 294 curpos : 705.637, 278.984 firstpos: 640, 16 curpos : 636.937, 12.2501 firstpos: 378, 48 curpos : 374.201, 37.2297 firstpos: 700, 24 curpos : 697.136, 21.1231 ...

Does the starting trace of a point start with an integer?

Thank you !

baliika commented 3 years ago

Hello ThinkPig826, thanks for your question. The starting position of each feature track depends on the detector used in the feature tracker. If the detector outputs integer coordinates as feature locations, then the 1st positions of the feature tracks are going to be integers. This is the case with the FAST feature detector, as it does not perform sub-pixel refinement after non-maximum suppression. The lower pyramid-level feature positions receive a 2^(l-1) scaling, which is again an integer, therefore the final feature positions will be integers even with multiple pyramid levels. Once the features were detected, their position is going to be adjusted by LK, and therefore they become non-integer values.

ThinkPig826 commented 3 years ago

thank you very much! Can I replace the points obtained by the detector with my own points? There is only one point in a grid.

ThinkPig826 commented 3 years ago

I want to use vilib library in vins.

baliika commented 3 years ago

Sure, you can. The detector is triggered here: https://github.com/uzh-rpg/vilib/blob/32c9c9caa07ce20c5a5c618306b7012804492728/visual_lib/src/feature_tracker/feature_tracker_gpu.cpp#L189

You should just simply remove our code here that adds the features from the detector to the tracker. And the way to populate the points with your points is:

std::shared_ptr<Frame> frame ; // the frame where the point can be observed (so that a template patch can be extracted)
const float x; // x coordinate of the point to be tracked
const float y; // y coordiante of the point to be tracked
const int level; // the actual pyramid level where the point was extracted from, e.g. if you only use a single resolution, then 0
const float score; // the score with which the point was detected, may be arbitrary
const std::size_t camera_id; // in single camera tracking, this is 0
// Add the point to the tracker
int track_index = addTrack(frame,
                                 x,
                                 y,
                                 level,
                                 score,
                                 camera_id);
// Now we add the point to the output frame, so that it can be displayed/or used outside the tracker
addFeature(cur_base_frames[c],track_index,camera_id);
++detected_features_num_[camera_id];

Also make sure, whenever you add the new points, the updateTracks() function is triggered so that the template patches are precalculated for the incoming frames. (https://github.com/uzh-rpg/vilib/blob/32c9c9caa07ce20c5a5c618306b7012804492728/visual_lib/src/feature_tracker/feature_tracker_gpu.cpp#L272)

ThinkPig826 commented 3 years ago

Thank you very much. I did that, but found that the tracking effect is not as good as OpenCV. I am not sure if it is my problem.