1 | initial version |
Question: Yes, just access the data-field. e.g.
cv::Mat1f a(2,2); float* matrix_data = (float*) a.data; // Note: static cast is probably more apropriate
Note: that the matrix_data will be de-allocated if the matrix a
loses its scope, so a safer way would be to copy it (e.g. using memcpy).
Question: yes you can put a matrix-header on top of your data.
float* matrix_data = new float[1]; matrix_data = 123.0; cv::Mat1f a(1,1,matrix_data);
The same also works with std::vector
.
By the way: I would always keep the data, i.e. your images, as matrices: 1. it is safer (no own memore allocations/deletions needed) and 2. it makes the code easier to read and to use.
2 | No.2 Revision |
Question: Yes, just access the data-field. e.g.
cv::Mat1f a(2,2); float* matrix_data = (float*) a.data; // Note: static cast is probably more apropriate
Note: that the matrix_data will be de-allocated if the matrix a
loses its scope, so a safer way would be to copy it (e.g. using memcpy).
Question: yes you can put a matrix-header on top of your data.
float* matrix_data = new float[1]; matrix_data = 123.0; cv::Mat1f a(1,1,matrix_data);
The same also works with std::vector
.
By the way: I would always keep the data, i.e. your images, as matrices: 1. it is safer (no own memore allocations/deletions needed) and 2. it makes the code easier to read and to use.
Please also have a look at http://docs.opencv.org/modules/core/doc/basic_structures.html#mat.