Ask Your Question
0

function trouble upgrading from c to c++

asked 2014-03-16 11:37:16 -0600

mreff555 gravatar image

updated 2014-03-16 11:47:26 -0600

berak gravatar image

I have a very small simple function using opencv libraries which takes a source image and stamps it to a location on a destination image. No matter what I try I am getting nowhere trying to update it to a c++ format. Here is the original.

void coriolus::stamp(IplImage * src, IplImage *dst, CvRect r)
{
      IplImage * mask = cvCloneImage(src);
      cvNot(mask,mask);
      cvSetImageROI(dst, r);
      cvCopy(src,dst,mask); 
      cvResetImageROI(dst); 
      cvReleaseImage(&mask);    
}

I actually thought it would be something simple like

void stamp(Mat src, Mat dst, Rect r)
{
    Mat mask = src.clone();
    bitwise_not(mask,mask);
    dst.adjustROI( Rect(r) );
    src.copyTo(dst,mask);
}

what am I missing?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-03-16 11:52:45 -0600

berak gravatar image

updated 2014-03-16 12:03:37 -0600

i think, you're just lacking some refs:

void stamp(const Mat &src, Mat &dst, const Rect &r)
{
    Mat mask = src.clone();
    bitwise_not(mask,mask);
    // hmm, adjustROI is not exactly the same as the c-code above
    // i can only guess here, but i think, you wanted this:
    // src.copyTo( dst(r), mask );
    dst.adjustROI( r );
    src.copyTo(dst,mask);
}

the important one is: Mat &dst , without it, the dst Mat won't get the roi updated ( only the pixels), because you're passing in a copy

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-03-16 11:37:16 -0600

Seen: 218 times

Last updated: Mar 16 '14