Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert cv::Mat to const CvMat* or CvMat*

Tags:

c++

opencv

I know only C language, so I am getting confusion/not understanding the syntax of the openCV data types particularly in cv::Mat, CvMat*, Mat.

My question is How can I convert cv::Mat to const CvMat* or CvMat*, and can any one provide documentation link for difference between CvMat *mat and cv::Mat and Mat in opencv2.4.

and How can I convert my int data to float data in CvMat ? Thank you

like image 510
surya Avatar asked Jun 14 '12 06:06

surya


People also ask

What is 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 cv_64f?

Here's example for CV_64FC1 : CV_ - this is just a prefix. 64 - number of bits per base matrix element (e.g. pixel value in grayscale image or single color element in BGR image) F - type of the base element. In this case it's F for float, but can also be S (signed) or U (unsigned)

What is use of mat class 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.


1 Answers

cv::Mat has a operator CvMat() so simple assignment works:

cv::Mat mat = ....;
CvMat cvMat = mat;

This uses the same underlying data so you have to be careful that the cv::Mat doesn't go out of scope before the CvMat.

If you need to use the CvMat in an API that takes a CvMat*, then pass the address of the object:

functionTakingCmMatptr(&cvMat);

As for the difference between cv::Mat and Mat, they are the same. In OpenCV examples, it is often assumed (and I don't think this is a good idea) that using namespace cv is used.

like image 194
juanchopanza Avatar answered Sep 23 '22 19:09

juanchopanza