CSS:规范化重叠的混合div的透明度

时间:2016-10-13 20:43:44

标签: javascript html css

假设我有代表一个人可用时间的div。不同的人'可用性可能重叠。我想用重叠的彩色div来表示这一点,其中重叠区域将合理地加总,因为表示所有人的重叠的区域将始终是相同的颜色(因此术语"标准化")。

我有两个重叠的div需要具有相同的不透明度和背景颜色,但重叠区域的不透明度需要标准化为1. opacity属性mix-blend-mode无法完成。{ 3}}。可以使用static Mat my_segment(Mat _inImage, Rect assumption, Rect face){ // human segmentation opencv // _inImage - input image // assumption - human rectangle on _inImage // face - face rectangle on _inImage // iterations - is being set externally /* GrabCut segmentation */ Mat bgModel,fgModel; // the models (internally used) Mat result; // segmentation result //*********************** step1: GrabCut human figure segmentation grabCut(_inImage, // input image result, // segmentation result assumption,// rectangle containing foreground bgModel,fgModel, // models iterations, // number of iterations cv::GC_INIT_WITH_RECT); // use rectangle // Get the pixels marked as likely foreground cv::compare(result,cv::GC_PR_FGD,result,cv::CMP_EQ); // upsample the resulting mask cv::Mat separated(assumption.size(),CV_8UC3,cv::Scalar(255,255,255)); _inImage(assumption).copyTo(separated,result(assumption)); // (bg pixels not copied) //return(separated); // return the innerings of assumption rectangle //*********************** step2: //cutting the skin with the mask based on the face rectangle Rect adjusted_face = face; adjusted_face.x = face.x - assumption.x; adjusted_face.y = face.y - assumption.y; //rectangle(separated, // adjusted_face.tl(), // adjusted_face.br(), // cv::Scalar(166,94,91), 2); //creating mask Mat mymask(separated.size(),CV_8UC1); // setting face area as sure background mymask.setTo(Scalar::all(GC_PR_FGD)); mymask(adjusted_face).setTo(Scalar::all(GC_BGD)); // performing grabcut grabCut(separated, mymask, cv::Rect(0,0,assumption.width,assumption.height), bgModel,fgModel, 1, cv::GC_INIT_WITH_MASK); // Just repeating everything from before // Get the pixels marked as likely foreground cv::compare(mymask,cv::GC_PR_FGD,mymask,cv::CMP_EQ); //here was the error //separated.copyTo(separated,mymask); // bg pixels not copied cv::Mat res(separated.size(),CV_8UC3,cv::Scalar(255,255,255)); separated.copyTo(res,mymask); // bg pixels not copied //*************************// //return(separated); // return the innerings of assumption rectangle return(res); } 属性来完成,也可以调整背景颜色吗?

since the opacity of the second layer would have to be 1

例如,如果有3个div,并且所有3个div重叠某个区域,则该区域需要与初始场景中的最终颜色相同(只有2个区域,以及某些区域重叠的区域)。 / p>

1 个答案:

答案 0 :(得分:0)

你可以一起使用绝对定位和不透明度吗?因此,给每个div提供相同的不透明度,并将一个div放在另一个div上,以有效地总结背景。

.container {
  position: relative;
  height: 200px;
}

.box {
  height: 100px;
  width: 100px;
  background: #000099;
  border: 1px solid #fff;
  opacity: 0.5;
}

.two {
  position: absolute;
  top: 80px;
}

像这样JsFiddle