0
votes

I'm designing c++/CLI library with many dll's and internal usage of opencv. OpenCV matrices are passed between theese dll and that is origin of my question:

Do you how to force cv::Mat to behave similar to std::unique_ptr, std::shared_ptr and std::weak_ptr?

A far as I know cv::Mat behave similar to std::shared_ptr (with reference counter), but what about other types of smart pointers?

1
Maybe, you can use the functions such as Mat::clear()/Mat.copyTo()/cv::swap() to simulate the other smart pointer operations.Kinght 金
If cv::Mat is a C++ wrapper for CvMat (C counterpart) then maybe you could make your own UniqueMat wrapper with deleted copy constructor or whatever features you need. I guess it might be a little more work, though.slawekwin

1 Answers

1
votes

By far the easiest method would be std::unique_ptr<cv::Mat>. It has the additional benefit of being obvious to future maintainers.

By itself this won't prevent others from holding on their own cv::Mat copy which would share ownership. You can partially prevent that: If ownership could be shared, clone the cv::Matbefore putting it into thestd::unique_ptr`. But anyone can later create additional cv::Mat's sharing ownership.