Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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 ?

share|improve this question

1 Answer

up vote 3 down vote accepted

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);
    }
}
share|improve this answer
answers.opencv.org/question/13871/… I think you don't need to create that additional variable row, also don't forgot taht you need a final reshape. +1 anyway – yes123 May 24 at 19:27
Explicitly declaring row isn't strictly necessary. I did it for readability. And reshape() isn't necessary unless you want to be extra sure--the original number of columns is preserved. – Aurelius May 24 at 20:31
Hm, acutally I think you are right. Without reshape code is working normally – yes123 May 25 at 13:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.