Omar Osama
Omar Osama

Reputation: 1431

assign a double matrix to CvMat opencv

It is look trivial. I tried this

double d[2];

CvMat* cvdata;

cvdata->data.db = d;

when I using debugging mood it seems that only the first element assigned to cvdata.

any suggestions? and what about 2-Dimensional array?

thank you

Upvotes: 0

Views: 12124

Answers (2)

Paul Weibert
Paul Weibert

Reputation: 314

You should not use a pointer to Mat, you can do it the following way:

int rows = ..;
int cols = ..;
cv::Mat cvdata(rows, cols, cv::DataType<double>::type);

when you copy cvdata or pass it as argument only a copy of the cv::Mat's header is created the internal data i copied. Opencv manages the pointers automatically.

Upvotes: 1

user1206794
user1206794

Reputation: 21

I think you need to set these first:

matrix size, matrix type

Example in C++:

double d[2];
cv::Mat* cvdata = new cv::Mat(1, 2, CV_64F);
.
.
.

http://opencv.itseez.com/modules/core/doc/intro.html#fixed-pixel-types-limited-use-of-templates

http://opencv.itseez.com/modules/core/doc/basic_structures.html#mat-mat

Upvotes: 2

Related Questions