Ask Your Question

Revision history [back]

How to retrieve a std::vector of points from cv::Mat?

I have a 'cv::Mat' with labeled blobs. So I am able to retrieve a mask for each component. Now what I am interested in are the indices of all points of a mask. The reason is that I want to use 'cv::fitLine' with these points, or any other minimizer to match data with my model. The only idea I have is iterating over the image and manually collect the indices, but maybe there is a smarter way? Maybe converting a (dense) matrix to a sparse one or some such?