-1

I want to add a transparent image like a cloth on human body part. I have done the part like where to put that cloth. I calculated the points also but the main part is how to place the transparent image on my human body image. Anybody knows simple python code to place transparent image on another image. please help me .

  • `cv2.addWeighted()` See the [documentation](https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_core/py_image_arithmetics/py_image_arithmetics.html) – Jeru Luke May 01 '18 at 07:56

1 Answers1

1

It's fairly easy to do with the addWeighted() function

Here is a tutorial -https://www.pyimagesearch.com/2016/03/07/transparent-overlays-with-opencv/

Relevant code snippet is:

# apply the overlay
cv2.addWeighted(overlay, alpha, output, 1 - alpha,
    0, output)

With the arguments being described as:

The first is our overlay , the image that we want to “overlay” on top of the original image using a supplied level of alpha transparency.

The second parameter is the actual alpha transparency of the overlay. The closer alpha is to 1.0, the more opaque the overlay will be. Similarly, the closer alpha is to 0.0, the more transparent the overlay will appear.

The third argument to cv2.addWeighted is the source image — in this case, the original image loaded from disk.

We supply the beta value as the fourth argument. Beta is defined as 1 - alpha . We need to define both alpha and beta such that alpha + beta = 1.0 .

The fifth parameter is the gamma value — a scalar added to the weighted sum. You can think of gamma as a constant added to the output image after applying the weighted addition. In this case, we set it to zero since we do not need to apply an addition of a constant value.

Finally, we have the last argument, output , which is the output destination after applying the weighted sum operation — this value is our final output image.

GPPK
  • 6,546
  • 4
  • 32
  • 57