Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

one module of our OpenCV software will be developed by another company

the short answer:

please try to convince them to use cv::Mat, not a shared_ptr.

the long one:

you might try something like this:

Mat src = ...
shared_ptr<char> p( static_cast<char>(src.data) );
PartnerCompanyModule( p, src.type(), src.cols, src.rows );

but now youre in trouble, since both Mat and shared_ptr want to delete the data !

once you use a shared_ptr, it tries to take ownership of the data.

you could again hack it:

src.addref(); // so the Mat won't  delete it
shared_ptr<char> p( static_cast<char>(src.data) );

but seriously, that's terrible. a "whack a mole" game with refcounts, design HELL !

one module of our OpenCV software will be developed by another company

the short answer:

please try to convince them to use cv::Mat, not a shared_ptr.

the long one:

you might try something like this:

Mat src = ...
shared_ptr<char> p( static_cast<char>(src.data) );
PartnerCompanyModule( p, src.type(), src.cols, src.rows );

but now youre in trouble, since both Mat and shared_ptr want to delete the data !

once you use a shared_ptr, it tries to take ownership of the data.

you could again hack it:

src.addref(); // so the Mat won't  delete it
shared_ptr<char> p( static_cast<char>(src.data) );

but seriously, that's terrible. a "whack a mole" game with refcounts, design HELL !terrible.