出于某些原因,我需要过滤掉 Mat 的行。 (我需要过滤掉一些ORB的描述符)
您建议我使用哪种方式?我还没有找到任何方法来从 Mat 中删除一行。 所以我在想我可以迭代地将好的行插入到一个新的 Mat 中。
C++ 伪代码(删除):
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
}
}
在检查某些条件(或仅在新垫中添加选定的行)后,如何从垫中删除一行?
或者如何向新 Mat 迭代添加新行?
最佳答案
使用 cv::Mat::push_back()
迭代添加新行很简单.
只添加好的描述符可能看起来像这样:
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);
}
}
关于arrays - 从 opencv::Mat 中删除选定的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16739286/