Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to replace a certain ROI with another image?

Hello,

I am making a simple app that was built from the face detection sample of the OpenCv4Android SDK. Basically my goal is to overlay or replace the detected face with another image like a smiley or a face of a dog, etc.

I tried to use copyTo(Mat dest) where dest is a submat of the entire image (basically the detected face region) and the Mat from which copyTo is called is the image to overlay or replace. This doesn't work though.

Can someone provide alternatives? Or maybe my understanding of copyTo is wrong? Hoping for some advice. Thanks and best regards,

click to hide/show revision 2
Added code out of comment

How to replace a certain ROI with another image?

Hello,

I am making a simple app that was built from the face detection sample of the OpenCv4Android SDK. Basically my goal is to overlay or replace the detected face with another image like a smiley or a face of a dog, etc.

I tried to use copyTo(Mat dest) where dest is a submat of the entire image (basically the detected face region) and the Mat from which copyTo is called is the image to overlay or replace. This doesn't work though.

Can someone provide alternatives? Or maybe my understanding of copyTo is wrong? Hoping for some advice. Thanks and best regards,


CODE THAT I USE - for clarity -

Mat capturedImage = Highgui.imread(<path/to/captured/image>) 
Mat selectedArea = capturedImage.submat(mDetectedFace) //mDetectedFace is a Rect object Mat replaceImage = Highgui.imread(<path/to/replacement/image>)

replaceImage.copyTo(selectedArea); 
Highgui.imwrite(<path/to/save/directory>, capturedImage)

How to replace a certain ROI with another image?

Hello,

I am making a simple app that was built from the face detection sample of the OpenCv4Android SDK. Basically my goal is to overlay or replace the detected face with another image like a smiley or a face of a dog, etc.

I tried to use copyTo(Mat dest) where dest is a submat of the entire image (basically the detected face region) and the Mat from which copyTo is called is the image to overlay or replace. This doesn't work though.

Can someone provide alternatives? Or maybe my understanding of copyTo is wrong? Hoping for some advice. Thanks and best regards,


CODE THAT I USE - for clarity -

Mat capturedImage = Highgui.imread(<path/to/captured/image>) 
Mat selectedArea = capturedImage.submat(mDetectedFace) //mDetectedFace is a Rect object  Mat replaceImage = Highgui.imread(<path/to/replacement/image>)

replaceImage.copyTo(selectedArea); 
Highgui.imwrite(<path/to/save/directory>, capturedImage)