Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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 histograms, descriptors 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.

Keypoints http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_feature_detectors.html?highlight=keypoint#KeyPoint 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.

Descriptor Matches http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_descriptor_matchers.html?highlight=dmatch#DMatch 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 to a cv::Mat work in each case? Thank you.

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.

Keypoints http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_feature_detectors.html?highlight=keypoint#KeyPoint Keypoints

http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_feature_detectors.html?highlight=keypoint#KeyPoint

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.

Descriptor Matches http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_descriptor_matchers.html?highlight=dmatch#DMatch Matches

http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_descriptor_matchers.html?highlight=dmatch#DMatch

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 to a cv::Mat work in each case? Thank you.

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.

Keypoints

http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_feature_detectors.html?highlight=keypoint#KeyPoint

std::vector<cv::keypoint>(); Has other attributes as well as a Point2f, such as octave, size etc which are of mixed types.

Contours 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.

Descriptor Matches

http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_descriptor_matchers.html?highlight=dmatch#DMatch

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 to a cv::Mat work in each case? Thank you.

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.

Keypoints

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.

Descriptor Matches

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 to from a cv::Mat to a std::vector work in each case? Thank you.

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.

Keypoints

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.

Descriptor Matches

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);

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.

Keypoints

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.

Descriptor Matches

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);vector<Point3f> b; a.copyTo(b); Therefore... with Point2f.... Mat a = Mat::ones(10,1,CV_32FC2);

etc.