Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ jobs:
- name: python-isort
uses: isort/isort-action@v1.1.0
with:
configuration: "--check-only --diff --line-length 120 --profile black"
configuration: "--check-only --diff --verbose --line-length 120 --profile black"
- name: Black formatter
uses: psf/black@stable
with:
options: "--check --verbose --line-length 120"
options: "--check --diff --verbose --line-length 120"


# TODO: Support linting with flake8 and maybe testing?
Expand Down
17 changes: 8 additions & 9 deletions autonomy/Detectors/simulation_noGPU.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,25 @@
class Simulation_noGPU_detector(base.DetectorBaseClass):
cameraStream = None

def __init__(self, cameraStream, controlThread):
def __init__(self, cameraStream, controlThread, client):
super().__init__()
# control thread is used for obtaining position and attitude data
self.controlThread = controlThread
self.cameraStream = cameraStream
self.client = SimulationClient()
self.client = client
if cameraStream == None:
return None

j = 0

def DetectorTask(self):
time.sleep(1)
time.sleep(1 / 30)
LastDetections = list()
detection = self.get_detection()
detection = detection["detected"]
# detection = detection["detected"]
for i in detection:
if i["visibleInFrame"]:
o = self.handle_detection(i)
LastDetections.append(o.toDictionary())
o = self.handle_detection(i)
LastDetections.append(o.toDictionary())

####################################
"""
Expand All @@ -42,7 +41,7 @@ def DetectorTask(self):
fdc.close()
self.j +=1
"""
fps = 1
fps = 30
self.InvokeCallback(fps, LastDetections)

def handle_detection(self, detection):
Expand Down Expand Up @@ -91,4 +90,4 @@ def handle_detection(self, detection):

def get_detection(self):
# camera stream is based on simulation web api.
return self.client.get_detection()
return self.client.okon.get_visible_detection()
14 changes: 5 additions & 9 deletions cameraStream/SimulationWAPIStreamClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,19 @@ class SimulationWAPIStreamClient(cameraStream):
__fi_x = (math.pi - h_fov) / 2
__fi_y = 2 * math.pi - v_fov / 2

def __init__(self):
def __init__(self, client):
threading.Thread.__init__(self)
self.frame = None
self.client = sc.SimulationClient()
self.client = client

def run(self):
while self.active:
self.receive_frame()
self.frame = self.client.okon.video
# around 50 fps
time.sleep(0.01)

def getFrame(self):
return self.frame

def receive_frame(self):
val = self.client.get_stream_frame()
if val != None:
self.frame = val
return self.client.okon.video

def setFov(self, h_fov, v_fov):
self.h_fov = h_fov
Expand All @@ -55,6 +50,7 @@ def getDepthMap(self):
return self.client.get_depth_map() # jpg bytes

def getPointCloud(self):
# TODO: fix
d_map = self.client.get_depth_map() # jpg bytes
nparray = np.frombuffer(img_bytes, np.uint8)
img = cv2.imdecode(nparray, cv2.IMREAD_GRAYSCALE)
Expand Down
54 changes: 54 additions & 0 deletions cameraStream/ZEDStream.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""ZED Camera local streaming
"""
import io
import threading

import numpy as np
import pyzed.sl as sl
from PIL import Image

from cameraStream.stream import cameraStream
from zed.ZEDCamera import ZEDCamera


class ZEDStream(cameraStream):
"""Streamer using ZED camera.

Produces byte representations of JPEG images/depth
from camera copies, which can be further streamed to GUI.
"""

def __init__(self, camera: ZEDCamera, lock: threading.Lock):
threading.Thread.__init__(self)
self.camera = camera
self.frame = None
self.depth_map = None
self.point_cloud = None
self.lock = lock

def run(self):
while self.active:
with self.lock:
self.frame = self.camera.frame
self.depth_map = self.camera.depth_map
self.point_cloud = self.camera.point_cloud

def getFrame(self) -> bytes:
"""Prepares byte representation of jpeg image"""
img = Image.fromarray(self.frame)
img_byte_arr = io.BytesIO()
img.save(img_byte_arr, format="JPEG")

return img_byte_arr.getvalue()

def getDepthMap(self) -> bytes:
"""Prepare byte representation of jpeg depth map"""
depth = Image.fromarray(self.depth_map)
depth_byte_arr = io.BytesIO()
depth.save(depth_byte_arr, format="JPEG")

return depth_byte_arr.getvalue()

def getPointCloud(self) -> np.ndarray:
"""Numpy array representing cloud of points with XYZ"""
return self.point_cloud
2 changes: 1 addition & 1 deletion communicationThreads/GUI/Sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def SendBattery(self):
def SendDetection(self, fps, detectionList):
key = bytes([Protocol.TO_GUI.AUTONOMY_MSG.DETECTION])
test = {"fps": fps, "ObjectsList": detectionList}
print(test)
# print(test)
data = json.dumps({"fps": fps, "ObjectsList": detectionList})
data = data.encode()
self.SendAutonomyMsg(data, key)
Expand Down
Loading