判断rect2在rect1上重贴面积
public boolean calculateAreas(TbCusCameraRecognitionAreas rect1, TbCusCameraRecognitionAreas rect2) {
if (rect1 == null || rect2 == null) {
return true;
}
try {
double p1_x = Double.parseDouble(rect1.getImgX());//rect1左下角X
double p1_y = Double.parseDouble(rect1.getImgY());//rect1左下角Y
double p2_x = p1_x + Double.parseDouble(rect1.getImgW());//rect1右上角X
double p2_y = p1_y + Double.parseDouble(rect1.getImgH());//rect1域右上角Y
double p3_x = Double.parseDouble(rect2.getImgX());//rect2左下角X
double p3_y = Double.parseDouble(rect2.getImgY());//rect2左下角Y
double p4_x = p3_x + Double.parseDouble(rect2.getImgW());//rect2右上角X
double p4_y = p3_y + Double.parseDouble(rect2.getImgH());//rect2右上角X
//当没有重叠的时候
if (p1_x > p4_x || p2_x < p3_x || p1_y > p4_y || p2_y < p3_y) {
return false;
}
//计算重叠的宽
double wid = Math.min(p2_x, p4_x) - Math.max(p1_x, p3_x);
//计算重叠的高
double hight = Math.min(p2_y, p4_y) - Math.max(p1_y, p3_y);
double overlapArea = wid * hight;//重叠的面积
log.info("重叠面积:{}", overlapArea);
//识别的面积
double totalArea = Double.parseDouble(rect2.getImgH()) * Double.parseDouble(rect2.getImgW());
log.info("算法识别面积:{}", totalArea);
log.info("占比:{}", (overlapArea / totalArea));
//重叠面积占用识别的面积,大于等于配置的百分比,就通过
if ((overlapArea / totalArea) < scale) {
return false;
}
return true;
} catch (Exception e) {
log.error("计算重叠面积错误", e);
return false;
}
}
标签:p3,java,double,parseDouble,重贴,Double,四边形,rect2,rect1
From: https://blog.csdn.net/duqiang5114/article/details/143770761