Ask Your Question

Best way of masking on warpAffine?

asked 2013-05-29 16:52:17 -0600

Papercut gravatar image

updated 2013-05-29 18:05:56 -0600


Just like using mask when copying image:

image1.copyTo(image2, mask)

I just want to apply warpAffine only on a particular region because I only need a small part of image for example mouth. But existing warpAffine methods do not seem to accept any masks. Therefore I need to find a smart and easy way to do masking warpAffine method in order to reduce running time. Has anyone here thought about it before? Please give me some tips!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-05-30 07:30:37 -0600

Guanta gravatar image

If you have the ROI-coordiantes of the mouth, then you could apply warpAffine only onto that. Example:

// x0,y0,x1,y1 are the bounding coordinates of your mouth-region
// of course the same could be achieved with cv::Rect()
cv::Mat mouth_roi(whole_image, cv::Range(y0,y1), cv::Range(x0,x1));
// don't know if warpAffine works in-place, but give it a try:
cv::warpAffine(mouth_roi, mouth_roi, M, mouth_roi.size());

If that doesn't work you have to apply warpAffine to a different destination matrix and copy it back to mouth_roi. If they have different sizes it's getting slightly more complicated but the principle is the same.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2013-05-29 16:52:17 -0600

Seen: 1,515 times

Last updated: May 30 '13