简体   繁体   中英

Steal the resource of cv::Mat to IplImage

below is the source codes of copying the resource of cv::Mat into the IplImage

//copy the resource of src into IplImage
void copy_mat_Ipl(cv::Mat const &src, IplImage **dst)
{
         IplImage* old = *dst;
        IplImage temp_src = src;
        *dst = cvCloneImage(&temp_src);
        cvReleaseImage(&old);
}

but I don't want to copy it, what I want is steal the resource from cv::Mat I have to steal it, because the cv::Mat could be a local object in a function If I don't steal it but do something like this

void move_mat_to_Ipl(cv::Mat &src, IplImage **dst)
{
         IplImage* old = *dst;            
        **dst = src;
        cvReleaseImage(&old);
}

void some_function(IplImage **dst)
{
   cv::Mat src;
   //do something
   move_mat_to_Ipl(src, dst);
}

The resource of src will be free, then dst will hold a dangling pointer How could I steal the resource of cv::Mat?

You will have to change the move_mat_to_Ipl function

IplImage ** move_mat_to_Ipl(cv::Mat &src, IplImage **dst)
{
    IplImage* old = *dst;
    IplImage temp_src = src;
    **dst = src;
    cvReleaseImage(&old);

    return **dst;
}

This will return the **dst and then you are able to pass it into the other function

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