user227666
user227666

Reputation: 774

convert cv::Mat to Cvmat* in OpenCV

Suppose, I am declaring my CvMat* as shown below and then converting it to cv::Mat and then doing the conversion of types from CV_8UC1 to CV_32FC1. Then after the conversion, I want to revert it back to CVMat*. Can anbody tell me how can I do the conversion from cv::Mat to CvMat* ?

     CvMat* r1 = cvLoadImageM(argv[2], 0);
     cv::Mat r1cpp(r1);
     r1.convertTo(r1, CV_32FC1, 1.0/255.0);

Or does anybody knows how can I do the conversion of CV_8UC1 to CV_32FC1 with C API?

Upvotes: 2

Views: 2846

Answers (1)

Alexey
Alexey

Reputation: 5978

You can convert CV_8UC1 to CV_32FC1 with C API using cvConvertScale((src), (dst), 1, 0 ) command as follows

// source image
CvMat* src = cvLoadImageM(argv[2], 0); 

// allocate destination image of type CV_32F
CvMat* dst = cvCreateMat(src->height, src->width, CV_32FC1) 

// convert src image to dst image (type CV_32F)
cvConvertScale(src, dst, 1, 0 );  

Upvotes: 3

Related Questions