简体   繁体   中英

Copy data from cv::Mat to CvMat and viceversa

如何在OpenCV中将数据从cv :: Mat复制到CvMat,反之亦然?

According to the documentation for cv::Mat , cv::Mat has a constructor that takes a CvMat * argument and an operator CvMat() member function. Therefore copying between the two can be accomplished easily as follows.

cv::Mat m;

// populate m

CvMat n = m; // cv::Mat::operator CvMat() const;

m = cv::Mat(&n); // cv::Mat::Mat(const CvMat* m, bool copyData = false);
// or
m = cv::Mat(&n, true); // to copy the data

According to opencv documentation ( http://docs.opencv.org/2.4/modules/core/doc/basic_structures.html ):

"Backward conversion from Mat to CvMat or IplImage is provided via cast operators Mat::operator CvMat() const and Mat::operator IplImage(). The operators do NOT copy the data."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM