gpt4 book ai didi

c++ - 用opencv着色

转载 作者:太空宇宙 更新时间:2023-11-03 22:50:48 26 4
gpt4 key购买 nike

我正在尝试做一些我以前见过的事情,我认为这很简单,但你知道那是怎么回事。

考虑下面的代码:

            vector<Point> polypoints{topleft,topright,bottomright,bottomleft};
vector<vector<Point>> arrayofpolypoints{polypoints};
fillPoly(frame, arrayofpolypoints, color3, LINE_8 ,0,Point(0,0));

我取 4 个给定点并在 Mat 图像上绘制/填充多边形。简单吧?现在我希望这个多边形具有透明度或阴影区域,而不是使其成为实体(或者用实体边​​框阴影会很好)。但似乎 OpenCV 中没有函数已经做到了这一点,所以现在我必须发明一些东西。有什么想法吗?

我认为在另一个空白 Mat 图像上绘制多边形可能会更好,然后遍历每个像素并涂黑所有其他像素(或某种比率)。然后我可以以某种方式组合初始框架和新垫子。这有意义吗?

最佳答案

我最终做了以下事情:

                            vector<Point> polypoints{topleft,topright,bottomright,bottomleft};
vector<vector<Point>> arrayofpolypoints{polypoints};
destimage = Scalar::all(0);
fillPoly(destimage, arrayofpolypoints, color3, LINE_8 ,0,Point(0,0));
double transparency = 0.5;
for (int i = 0; i < frame.cols; i++) {
for (int j = 0; j < frame.rows; j++) {
Vec3b &intensity = frame.at<Vec3b>(j, i);
Vec3b &intensityoverlay = destimage.at<Vec3b>(j, i);
for(int k = 0; k < frame.channels(); k++) {
uchar col = intensityoverlay.val[k];
if (col != 0){
intensity.val[k] = (intensity.val[k]*(1-transparency) + (transparency*col));
}
}
}
}

关于c++ - 用opencv着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38131066/

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