Skip to content

Commit

Permalink
conditional for texture
Browse files Browse the repository at this point in the history
  • Loading branch information
OloFuchs committed Jan 10, 2024
1 parent 9330306 commit 8be7b49
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
44 changes: 26 additions & 18 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def __init__(self, service_config: EventServiceConfig) -> None:

self.image_decoder = TurboJPEG()

self.view_name = "rgb"

self.async_tasks: list[asyncio.Task] = []

def build(self):
Expand All @@ -70,6 +72,9 @@ def on_exit_btn(self) -> None:
task.cancel()
App.get_running_app().stop()

def update_view(self, view_name: str):
self.view_name = view_name

async def app_func(self):
async def run_wrapper():
# we don't actually need to set asyncio as the lib because it is
Expand Down Expand Up @@ -114,24 +119,27 @@ async def stream_camera(
SubscribeRequest(uri=Uri(path=f"/{view_name}"), every_n=rate),
decode=False,
):
print(view_name)
message = payload_to_protobuf(event, payload)
try:
img = self.image_decoder.decode(message.image_data)
except Exception as e:
logger.exception(f"Error decoding image: {e}")
continue

# create the opengl texture and set it to the image
texture = Texture.create(size=(img.shape[1], img.shape[0]), icolorfmt="bgr")
texture.flip_vertical()
texture.blit_buffer(
bytes(img.data),
colorfmt="bgr",
bufferfmt="ubyte",
mipmap_generation=False,
)
self.root.ids[view_name].texture = texture
if view_name == self.view_name:
print(self.view_name)
message = payload_to_protobuf(event, payload)
try:
img = self.image_decoder.decode(message.image_data)
except Exception as e:
logger.exception(f"Error decoding image: {e}")
continue

# create the opengl texture and set it to the image
texture = Texture.create(
size=(img.shape[1], img.shape[0]), icolorfmt="bgr"
)
texture.flip_vertical()
texture.blit_buffer(
bytes(img.data),
colorfmt="bgr",
bufferfmt="ubyte",
mipmap_generation=False,
)
self.root.ids[view_name].texture = texture


def find_config_by_name(
Expand Down
4 changes: 4 additions & 0 deletions src/res/main.kv
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ RelativeLayout:
do_default_tab: False
TabbedPanelItem:
text: "Rgb"
on_press: app.update_view('rgb')
Image:
id: rgb
TabbedPanelItem:
text: "Disparity"
on_press: app.update_view('disparity')
Image:
id: disparity
TabbedPanelItem:
text: "Left"
on_press: app.update_view('left')
Image:
id: left
TabbedPanelItem:
text: "Right"
on_press: app.update_view('right')
Image:
id: right
Button:
Expand Down

0 comments on commit 8be7b49

Please sign in to comment.