gpt4 book ai didi

c++ - 如何创建一个半透明的形状?

转载 作者:IT老高 更新时间:2023-10-28 21:38:19 32 4
gpt4 key购买 nike

我想知道如何在OpenCV中绘制半透​​明的形状,类似于下图(来自http://tellthattomycamera.wordpress.com/)

enter image description here

我不需要那些花哨的圆圈,但我希望能够绘制一个矩形,例如,在 3 channel 彩色图像上并指定矩形的透明度,例如

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

其中 0,125,125 是矩形的颜色,0.4 指定透明度。然而,OpenCV 并没有将此功能内置到其绘图功能中。如何在 OpenCV 中绘制形状,以便通过该形状部分看到正在绘制的原始图像?

最佳答案

下图说明了使用 OpenCV 的透明度。您需要在图像和矩形之间进行 alpha 混合。下面是执行此操作的一种方法的代码。

enter image description here

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

int main( int argc, char** argv )
{
cv::Mat image = cv::imread("IMG_2083s.png");
cv::Mat roi = image(cv::Rect(100, 100, 300, 300));
cv::Mat color(roi.size(), CV_8UC3, cv::Scalar(0, 125, 125));
double alpha = 0.3;
cv::addWeighted(color, alpha, roi, 1.0 - alpha , 0.0, roi);

cv::imshow("image",image);
cv::waitKey(0);
}

关于c++ - 如何创建一个半透明的形状?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24480751/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com