Ask Your Question
1

How to create a semi transparent shape?

asked 2014-06-28 10:34:05 -0600

Robby18 gravatar image

updated 2015-10-20 10:24:38 -0600

Hi,

I would like to know, how to create a semi-transparent form like this: http://tellthattomycamera.wordpress.com/

I tried this:

rectangle (img, Point (100,100), Point (300,300), Scalar (0,125,125,0.4), CV_FILLED);

But does not work.

I know that the functions do not support alpha-transparency when the target image is 4-channel. But i use a 3-channel image (from webcam).

So why doesn't it work?

Thanks

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2014-06-29 22:27:55 -0600

Haris gravatar image

updated 2014-06-30 01:41:59 -0600

You can use addWeighted to create such an effect.

Like,

  • Load source image.

  • Create a black image with same type and channel as source.

  • Draw whatever you want on black image.

  • Use aaddWeighted, adjust alpha and beta(weight each array element) till you get the desired result.

edit flag offensive delete link more

Comments

Thanks for the reply. I have just one last question, how do you use "alpha component" in the class Scalar? http://docs.opencv.org/modules/core/doc/drawing_functions.html

Robby18 gravatar imageRobby18 ( 2014-06-30 07:49:57 -0600 )edit
2

According to a note in http://docs.opencv.org/3.2.0/d6/d6e/group__imgproc__draw.html, "The functions do not support alpha-transparency when the target image is 4-channel. In this case, the color[3] is simply copied to the repainted pixels. Thus, if you want to paint semi-transparent shapes, you can paint them in a separate buffer and then blend it with the main image."

efreet gravatar imageefreet ( 2017-04-05 14:17:58 -0600 )edit

Question Tools

Stats

Asked: 2014-06-28 10:34:05 -0600

Seen: 10,223 times

Last updated: Jun 30 '14