浏览代码

develop segmentation preview in streamlit, fix dependency on system to get font

/pyrception-integration
leopoldo-zugasti 4 年前
当前提交
8f35c953
共有 5 个文件被更改,包括 128 次插入8 次删除
  1. 2
      com.unity.perception/Editor/Pyrception/PyrceptionInstaller.cs
  2. 74
      com.unity.perception/Editor/Pyrception/pyrception-utils/pyrception_utils/preview.py
  3. 5
      com.unity.perception/Editor/Pyrception/pyrception-utils/pyrception_utils/pyrception.py
  4. 34
      com.unity.perception/Editor/Pyrception/pyrception-utils/pyrception_utils/NairiNormal-m509.ttf
  5. 21
      com.unity.perception/Editor/Pyrception/pyrception-utils/pyrception_utils/NairiNormal-m509.ttf.meta

2
com.unity.perception/Editor/Pyrception/PyrceptionInstaller.cs


string command = "";
#if UNITY_EDITOR_WIN
command = $"cd \"{path}\\DataInsightsEnv\\Scripts\\\" && activate && cd \"{pathToData}\\..\" && \"{path}\\DataInsightsEnv\\Scripts\\pyrception-utils.exe\" preview --data=\".\"";
command = $"cd \"{path}\\DataInsightsEnv\\Scripts\\\" && activate && cd \"{pathToData}\\..\" && \"{path}\\DataInsightsEnv\\Scripts\\pyrception-utils.exe\" preview --data=\".\"";
#elif (UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX)
command = $"cd \"{path}/DataInsightsEnv/bin\"; activate; cd \"{pathToData}/..\" ; \"{path}/DataInsightsEnv/bin/pyrception-utils\" preview --data=\".\"";
#endif

74
com.unity.perception/Editor/Pyrception/pyrception-utils/pyrception_utils/preview.py


import argparse
import os
import pathlib
from typing import Dict, List, Tuple
import numpy as np

:param description: Image description
:type str:
"""
image = image.copy()
font = ImageFont.truetype("C:\\Windows\\Fonts\\Arial.ttf", 15)
st.text("There are " + str(len(classes)) + " classes")
path_to_font = pathlib.Path(__file__).parent.absolute()
font = ImageFont.truetype(f"{path_to_font}/NairiNormal-m509.ttf", 15)
for label, box in zip(labels, boxes):
label = label - 1
class_name = classes[label]

st.image(image, use_column_width=True)
def draw_image_with_semantic_segmentation(
image: Image,
height: int,
width: int,
segmentation: Image,
header: str,
description: str,
):
"""
Draws an image in streamlit with labels and bounding boxes.
:param image: the PIL image
:type PIL:
:param height: height of the image
:type int:
:param width: width of the image
:type int:
:param segmentation: Segmentation Image
:type PIL:
:param header: Image header
:type str:
:param description: Image description
:type str:
"""
# image_draw = ImageDraw(segmentation)
image = image.copy()
(seg_r, seg_g, seg_b) = segmentation.getpixel((0, 0))
st.sidebar.markdown('# Segmentation color intensity')
color_intensity = st.sidebar.slider('color intensity (%)', 0, 100, 65);
alpha = color_intensity / 100;
for x in range(0, width - 1):
for y in range(0, height - 1):
(seg_r, seg_g, seg_b) = segmentation.getpixel((x, y))
(r, g, b) = image.getpixel((x, y))
# if it isn't a black pixel in the segmentation image then highlight it with the segmentation color
if seg_r != 0 or seg_g != 0 or seg_b != 0:
image.putpixel((x, y),
(int((1 - alpha) * r + alpha * seg_r),
int((1 - alpha) * g + alpha * seg_g),
int((1 - alpha) * b + alpha * seg_b)))
st.subheader(header)
st.markdown(description)
st.image(image, use_column_width=True)
def display_count(
header: str,
description: str,
):
"""
:param header: Image header
:type str:
:param description: Image description
:type str:
"""
return
@st.cache(show_spinner=True, allow_output_mutation=True)
def load_perception_dataset(path: str) -> Tuple:
"""

"hello", classes
)
image_index = frame_selector_ui(dataset)
image, target = dataset[image_index]
image, segmentation, target = dataset[image_index]
image, classes, labels, boxes, colors, "Synthetic Image Preview", ""
image, classes, labels, boxes, colors, "Bounding Boxes Preview", ""
)
draw_image_with_semantic_segmentation(
image, dataset.metadata.image_size[0], dataset.metadata.image_size[1], segmentation, "Semantic Segmentation Preview", ""
)

parser = argparse.ArgumentParser()
parser.add_argument("data", type=str)
args = parser.parse_args()
print("\n")
print("The path is: " + args.data)
preview_app(args)

5
com.unity.perception/Editor/Pyrception/pyrception-utils/pyrception_utils/pyrception.py


image = Image.open(
os.path.join(self.metadata.data_dir, self.data[sub_index]["filename"])
).convert("RGB")
segmentation = Image.open(
os.path.join(self.metadata.data_dir, self.data[sub_index]["annotations"][1]["filename"])
).convert("RGB")
except IndexError:
print(self.data)
raise IndexError(f"Index is :{index} Subindex is:{sub_index}")

# RGB<uuid>/rgb_<image_id>.png
image_id = self.data[sub_index]["filename"][44:-4]
target = {"image_id": image_id, "labels": labels, "boxes": boxes}
return image, target
return image, segmentation, target
def __len__(self) -> int:
"""

34
com.unity.perception/Editor/Pyrception/pyrception-utils/pyrception_utils/NairiNormal-m509.ttf
文件差异内容过多而无法显示
查看文件

21
com.unity.perception/Editor/Pyrception/pyrception-utils/pyrception_utils/NairiNormal-m509.ttf.meta


fileFormatVersion: 2
guid: 34a93e4e97aad7245b71f90115917a11
TrueTypeFontImporter:
externalObjects: {}
serializedVersion: 4
fontSize: 16
forceTextureCase: -2
characterSpacing: 0
characterPadding: 1
includeFontData: 1
fontNames:
- Nairi
fallbackFontReferences: []
customCharacters:
fontRenderingMode: 0
ascentCalculationMode: 1
useLegacyBoundsCalculation: 0
shouldRoundAdvanceValue: 1
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存