修正涂抹框旋转
This commit is contained in:
@@ -115,6 +115,7 @@ def rotate_image(img, angle):
|
||||
def rotate_rectangle(rectangle, center, angle):
|
||||
def rotate_point(pt, angle, center):
|
||||
matrix = cv2.getRotationMatrix2D(center, angle, 1)
|
||||
if angle != 180:
|
||||
# 旋转后平移
|
||||
matrix[0, 2] += center[1] - center[0]
|
||||
matrix[1, 2] += center[0] - center[1]
|
||||
@@ -124,6 +125,9 @@ def rotate_rectangle(rectangle, center, angle):
|
||||
pt = np.array([[pt[0]], [pt[1]], [1]])
|
||||
return np.dot(reverse_matrix, pt)
|
||||
|
||||
if angle == 0:
|
||||
return list(rectangle)
|
||||
|
||||
x1, y1, x2, y2 = rectangle
|
||||
|
||||
# 计算矩形的四个顶点
|
||||
@@ -193,7 +197,7 @@ def find_box_of_content(content, layout):
|
||||
)
|
||||
|
||||
|
||||
def mask_image(image, content):
|
||||
def get_mask_layout(image, content):
|
||||
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file:
|
||||
cv2.imwrite(temp_file.name, image)
|
||||
|
||||
@@ -238,7 +242,7 @@ def photo_mask(pk_phhd, content):
|
||||
for img in split_result:
|
||||
angles = get_image_rotation_angles(img["img"])
|
||||
rotated_img = rotate_image(img["img"], int(angles[0]))
|
||||
results = mask_image(rotated_img, content)
|
||||
results = get_mask_layout(rotated_img, content)
|
||||
|
||||
for result in results:
|
||||
height, width = img["img"].shape[:2]
|
||||
|
||||
Reference in New Issue
Block a user