聚opencv半透明

poly opencv semi-transperent

我的问题是针对 Opencv 专家的,我已经检测到道路线(左线和右线),所以我打算用半透明蓝色绘制道路区域。所以我用了:

cv::fillPoly(image, ppt, npt, 1, CV_RGB(0, 0,200), lineType);

ppt-包含左右的点, npt-点数

但是,我得到的是满马路的区域,这不是我的目标。

所以,我的问题是,有什么办法可以把道路区域涂成半透明的吗?我被告知要添加另一个频道,例如:

cv::Mat channel[3];
split(image, channel); 
    channel[0] = cv::Mat::zeros(image.rows, image.cols, CV_8UC1);
     merge(channel, 3, image);cv::imshow("kkk",image); 

但问题是我得到的所有图像都是半透明的,我只想要道路区域。任何想法表示赞赏!!

谢谢

试试这个代码(无法在手机上测试):

cv::Mat polyImage = cv::Mat(image.rows, image.cols, CV_8UC3,cv::Scalar (0,0,0));
cv::fillPoly(polyImage, ppt, npt, 1, CV_RGB(0, 0,200), lineType);

float transFactor = 0.5f; // the bigger the more transparent

for(int y=0;y <image.rows;++y)
    for(int x=0;x <image.cols; ++x)
    {
        if(polyImage.at<cv::Vec3b>(y,x) != cv::Vec3b(0,0,0) )
            image.at<cv::Vec3b>(y,x) = (transFactor)*image.at<cv::Vec3b>(y,x) + (1.0f - transFactor)*polyImage.at<cv::Vec3b>(y,x);
    }