I have a visual odometry routine that computes matches between the current frame and the previous frame. If keypoints are detected, a call to compute
returns a description cv::Mat
where the size is (WxH)=(64xNumKeyPoints). This is expected. However, if called with an empty vector of keypoints, instead of returning an empty cv::Mat
(with size (WxH)=(0x0)), the description cv::Mat
has size (WxH)=(64x1). This means that passing this to a matcher yields a match where the indices of cv::DMatch
are invalid as using these indices results in an out-of-bounds access.
Obviously, I can work around this, but for code simplicity with minimal conditionals and branching, this behavior is undesirable. When called with no cv::KeyPoint
s, compute
should set the passed in cv::Mat
to be empty, such that when passed to a matcher, no matches are found.
Because I am reusing objects (current frame data are assigned/swapped/copied to previous frame data). If I find that no features/keypoints are detected, what would be the best way to signify this to the matcher? How do I best unset the size of this cv::Mat
or set it to empty? Is "releasing" the descriptor cv::Mat
the proper way to "empty" it?
To summarize, I want a constant uninterrupted pipeline: detect->extract->match to yield zero matches when zero keypoints are detected.
My descriptor extractor is cv::xfeatures2d::FREAK
. My matcher is cv::BFMatcher
.