[英]Find size of rotated rectangle that covers orginal rectangle
Hi everyone I have a bounding box of faces from the face detection system in the format [x1, y1, x2, y2]
.大家好,我有一个来自人脸检测系统的人脸边界框,格式为[x1, y1, x2, y2]
。
I want to crop out and align the face my current approach is as follows: calculate the angle from the eye position then rotate and crop using cv2 warpAffine function.我想裁剪并对齐脸部,我目前的方法如下:从眼睛 position 计算角度,然后使用 cv2 warpAffine function 旋转和裁剪。
The problem is the new rotated bounding box is not completely covering the old bounding box, how I can calculate the size of the new bounding box so it completely contains the old one问题是新的旋转边界框没有完全覆盖旧边界框,我如何计算新边界框的大小使其完全包含旧边界框
center = (x1 + x2) // 2, (y1 + y2) // 2
d_y = eye_center[1] - mouth_center[1]
d_x = eye_center[0] - mouth_center[0]
angle = np.degrees(np.arctan2(d_y, d_x)) + 90
M = cv2.getRotationMatrix2D(center, angle, 1)
M[0, 2] += (width * 0.5) - center[0] # width is x2-x1 from face detector
M[1, 2] += (height * 0.5) - center[1] # height is y2-y1 from face detector
res_img = cv2.warpAffine(img, M, (width, height))
Dimensions of larger box are (for w,h = width, height
of smaller box, rotation angle Fi
):大盒子的尺寸是(对于w,h = width, height
,旋转角度Fi
):
H = w * Abs(Sin(Fi)) + h * Abs(Cos(Fi))
W = w * Abs(Cos(Fi)) + h * Abs(Sin(Fi))
Center remains the same, so base corner coordinates are中心保持不变,所以底角坐标是
xx = centerx - (W-w)/2
yy = centery - (H-h)/2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.