kyamagu commited on
Commit
9099d46
1 Parent(s): aeda328

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +13 -9
README.md CHANGED
@@ -865,6 +865,13 @@ The Crello dataset has 3 splits: train, validation, and test. The current split
865
  Each example can be visualized in the following approach. Note the following does not guarantee a similar appearance to the original template.
866
 
867
  ```python
 
 
 
 
 
 
 
868
  def render(dataset: datasets.Dataset, example: Dict[str, Any], max_size: float=512.) -> bytes:
869
  """Render parsed sequence example onto an image and return as PNG bytes."""
870
  canvas_width = int(dataset.features["canvas_width"].int2str(example["canvas_width"]))
@@ -878,7 +885,7 @@ def render(dataset: datasets.Dataset, example: Dict[str, Any], max_size: float=5
878
  for index in range(example["length"]):
879
  pil_image = example["image"][index]
880
  image = skia.Image.frombytes(
881
- pil_image.convert("RGBA").tobytes(),
882
  pil_image.size,
883
  skia.kRGBA_8888_ColorType)
884
  left = example["left"][index] * canvas_width
@@ -888,14 +895,11 @@ def render(dataset: datasets.Dataset, example: Dict[str, Any], max_size: float=5
888
  rect = skia.Rect.MakeXYWH(left, top, width, height)
889
 
890
  angle = example["angle"][index]
891
- if angle != 0:
892
- degree = 180. * angle / np.pi
893
- canvas.save()
894
- canvas.rotate(degree, left + width / 2., top + height / 2.)
895
-
896
- canvas.drawImageRect(image, rect)
897
- if angle != 0:
898
- canvas.restore()
899
 
900
  image = surface.makeImageSnapshot()
901
  with io.BytesIO() as f:
 
865
  Each example can be visualized in the following approach. Note the following does not guarantee a similar appearance to the original template.
866
 
867
  ```python
868
+ import io
869
+ from typing import Any, Dict
870
+
871
+ import numpy as np
872
+ import skia
873
+
874
+
875
  def render(dataset: datasets.Dataset, example: Dict[str, Any], max_size: float=512.) -> bytes:
876
  """Render parsed sequence example onto an image and return as PNG bytes."""
877
  canvas_width = int(dataset.features["canvas_width"].int2str(example["canvas_width"]))
 
885
  for index in range(example["length"]):
886
  pil_image = example["image"][index]
887
  image = skia.Image.frombytes(
888
+ pil_image.convert('RGBA').tobytes(),
889
  pil_image.size,
890
  skia.kRGBA_8888_ColorType)
891
  left = example["left"][index] * canvas_width
 
895
  rect = skia.Rect.MakeXYWH(left, top, width, height)
896
 
897
  angle = example["angle"][index]
898
+ with skia.AutoCanvasRestore(canvas):
899
+ if angle != 0:
900
+ degree = 180. * angle / np.pi
901
+ canvas.rotate(degree, left + width / 2., top + height / 2.)
902
+ canvas.drawImageRect(image, rect)
 
 
 
903
 
904
  image = surface.makeImageSnapshot()
905
  with io.BytesIO() as f: