fix(pre_commit): 🎨 auto format pre-commit hooks

This commit is contained in:
pre-commit-ci[bot] 2023-10-18 20:46:24 +00:00
parent aabca4a4b5
commit b35a6161dd
1 changed files with 9 additions and 6 deletions

View File

@ -172,17 +172,20 @@ def draw_text(
def draw_image(
scene: np.ndarray, image: Union[str, np.ndarray], opacity: float, rect: Rect
scene: np.ndarray, image: Union[str, np.ndarray], opacity: float, rect: Rect
) -> np.ndarray:
"""
Draws an image onto a given scene with specified opacity and dimensions.
"""
# Input checks
assert 0.0 <= opacity <= 1.0, "Opacity has to be between 0.0 and 1.0."
assert rect.x >= 0 and rect.y >= 0, "Top left coordinates of the rect must be positive."
assert (
rect.x >= 0 and rect.y >= 0
), "Top left coordinates of the rect must be positive."
assert rect.width > 0 and rect.height > 0, "Rect dimensions should be positive."
assert rect.x + rect.width <= scene.shape[1] and rect.y + rect.height <= \
scene.shape[0], "Image exceeds scene bounds."
assert (
rect.x + rect.width <= scene.shape[1] and rect.y + rect.height <= scene.shape[0]
), "Image exceeds scene bounds."
# Read image if a path is provided
if isinstance(image, str):
@ -204,12 +207,12 @@ def draw_image(
alpha_channel = cv2.convertScaleAbs(alpha_channel * opacity)
# Get ROI from the scene
scene_roi = scene[rect.y:rect.y + rect.height, rect.x:rect.x + rect.width]
scene_roi = scene[rect.y : rect.y + rect.height, rect.x : rect.x + rect.width]
# Blend the image and the ROI
blended_roi = cv2.addWeighted(scene_roi, 1 - opacity, image, opacity, 0)
# Apply the blended ROI to the scene
scene[rect.y:rect.y + rect.height, rect.x:rect.x + rect.width] = blended_roi
scene[rect.y : rect.y + rect.height, rect.x : rect.x + rect.width] = blended_roi
return scene