Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert CvMat* to cv::Mat in OpenCV3.0

Tags:

c++

opencv3.0

In opencv2.4.10 which I used before, conversion from CvMat* to cv::Mat can be done as below.

CvMat *src = ...;
cv::Mat dst;
dst = cv::Mat(src);

However, in opencv3.0 rc1 cannot convert like this. In certain website, this conversion can be done as below.

CvMat* src = ...;
cv::Mat dst;
dst = cv::Mat(src->rows, src->cols, src->type, src->data.*);

If type of src is 'float', the last argument is 'src->data.fl'.

Why constructor of cv::Mat is decreased? Or are there some methods about conversion from CvMat* to cv::Mat?

like image 617
Toshi Avatar asked May 25 '15 02:05

Toshi


People also ask

What is a CV :: mat?

In OpenCV the main matrix class is called Mat and is contained in the OpenCV-namespace cv. This matrix is not templated but nevertheless can contain different data types. These are indicated by a certain type-number. Additionally, OpenCV provides a templated class called Mat_, which is derived from Mat.

What does MAT mean in C++?

Mat is basically a class with two data parts : the matrix header (containing information such as the size of the matrix, the method used for storing, at which address is the matrix stored, and so on) and a pointer to the matrix containing the pixel values (taking any dimensionality depending on the method chosen for ...

What is mat type in OpenCV?

The Mat class of OpenCV library is used to store the values of an image. It represents an n-dimensional array and is used to store image data of grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms, etc.

What is CV_64F?

CV_64F is the same as CV_64FC1 . So if you need just 2D matrix (i.e. single channeled) you can just use CV_64F. EDIT. More generally, type name of a Mat object consists of several parts.


2 Answers

CvMat* matrix;
Mat M0 = cvarrToMat(matrix);

OpenCV provided this function instead of Mat(matrix).

Note: In OpenCV 3.0 they wrapped up all the constructors which convert old-style structures (cvmat, IPLImage) to the new-style Mat into this function.

like image 128
hariprasad Avatar answered Oct 31 '22 22:10

hariprasad


In order to convert CvMat* to Mat you have to do like this:

cv::Mat dst(src->rows, src->cols, CV_64FC1, src->data.fl);
like image 29
Abc Avatar answered Oct 31 '22 22:10

Abc