Ask Your Question

convert from vector to Mat

asked 2012-10-31 06:14:46 -0500

mrgloom gravatar image

updated 2020-11-30 03:33:26 -0500

I have

vector<cv::Point> pts

and I want to use it with FLANN I tried

cv::flann::Index tree= cv::flann::Index(cv::Mat(pts),cv::flann::KDTreeIndexParams(1));

but it doesn't work.I think I must convert pts to Mat.

How I can do this?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2012-10-31 14:31:46 -0500

AlexanderShishkov gravatar image

You should use one channel cv::Mat (see docs here:

When you use cv::Mat(pts) you get two channels matrix Kx1 with type CV_32FC2, so you should call reshape to get matrix K*2x1 with type CV_32FC.

std::vector<cv::Point2f> pts(K);
cv::flann::Index tree= cv::flann::Index(cv::Mat(pts).reshape(1),cv::flann::KDTreeIndexParams(1));
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2012-10-31 06:14:46 -0500

Seen: 3,826 times

Last updated: Oct 31 '12