I’ve got a texture captured from a webcam with people in it. I have used opencv to find the rectangle around a face in the image.
I want to:
- take a portion of the image - defined by the rectangle
- mask it out with a soft edged mask to frame the face
- apply a helmet image over the top.
It would look something like this (where original crowd image is much bigger)
So I am hoping to use the Cardmaker class and several texture stages.
But two of the textures are UV 0…1 but the original face is a tiny subset of the UV range.
So I need multiple UV sets on the Card.
But I can’t work out how to add them to a card object.
My mask image is:
My helmet image is:
(Any image will do for the face in a crowd image.)
I imagine my code might look something like this:
-but how do I get my UVs in there as well ?
- alpha mask values not right yet.
def make_card(self, x1,y1,x2,y2):
texface = loader.loadTexture("models/crowd.jpg")
texhelment = loader.loadTexture("models/helmet.png")
texmask = loader.loadTexture("models/headmask.png")
cm = CardMaker('head')
cm.setFrame(-1,1,-1,1)
self.facecard = render2d.attachNewNode(cm.generate(),2)
self.facecard.setColor(0,0,0,1)
self.facecard.setTransparency(TransparencyAttrib.MAlpha)
#
self.tsface = TextureStage('base')
self.tsface.setMode(TextureStage.MReplace)
self.facecard.setTexture(self.tsface, texface)
#
self.tsmask = TextureStage('mask')
self.tsmask.setCombineAlpha(TextureStage.CMSubtract,
TextureStage.CSPrevious,
TextureStage.COSrcColor,
TextureStage.CSTexture,
TextureStage.COSrcAlpha)
self.facecard.setTexture(self.tsmask, texmask)
#
self.tshelmet = TextureStage('helmet')
self.tshelmet.setMode(TextureStage.MDecal)
self.facecard.setTexture(self.tshelmet, texhelment)
Any ideas on how to make this work ?