Armin Meisterhirn
Armin Meisterhirn

Reputation: 801

How to convert Mat to cvMat in OpenCV 3.0

How can I convert an OpenCV Mat object to cvMat object ?

As per this OpenCV interoperability document(1), this conversion should be possible. But on declaring cvMat, compiler gives below error message at line cvMat deprecatedImg

: error: < expected ‘;’ before ‘deprecatedImg’ >,

How to fix this ?

Upvotes: 1

Views: 2069

Answers (1)

kiranpradeep
kiranpradeep

Reputation: 11201

In OpenCV 3 and above you have to use compatability headers(types_c.h) for using deprecated C objects like cvMat. In OpenCV 3.0, CvMat has a constructor which accepts a Mat(1). Code as below.

#include "opencv2/core/types_c.h"
cv::Mat img = ... ;
CvMat deprecatedImg(img);

In OpenCV 2.4.* and below, Mat to CvMat conversion operator(2) exists and you can simply assign a Mat to CvMat as below. Note that this conversion operator no more exists in OpenCV 3 and above.

Mat img = ...;
CvMat cvMatImg = img;

Upvotes: 6

Related Questions