Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

If you don't want to use SparseMat than I see only the way to do it by hand, i.e.

  1. either: cv::countNonZero(mat) -> gives you number of non-zero-elements -> create new matrix with size of this number of non-zero-elements -> fill new matrix with non-zero elements

  2. or: create std::vector of your type of numbers -> go through your matrix and push_back() those numbers which are non-zero to your vector -> create new matrix header on top of your vector

However, you should also consider to just use a mask for your following procedure, you can generate it by e.g. cv::Mat mask = (your_mat == 0).