Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing selected rows from opencv::Mat?

For some reasons I need to filter out rows of a Mat. (I need to filter out some descriptors of ORB)

Which way do you suggest me? I haven't find any method to remove a single row from a Mat. So I was thinking I could iteratively inserting the good rows in a new Mat.

C++ pseudocode (with removing):

Mat desc;
ORB(myImage,cv::noArray,kp,desc);
matcher->match( myPreviousDesc, desc, matches );

for(auto i=0;i<matches.size();i++) {
   if (some conditions) {
      Remove the ith row of desc:
      erase( desc.row( matches[i].queryIdx ) ); // pseudo
   }
}

How would you erase a single row from a Mat after checking for some conditions (or adding only the selected row in a new Mat) ?

Or how to add a new row iteratively to a new Mat ?


1 Answers

Iteratively adding a new row is straightforward with cv::Mat::push_back().

Adding only good descriptors might look like this:

cv::Mat good_descriptors;   
for (auto i = 0; i < matches.size(); ++i)
{
    if (/*something*/)
    {
        cv::Mat row = desc.row(matches[i].queryIdx);
        good_descriptors.push_back(row);
    }
}
like image 70
Aurelius Avatar answered Oct 23 '25 07:10

Aurelius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!