# get values of nonZero elements of a 2-dim cv::Mat

I want to get values of nonZero elements of a 2-dim cv::Mat and put the result on a cv::Mat. How I can do this ? I used following code to get the index of nonZero elements :

cv::vector<cv::vec2i> nonzero ;

cv::findNonZero(mask,nonzero);

and the problem is ?

findNonZero function get index of nonZero elements, but I want value of them. I can get value of the first nonZero element by using nonzero.at(1), but How I can put all values in a cv::Mat ?

you can make a new Mat with the nonzero elements (say, all on a single row), but a 2d Mat ? what about the "holes" ?

what do you need it for ?

who I can make a new with with the nonzero elements ? I have a probability matrix (mask) and want probability of the nonzero elements for a classification task.

still unclear. which shape is required for the classification task ? any ?