Skip to content

Commit

Permalink
Merge pull request #2738 from JdeRobot/remove-shared-used-inside-some…
Browse files Browse the repository at this point in the history
…-exercises

Remove shared used inside some exercises
  • Loading branch information
CDAM2020 authored Sep 25, 2024
2 parents 26a3060 + f2a74f0 commit c97df6f
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 536 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from gui_interfaces.general.measuring_threading_gui import MeasuringThreadingGUI
from console_interfaces.general.console import start_console
from shared.image import SharedImage
from map import Map
from HAL import getPose3d

Expand All @@ -22,9 +21,12 @@ def __init__(self, host="ws://127.0.0.1:2303"):
self.mapXY = None
self.worldXY = None

self.image_to_be_shown = None
self.image_to_be_shown_updated = False
self.image_show_lock = threading.Lock()

# Payload vars
self.payload = {'image': '', 'map': '', 'array': ''}
self.shared_image = SharedImage("numpyimage")
self.map = Map(getPose3d)

self.start()
Expand Down Expand Up @@ -60,23 +62,36 @@ def update_gui(self):
message = json.dumps(self.payload)
self.send_to_client(message)

# Function to prepare image payload
# Encodes the image as a JSON string and sends through the WS
def payloadImage(self):
"""Encodes the image data to be sent to websocket"""
image = self.shared_image.get()
with self.image_show_lock:
image_to_be_shown_updated = self.image_to_be_shown_updated
image_to_be_shown = self.image_to_be_shown

image = image_to_be_shown
payload = {'image': '', 'shape': ''}


if not image_to_be_shown_updated:
return payload

shape = image.shape
frame = cv2.imencode('.PNG', image)[1]
frame = cv2.imencode('.JPEG', image)[1]
encoded_image = base64.b64encode(frame)

payload['image'] = encoded_image.decode('utf-8')
payload['shape'] = shape


with self.image_show_lock:
self.image_to_be_shown_updated = False

return payload

def showNumpy(self, image):
processed_image = np.stack((image,) * 3, axis=-1)
self.shared_image.add(processed_image)
with self.image_show_lock:
self.image_to_be_shown = processed_image
self.image_to_be_shown_updated = True

def showPath(self, array):
"""Process the array(ideal path) to be sent to websocket"""
Expand Down
Binary file not shown.
Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit c97df6f

Please sign in to comment.