且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C ++中的函数类似于numpy flatten

更新时间:2022-06-27 01:05:41

所以我已经弄清楚了,没有直线或一线解决方案(如果有的话,我知道哈哈)

So I have figured this out, there is no straight or 1 line solution of this ( if there is let me know haha)

res = center[label.flatten()] 

可以在C ++ opencv中使用以下命令执行

can be performed with following in C++ opencv

for(int i = 0; i<labels.rows ; i++)
{
  if(labels.at<int>(i) == 0) { 
    res.push_back(centers.row(0));
  } else if(labels.at<int>(i) == 1) {
      res.push_back(centers.row(1)); 
  } else if(labels.at<int>(i) == 2) {
      res.push_back(centers.row(2)); 
  } else{
      res.push_back(centers.row(3));
  } 
}

谢谢.