我正在使用opencv将一些matlab代码翻译成c ++.我想获得满足条件的Matrix的值.我为此创建了一个蒙版,当我将它应用到原始矩阵时,我得到的原始矩阵大小相同,但是掩码中没有0值.但我的问题是如何才能获得矩阵中非零值并将其分配给不同的矩阵.
我的matlab代码是:
for i= 1:size(no,1)
mask= labels==i;
op = orig(mask, :); //op only contains the values from the orig matrix which are in the mask. So orig size and op size is not the same
.....
end
Run Code Online (Sandbox Code Playgroud)
我现在的c ++翻译是:
for (int i=0; i<n.rows; i++)
{
Mat mask;
compare(labels,i,mask,CMP_EQ);
Mat op;
orig.copyTo(op,mask); //Here the orig size and the op size is always same but values which are not in the mask are 0
}
Run Code Online (Sandbox Code Playgroud)
那么,我怎样才能创建一个只有掩码满足的值的矩阵?