簡體   English   中英

查找覆蓋原始矩形的旋轉矩形的大小

[英]Find size of rotated rectangle that covers orginal rectangle

大家好,我有一個來自人臉檢測系統的人臉邊界框,格式為[x1, y1, x2, y2]

我想裁剪並對齊臉部,我目前的方法如下:從眼睛 position 計算角度,然后使用 cv2 warpAffine function 旋轉和裁剪。

問題是新的旋轉邊界框沒有完全覆蓋舊邊界框,我如何計算新邊界框的大小使其完全包含舊邊界框

選擇矩形的原始圖像

原始圖像

裁剪和旋轉的圖像

對齊的圖像

代碼做裁剪部分

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))

大盒子的尺寸是(對於w,h = width, height ,旋轉角度Fi ):

 H = w * Abs(Sin(Fi)) + h * Abs(Cos(Fi))
 W = w * Abs(Cos(Fi)) + h * Abs(Sin(Fi))

中心保持不變,所以底角坐標是

xx = centerx - (W-w)/2
yy = centery - (H-h)/2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM