Ask Your Question

jfdesgagne's profile - activity

2013-09-25 20:38:53 -0600 received badge  Editor (source)
2013-09-25 20:38:29 -0600 asked a question cv::Mat() data pointer vs Mat::clone()

I have a pointer to a buffer image. I'm trying to create a cv::Mat and assign it my buffer image. The only way i found is by doing

uchar* buffer; //have some data in it
cv::Mat(height, width, CV_8UC1, buffer); //which won't copy the data, will use the pointer as reference

The problem is I don't have ownership of that buffer. So I can either :

create a mat and assign it that buffer, than do a copyTo itself. (which is the same thing than I clone())

do a malloc and memcpy of that buffer (so i have a pointer that i own) and create a mat from it. (which is much faster).

Is the method #2 wrong? Why is it so much faster?

Bonus questions: What is hapenning to my buffer memory when I do operation on my mat? Is it getting resized? Is it getting updated (if i do a cv::flip, will it update the original buffer) ? And why is the clone() so expensive?

Sorry for the multiple questions, but I think they are all related and will help me to understand a little bit better the cv::Mat structure.