I draw objects on IplImage like this:
cvLine(image, point_1, point_2, color, thickness, CV_AA); // Line
cvCircle(mage, point, radius, color, thickness, CV_AA); // Circle
// and some others...
How can I draw them translucent? cv::Scalar does not support alpha channel, if I understand correctly. I found something similar, but not quite appropriate: link. Here we are talking about translucenty IplImage, not about the objects on it.
So, I tested it now with
IplImageandcv::Mat, and bothcvCircleandcv::circledon't support drawing semi-transparent objects. I used OpenCV 3.4.0, since this version still supports the old C API.Let's have a look at the following code:
We create a blue 4-channel image with zero transparency, and draw a red circle with 0.5 transparency. In both cases, we get the following output:
We see, that the part of red circle actually "replaces" the pixel values in the original blue image.
So, for
IplImageas well as forcv::Matwe need to use blending, e.g. usingaddWeighted. Let's have a look at this code:In fact, we create a blue 3-channel background image like this:
And, we create a black foreground 3-channel image of the same size with the red circle:
Using
addWeightedwithalpha = 1andbeta = 0.5, we get the expected output for both versions: