1
votes

Apologies if this is a stupid question, I am not the most experienced with using pointers in c++.

I am using openCv, and have a cv::Mat initialized as:

cv::Mat* frame;

I also have another Mat, filled with data initialized as:

cv::Mat frameRaw;

Obviously one is a pointer, and the other is not.

I need to copy the data from frameRaw into frame.

I have tried *frame = frameRaw; but it gives me an exception error.

How should I do this?

Thanks.

2
do you initialize your frame before use it? - apple apple
Actually, it was commented out! works now, will update post. Thank you! - anti
There is no need for this first syntax, can you just just replace it with the second? Usage of new is avoided in modern C++. Opencv follows that idiom and make things easier to handle. - kebs

2 Answers

1
votes

Thank you for pointing out my mistake. I had not initialized the Mat properly. Adding

frame = new cv::Mat();

fixes the issue.

0
votes

See the code snippet, hope this will answer you:

Mat * f = new Mat(2,2,CV_32FC1);
    f->at<float>(0,0) = 1;
    f->at<float>(0,1) = 2;
    f->at<float>(1,0) = 3;
    f->at<float>(1,1) = 4;

    Mat ff;
    f->copyTo(ff);
    cout<<ff;