cvWarpAffine and masks

So I need to take a black and white image, rotate it and stamp it on to another image without the white spaces overlapping.

I wrote this which works for the most part.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void stamp(
    IplImage * src, 
    IplImage * dst, 
    CvRect r,
    double angle=-50.0,
    double scale = 1
    ){
      CvPoint2D32f center = cvPoint2D32f(src->width/2,src->height/2);
      CvMat*  rot_mat = cvCreateMat(2,3,CV_32FC1); 
      IplImage * intermediate = cvCloneImage(src);

      cv2DRotationMatrix(center,angle,scale,rot_mat);                                          
            cvWarpAffine(src,intermediate,rot_mat,CV_WARP_FILL_OUTLIERS,cvScalarAll(255));
      IplImage * mask = cvCloneImage(intermediate);
      cvNot(mask,mask); 
      cvSetImageROI(dst, r); 
      cvCopy(intermediate,dst,mask); 
      cvResetImageROI(dst);
      cvReleaseImage(&mask); 
      cvReleaseMat(&rot_mat);
      cvReleaseImage(&intermediate);      


I loose a bit of image quality which would be great if I could improve, but it is acceptable. what I can't figure out is why I need the intermediate. Originally I was trying to save lines of code by
1. copying the source to the mask
2. zeroing the mask
3 applying the transform from the source to the mask
4 zeroing the src and copying the mask to the source
5 cvNot(mask)

this came out horrible, The Image was inverted with horrible quality.

any explanations?
never mind. Figured it out.
Accidently inverted the mask twice.
Topic archived. No new replies allowed.