Ask Your Question

Revision history [back]

Hi!

  1. It is possible to convert a vector to a cv::Mat, but only if vector inside-type is supported by OpenCV. That is, there is a structure called "DataType" which define how data can be used but Mat constructor (look in modules\core\include\opencv2\core\traits.hpp for examples). So this is defined for classic types (float, int...) and some more complex types, like cv::Complex<>, std::complex<>, cv::Vec<> etc. If you want to add your specific type, you just have to specialize this class. But be careful: inside-type can't be a structure of different types like cv::Keypoint is (there is float and int)! Indeed, a Mat with such data doesn't make sens as a Mat is defined with a single data type (CV_32F for instance)

  2. The constructor of Mat allow you to specify if you want to copy the data or not. If you don't want to copy data, the overhead is null!

  3. I don't understand this question ;-)

  4. There is no direct conversions from Mat to vector, but you can do it quite fast using memcpy, assuming your Mat is contiguous, and vector is already allocated with enough space.

So here is a snippet of how to do this with classical types:

std::vector<cv::Point3d> test;
test.push_back(cv::Point3d(0, 1, 2)); test.push_back(cv::Point3d(3, 4, 5));
cv::Mat cvt(test, false);//second param for data copy

Hi!

  1. It is possible to convert a vector to a cv::Mat, but only if vector inside-type is supported by OpenCV. That is, there is a structure called "DataType" which define how data can be used but by Mat constructor (look in modules\core\include\opencv2\core\traits.hpp for examples). So this is defined for classic types (float, int...) and some more complex types, like cv::Complex<>, std::complex<>, cv::Vec<> etc. If you want to add your specific type, you just have to specialize this class. But be careful: inside-type can't be a structure of different types like cv::Keypoint is (there is float and int)! Indeed, a Mat with such data doesn't make sens sense as a Mat is defined with a single data type (CV_32F for instance)instance), so the values would be incoherent.

  2. The constructor of Mat allow you to specify if you want to copy the data or not. If you don't want to copy data, the overhead is null!

  3. I don't understand this question ;-)

  4. There is no direct conversions from Mat to vector, but you can do it quite fast using memcpy, assuming your Mat is contiguous, and vector is already allocated with enough space.

So here is a snippet of how to do this with classical types:

std::vector<cv::Point3d> test;
test.push_back(cv::Point3d(0, 1, 2)); test.push_back(cv::Point3d(3, 4, 5));
cv::Mat cvt(test, false);//second param for data copy

Hi!

  1. It is possible to convert a vector to a cv::Mat, but only if vector inside-type is supported by OpenCV. That is, there is a structure called "DataType" which define how data can be used by Mat constructor (look in modules\core\include\opencv2\core\traits.hpp for examples). So this is defined for classic types (float, int...) and some more complex types, like cv::Complex<>, std::complex<>, cv::Vec<> etc. If you want to add your specific type, you just have to specialize this class. But be careful: inside-type can't be a structure of different types like cv::Keypoint is (there is float and int)! Indeed, a Mat with such data doesn't make sense as a Mat is defined with a single data type (CV_32F for instance), so the values would be incoherent.

  2. The constructor of Mat allow you to specify if you want to copy the data or not. If you don't want to copy data, the overhead is null!

  3. I don't understand this question ;-)

  4. There is no direct conversions from Mat to vector, but you can do it quite fast using memcpy, assuming your Mat is contiguous, and vector is already allocated with enough space.

So here is a snippet of how to do this with classical types:

std::vector<cv::Point3d> test;
test.push_back(cv::Point3d(0, 1, 2)); test.push_back(cv::Point3d(3, 4, 5));
cv::Mat cvt(test, false);//second param for data copy
copy (here, data are not duplicated!)

Hi!

  1. It is possible to convert a vector to a cv::Mat, but only if vector inside-type is supported by OpenCV. That is, there is a structure called "DataType" which define how data can be used by Mat constructor (look in modules\core\include\opencv2\core\traits.hpp for examples). So this is defined for classic types (float, int...) and some more complex types, like cv::Complex<>, std::complex<>, cv::Vec<> etc. If you want to add your specific type, you just have to specialize this class. But be careful: inside-type can't be a structure of different types like cv::Keypoint is (there is float and int)! Indeed, a Mat with such data doesn't make sense as a Mat is defined with a single data type (CV_32F for instance), so the values would be incoherent.

  2. The constructor of Mat allow you to specify if you want to copy the data or not. If you don't want to copy data, the overhead is null!

  3. I don't understand this question ;-)

  4. There is no direct conversions from Mat to vector, but Assuming your Mat is contiguous, the solution you post is the best you can do it quite fast using memcpy, assuming your Mat is contiguous, and vector is already allocated with enough space.do!

So here is a snippet of how to do this with classical types:

std::vector<cv::Point3d> test;
test.push_back(cv::Point3d(0, 1, 2)); test.push_back(cv::Point3d(3, 4, 5));
cv::Mat cvt(test, false);//second param for data copy (here, data are not duplicated!)