Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PNG support for transparency #84

Merged
merged 2 commits into from
Mar 21, 2024
Merged

Add PNG support for transparency #84

merged 2 commits into from
Mar 21, 2024

Conversation

bipinkrish
Copy link
Contributor

@bipinkrish bipinkrish commented Mar 21, 2024

Issue for more info : #82

Copy link
Collaborator

@AmitMY AmitMY left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Good work! Minor modifications required/should be discussed.

@@ -74,7 +74,8 @@ def _draw_frame(self, frame: ma.MaskedArray, frame_confidence: np.ndarray, img)
@lru_cache(maxsize=None)
def _point_color(p_i: int):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would add transparency=False, since it can be that we don't want it.

@@ -74,7 +74,8 @@ def _draw_frame(self, frame: ma.MaskedArray, frame_confidence: np.ndarray, img)
@lru_cache(maxsize=None)
def _point_color(p_i: int):
opacity = c[p_i + idx]
np_color = colors[p_i % len(component.colors)] * opacity + (1 - opacity) * background_color
np_color = colors[p_i % len(component.colors)] * opacity + (1 - opacity) * background_color[:3]
np_color = np.append(np_color, opacity * 255)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only when transparency==True

@@ -110,7 +111,7 @@ def _point_color(p_i: int):

return img

def draw(self, background_color: Tuple[int, int, int] = (255, 255, 255), max_frames: int = None):
def draw(self, background_color: Tuple[int, int, int] = (255, 255, 255), max_frames: int = None, alpha: int = 0):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too I think we should have transparency, not alpha, because this will (IMO) break support for video exports

int_frames = np.array(np.around(self.pose.body.data.data), dtype="int32")
background = np.full((self.pose.header.dimensions.height, self.pose.header.dimensions.width, 3),
background = np.full((self.pose.header.dimensions.height, self.pose.header.dimensions.width, 4),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and then I'd split this into two cases, transparent or not

save_all=True,
duration=1000 / self.pose.body.fps,
loop=0)

def save_png(self, f_name: str, frames: Iterable[np.ndarray]):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think save_png and save_gif could be both using save_image(f_name: str, frames: ..., format="PNG", transparency=False) for example. right now the code is mostly duplicate

@@ -231,11 +235,45 @@ def save_gif(self, f_name: str, frames: Iterable[np.ndarray]):
images = [Image.fromarray(self.cv2.cvtColor(frame, self.cv2.COLOR_BGR2RGB)) for frame in frames]
images[0].save(f_name,
format="GIF",
append_images=images,
append_images=images[1:],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch!

@bipinkrish
Copy link
Contributor Author

All the changes requested are fixed

Copy link
Collaborator

@AmitMY AmitMY left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

absolutely fantastic.

@AmitMY AmitMY merged commit 581d4ce into sign-language-processing:master Mar 21, 2024
2 checks passed
@bipinkrish bipinkrish deleted the png branch March 21, 2024 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants