Is any way to convert Mat image to vector?
This doesnt work:
Mat input = imread("image.png");
vector<Point> points;
points = input;
Is any way to convert Mat image to vector?
This doesnt work:
Mat input = imread("image.png");
vector<Point> points;
points = input;
You could easily do it manually, creating points directly using the row/col indexing of the mat:
//Create a blank mat of size 3x3 and an empty point vector
cv::Mat img = cv::Mat::zeros(cv::Size(3, 3), CV_8UC3);
std::vector<cv::Point> points;
//Loop over each pixel and create a point
for (int x = 0; x < img.cols; x++)
for (int y = 0; y < img.rows; y++)
points.push_back(cv::Point(x, y));
//Print out results
for (cv::Point p : points)
std::cout << p << "\n";
But I can't see why you'd need to do this, you already know the points in the matrix as you have access to its size.
Please explain how do you wish to convert the image to points. What would each point in your vector hold?
You can populate your vector by iterating through the matrix.
You can assign a 3x1,1x3 or a 1x2, 2x1 Mat array to a Point2f, Point3f structure by constructors.
This thread may be helpful, Conversion of 3x1 or 1x3 cv::Mat to cv::Point3d?