cv::Feature2D::compute called with empty std::vector<cv::KeyPoint> [closed]
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 descriptor cv::Mat
of size (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 descriptor 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 into the empty vector of keypoints.
Obviously, I can work around this, but for code simplicity with minimal conditionals and branching, this behavior is undesirable. When called with zero cv::KeyPoint
s, compute
should set the passed in cv::Mat
to be empty, such that when passed to a matcher, zero matches are found.
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 the descriptor 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
.