I'm new to openface. I know how to get an aligned face using openface.AlignDlib.align(), but is there anyway to transform the face back to its original shape?
Asked
Active
Viewed 370 times
0
-
how is it different from keeping `rgbImg` you pass to `.align()`? – Marat Mar 01 '17 at 01:53
-
Just curious, what does your question have anything to do with opencv? – Quang Hoang Mar 01 '17 at 03:33
-
@Marat: let's say i made some modification to the aligned image and i want to keep that modification when I get back to the original rbgImg. – windancer Mar 01 '17 at 06:33
1 Answers
1
What you basically need is an inverse affine transformation. So, we need to get an inverse transformation matrix, and then apply warpAffine
. Here is a piece of align()
code:
npLandmarkIndices = np.array(landmarkIndices)
H = cv2.getAffineTransform(npLandmarks[npLandmarkIndices],
imgDim * MINMAX_TEMPLATE[npLandmarkIndices])
thumbnail = cv2.warpAffine(rgbImg, H, (imgDim, imgDim))
H
is not stored anywhere, so we need to learn the transform matrix:
H_reverse = cv2.getAffineTransform(
imgDim * MINMAX_TEMPLATE[npLandmarkIndices],
npLandmarks[npLandmarkIndices])
inverse_projection = cv2.warpAffine(thumbnail, H_reverse, rgbImg.shape)
I did not check if the code is actually working, but I hope you can get the direction

Marat
- 15,215
- 2
- 39
- 48