Warm tip: This article is reproduced from serverfault.com, please click

How to put an image on a t-shirt using Python OpenCV

发布于 2020-11-28 05:25:27

I'm trying to put any custom image on a blank t-shirt as done below

enter image description here

I'm using Python's CV2. Any idea how that could be done? I'm thinking cv2.inRange could point me to the white t-shirt and then I could resize the image to fit the shirt, but I'm not sure how to preserve the shadow and wrinkle effects. Maybe with edge detection?

Questioner
rcmenoni
Viewed
0
Christoph Rackwitz 2020-11-29 08:10:44

you want to "blend" the overlay onto the image. open an image editor and explore the blend modes it has for layers. I would suggest trying the "multiply" and "overlay" modes.

OpenCV has some limited support for blending but I would suggest formulating the calculation yourself. the Wikipedia article should help. for a multiply, I would convert both pictures to CV_32F, scale them by 1/255 (so the range is 0.0 .. 1.0), then just multiply them elementwise.

getting a mask for the t-shirt is a useful step. that will let you place the overlay only on the t-shirt, not on the background or skin of the model.

multiply blend using SO logo with white background on a picture from pxhere.com

edge detection is not at all applicable here.