根据MTCNN中P网络的输出,反算到原图中画框
根据MTCNN中P网络的输出,反算到原图中画框
start_index是索引 offset是偏移量 cls是置信度 scale是缩放尺寸 stride是步长,MTCNN中步长是固定的 因为在做图像金字塔的时候,对原图乘以了一个scale,所以在反算的时候要除以scale
# 将回归量还原到原图上去 def __box(self, start_index, offset, cls, scale, stride=2, side_len=12): _x1 = (start_index[1] * stride) / scale _y1 = (start_index[0] * stride) / scale _x2 = (start_index[1] * stride + side_len) / scale _y2 = (start_index[0] * stride + side_len) / scale ow = _x2 - _x1 oh = _y2 - _y1 _offset = offset[:, start_index[0], start_index[1]] x1 = _x1 + ow * _offset[0] y1 = _y1 + oh * _offset[1] x2 = _x2 + ow * _offset[2] y2 = _y2 + oh * _offset[3] return [x1, y1, x2, y2, cls]
x1 = _x1 + ow * _offset[0] y1 = _y1 + oh * _offset[1] x2 = _x2 + ow * _offset[2] y2 = _y2 + oh * _offset[3] 上面的公式是这么回事: