Ask Your Question
3

convert from vector to Mat

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

mrgloom gravatar image

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

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
7

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

AlexanderShishkov gravatar image

You should use one channel cv::Mat (see docs here: http://docs.opencv.org/modules/flann/doc/flann_fast_approximate_nearest_neighbor_search.html#flann-index)

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

Stats

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

Seen: 4,052 times

Last updated: Oct 31 '12