chostDevil
chostDevil

Reputation: 1071

how to convert from cv::Mat to CvArr?

i have passed a lot of time searching on how to convert from cv::Mat or CvMat to CvArr but with no gain ,please help me in that,thanks.

Upvotes: 8

Views: 31147

Answers (5)

Vivek Mahto
Vivek Mahto

Reputation: 314

Mat img = imread("C:\MyPic.jpg",CV_LOAD_IMAGE_GRAYSCALE);
IplImage tmp=img;
cvErode(&tmp, &tmp, 0, 2);
Mat laser=&tmp;
    imshow("Eroded",laser);

I converted cv::Mat to CvArr by this way. Instead of using tmp directly use &tmp.

Upvotes: 5

Clement Roblot
Clement Roblot

Reputation: 909

When I need to do that I just use :

IplImage tmp = image;

With image a Mat variable.

Upvotes: 4

jamk
jamk

Reputation: 866

convert first the image using the following:

IplImage* oldstyleimg = &matimg.operator IplImage()

I don t remember if it only create the header for the image or it makes a copy

Upvotes: -1

Juraj
Juraj

Reputation: 6638

Are you sure you want to convert it? sometimes there is equivalent function that use what you have. For example cvMorphologyEx is using CvArr but morphologyEx is using cv::Mat.

Upvotes: 1

lezebulon
lezebulon

Reputation: 8014

If I recall correctly, CvMat IS a CvArr so you can just cast it into a CvArr, and the first bytes of the now CvArr tell the function that it is actually a CvMat: http://opencv.willowgarage.com/documentation/basic_structures.html#cvarr

Upvotes: 1

Related Questions