1 | initial version |
still i can't imagine how to use such a matrix but you can create it with findNonZero()
take a look at the code below
#include <opencv2/opencv.hpp>
using namespace cv;
int main( int argc, const char** argv )
{
Mat src= Mat::ones(5,5,CV_8UC1);
std::vector<Point> locations; // output, locations of non-zero pixels
findNonZero(src, locations);
std::cout << locations;
return 0;
}
output locations
vector is like below you can reshape it if you want
[0, 0;
1, 0;
2, 0;
3, 0;
4, 0;
0, 1;
1, 1;
2, 1;
3, 1;
4, 1;
0, 2;
1, 2;
2, 2;
3, 2;
4, 2;
0, 3;
1, 3;
2, 3;
3, 3;
4, 3;
0, 4;
1, 4;
2, 4;
3, 4;
4, 4]
2 | No.2 Revision |
still i can't imagine how to use such a matrix but you can create it with findNonZero()
take a look at the code below
#include <opencv2/opencv.hpp>
using namespace cv;
int main( int argc, const char** argv )
{
Mat src= Mat::ones(5,5,CV_8UC1);
std::vector<Point> //std::vector<Point> locations; // you can use vector or Mat to get same result
Mat locations; // output, locations of non-zero pixels
findNonZero(src, locations);
std::cout << locations;
return 0;
}
output locations
vector is like below you can reshape it if you want
[0, 0;
1, 0;
2, 0;
3, 0;
4, 0;
0, 1;
1, 1;
2, 1;
3, 1;
4, 1;
0, 2;
1, 2;
2, 2;
3, 2;
4, 2;
0, 3;
1, 3;
2, 3;
3, 3;
4, 3;
0, 4;
1, 4;
2, 4;
3, 4;
4, 4]