-
Notifications
You must be signed in to change notification settings - Fork 23
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
Conversation
There was a problem hiding this 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): |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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]): |
There was a problem hiding this comment.
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:], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch!
All the changes requested are fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
absolutely fantastic.
Issue for more info : #82