Interfaces std::Vector to cv::Mat
Hello,
I am working with OpenCV and love the cv::Mat. Shared pointers for the win!
With a std::vector<cv::point>() we can simply convert to a cv::Mat.
std::vector<cv::Point> points = std::vector<cv::Point>();
cv::Mat pointsMat = cv::Mat(points);
cv::Point point = pointsMat.at<cv::Point>(0,0);
We can then access the points. Sweet.
There are other datatypes such as histograms, descriptors matrices that all use the cv::Mat, making it ideal for interfaces.
What about these types?
2Df/2Dd/3Df/3Dd Points
std::vector<cv::Point3d> points = std::vector<cv::Point3d>();
This is the same as above for cv::Point.
std::vector<cv::keypoint>(); Has other attributes as well as a Point2f, such as octave, size etc which are of mixed types.
Contours std::vector<std::vector<cv::point>>(); Possibly, std::vector<cv::mat> if treated like a single vector of cv::Point. However we still have a std::vector.
std::vector<cv::dmatch>() This contains int, bool, float types.
With contours, it could be done using a std::vector<cv::mat> where a std::vector<cv::mat>(1) is used for single images and matrices. The std::vector is NOT thread safe, so i don't want to be passing too many of them around.
1) Can we convert these types to a cv::Mat? Even if a deconversion step back to their original type is required.
2) What is the overhead for converting std::vector to cv::Mat?
3) Are there any known interfaces for OpenCV primitives?
4) How would the conversion back from a cv::Mat to a std::vector work in each case? Thank you.
EDIT
I found this on a similar post on this forum.
Mat a = Mat::ones(10,1,CV_32FC3);
vector<Point3f> b;
a.copyTo(b);
Therefore... with Point2f....
Mat a = Mat::ones(10,1,CV_32FC2);
etc.