SDD123
SDD123

Reputation: 63

Converting point2d to Mat

How can I convert vector<Point2d> to Mat.

     Mat newImg = Mat(ImagePoints);
     imwrite("E:/softwares/1.8.0.71/bin/newImg.png", newImg); 

This is not working since imWrite() will only accept channel 1 or 3 or 4 and the Image Points are 2 channel.

I am using OpenCV version 3.

Upvotes: 0

Views: 1272

Answers (1)

Anubhav Rohatgi
Anubhav Rohatgi

Reputation: 458

Here is the answer:

Dont worry about the type casting. Using integers in double. But this is just to give the gist of the solution.

std::vector< cv::Point2d> points;

for(int i =0; i < 10; i++)
{
    points.push_back(cv::Point2d(i,i));
}

cv::Mat_<cv::Point2d> matrix(points);

std::cout<<matrix.at<cv::Point2d>(1);

But if you want to save this Mat then use XML. Imwrite wont write the Mat.

Upvotes: 1

Related Questions