Matrix masking operation in OpenCV(C++) and in Matlab -
i following operation (which @ current state in matlab) using cv::mat variables.
i have matrix mask:
mask = 1 0 0 1 0 1 then matrix m:
m = 1 2 3 4 5 6 3 and samples = m(mask,:)
samples = 1 2 6 my question is, how can perform same operation like, m(mask,:), opencv?
with knowledge closet function thing copyto function in opencv matrix , mask inputs. function hold original structure of matrix can test it.
i think there no problem use for loop in opencv(in c++) because it's fast. propose use for loop below codes.
mat m=(mat_<uchar>(2,3)<<1,2,3,4,5,6); //create m cout<<m<<endl; mat mask=(mat_<bool>(2,3)<<1,0,0,1,0,1); // create mask cout<<mask<<endl; mat samples; /////////////////////////////// for(int i=0;i<m.total();i++) { if(mask.at<uchar>(i)) samples.push_back(m.at<uchar>(i)); } cout<<samples<<endl; above code result below outputs.
[ 1, 2, 3; 4, 5, 6] [ 1, 0, 0; 1, 0, 1] [ 1; 4; 6] with using copyto output below
[1 0 0 4 0 6]; 
Comments
Post a Comment