Ask Your Question
0

How to draw line with alpha transparency?

asked 2019-03-28 22:55:17 -0600

LucasJin gravatar image

I know there is a addWeighted method. But what I need is draw many lines, every line with different transparency.

Which means, can not using N mask to draw then addWeighted, that too slow speed.

To draw a line on BGR format image:

line(img_a, p1, p2, c, 2, CV_AA);

It does not add alpha even c is Scalar with alphas.

I convert image from BGR to BGRA with 4 channels, but the line still full with color rather than with transparency.

Any body could help me out with simply what I need?

serveral lines with difference transparency on a color image (not using addWeighted that is slow I have 500 lines).

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-03-29 01:44:40 -0600

berak gravatar image

there is no real support for anything related to alpha transparency in opencv (it's a computer-vision library, not photoshop), you have to live with it.

you can draw things with CV_8UC4 color into a CV_8UC4 image, but it will replace the previous pixel value, not do any "alpha composition" there.

edit flag offensive delete link more

Comments

thank u sir, for your reply. However, I really want a example to prove that, draw a line (retangle whatever) with Scalor(112, 112, 112, 0.4) on a 4 channel color image, will it shows in transparent? If not, then I shall give it up. Although I know using weighted to add a mask, but if my shape is many and small, the alpha are not same indivisual, so it's really does not know how to achieve that purpose.

LucasJin gravatar imageLucasJin ( 2019-03-29 03:11:34 -0600 )edit

will it shows in transparent?

again, no. also remember, that it's [0..255] with uchar pixels, not [0..1] (as you have it above)

what you expected was some "composition", like src_col + dst_col*alpha , instead what you get is just dst_col

berak gravatar imageberak ( 2019-03-29 03:24:40 -0600 )edit

Use cv::addWeighted() to mimic an alpha channel. Draw on a copy of the original image and then do weighted addition of the two.

Der Luftmensch gravatar imageDer Luftmensch ( 2019-03-30 14:27:14 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-03-28 22:55:17 -0600

Seen: 13,230 times

Last updated: Mar 29 '19