【问题标题】:Using Matlab's colon operator in OpenCV C++ without loop在没有循环的 OpenCV C++ 中使用 Matlab 的冒号运算符
【发布时间】:2014-04-08 11:23:19
【问题描述】:

C++ 中有什么解决方案我可以像 Matlab 中的冒号一样使用。

在 Matlab 中

image(i,j-one_count:j-1)=0;

由于我使用的是Mat Structure Opencv,所以也是向量结构。

如何在不使用循环的情况下在 C++ 中编写相同的内容?

另一个问题中的 Matlab 和 C++ 的完整代码

Attempt to implementation Running Length Smoothing Algorithm in C++

【问题讨论】:

    标签: c++ matlab opencv


    【解决方案1】:

    考虑到您使用的是cv::Mat。你有没有考虑过使用colRange(int startcol, int endcol)

    image.colRange( j-one_count - 1, j - 2 ) = 0;
    

    【讨论】:

    【解决方案2】:

    使用范围函数 你可以按如下方式使用它

    image(Range(i,i+1),Range(j-one_count:j-1)) = Mat::zeros(1,j-one_count:j-1,image.type());
    
    Range(a,b) can be used to get row/column from [a,b). ie from row/column a to row/column b-1
    

    你也不能直接赋值 0。您可以将大小相等的零矩阵分配为从图像中获取的子矩阵。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多