| | |
| | | from typing import List |
| | | import numpy as np |
| | | import cv2 |
| | | from tomlkit import value |
| | | |
| | | # # add python path of src to sys.path |
| | | # src_path = os.path.join(__file__, *(['..'] * 2)) |
| | |
| | | |
| | | # extracting the msg from queue |
| | | msg = queue.get() |
| | | msg_pb = pb.PlyMessage() |
| | | msg_pb = pb.PlysMessage() |
| | | msg_pb.ParseFromString(msg) |
| | | |
| | | # save the raw pb msg |
| | |
| | | rows = ply.rows |
| | | cols = ply.cols |
| | | order = ply.order |
| | | dt = ply.d_types |
| | | dt = ply.dtype |
| | | |
| | | # save the pointcloud array data |
| | | if (data_byte is None) | (len(data_byte) != data_legth): |
| | |
| | | else: |
| | | # frame the bytes to array |
| | | data_array = np.frombuffer(data_byte,dtype=dt) |
| | | data_array = data_array.reshape(rows,cols) |
| | | data_array = data_array.reshape(rows,cols,order=order) |
| | | # save the data with .ply format |
| | | filename = f"{msg_source}_{msg_timestamp}_pointcloud{id}" |
| | | write_ply(data_array,self.plysmsg_folder,filename) |
| | |
| | | source:str, |
| | | routing_key:str): |
| | | |
| | | # constract a images message |
| | | imagesMsg = pb.ImagesMessage() |
| | | imagesMsg.source = source |
| | | curr_time = datetime.now().strftime('%Y-%m-%d-%H-%M-%S') |
| | | imagesMsg.timestamp = curr_time |
| | | # constract a images message |
| | | imagesMsg = pb.ImagesMessage() |
| | | imagesMsg.source = source |
| | | curr_time = datetime.now().strftime('%Y-%m-%d-%H-%M-%S') |
| | | imagesMsg.timestamp = curr_time |
| | | |
| | | for img in images: |
| | | if img is not None: |
| | | success,image_encoded = cv2.imencode(".jpg",img) |
| | | if success: |
| | | image_bytes = image_encoded.tobytes() |
| | | image_length = len(image_bytes) |
| | | # add the encoded image to msg |
| | | image_item = imagesMsg.Image.add() |
| | | image_item.length = image_length |
| | | image_item.data = image_bytes |
| | | for img in images: |
| | | if img is not None: |
| | | success,image_encoded = cv2.imencode(".jpg",img) |
| | | if success: |
| | | image_bytes = image_encoded.tobytes() |
| | | image_length = len(image_bytes) |
| | | # add the encoded image to msg |
| | | image_item = imagesMsg.Image.add() |
| | | image_item.length = image_length |
| | | image_item.data = image_bytes |
| | | |
| | | # converting the pb image msg to bytes |
| | | imageMsg_bytes = imagesMsg.SerializeToString() |
| | | # add the imageMsg to the queue |
| | | images_queue.put([routing_key,imageMsg_bytes]) |
| | | # converting the pb image msg to bytes |
| | | imageMsg_bytes = imagesMsg.SerializeToString() |
| | | # add the imageMsg to the queue |
| | | images_queue.put([routing_key,imageMsg_bytes]) |
| | | |
| | | def send_pointcloud_tool(pointclouds:queue.Queue, |
| | | plys_queue:queue.Queue, |
| | | source:str, |
| | | routing_key:str): |
| | | |
| | | # constract a plys message |
| | | plysMsg = pb.PlysMessage() |
| | | plysMsg.source = source |
| | | curr_time = datetime.now().strftime('%Y-%m-%d-%H-%M-%S') |
| | | plysMsg.timestamp = curr_time |
| | | |
| | | |
| | | run =True |
| | | while run: |
| | | while not pointclouds.empty(): |
| | | |
| | | value = pointclouds.get() |
| | | |
| | | if value is not False: |
| | | pointcloud = np.array(value) |
| | | # get the attributes of the PointCloudItem |
| | | rows = pointcloud.shape[0] |
| | | cols = pointcloud.shape[1] |
| | | order = "C" |
| | | dtype = str(pointcloud.dtype) |
| | | data = pointcloud.tobytes(order=order) |
| | | length = len(data) |
| | | |
| | | # add the pointcloud to the msg |
| | | item = plysMsg.Plydata.add() |
| | | item.length = length |
| | | item.rows = rows |
| | | item.cols = cols |
| | | item.order = order |
| | | item.dtype = dtype |
| | | item.data = data |
| | | |
| | | else: |
| | | # converting the pb ply msg to bytes |
| | | plysMsg_bytes = plysMsg.SerializeToString() |
| | | # add the plysMsg to the queue |
| | | plys_queue.put([routing_key,plysMsg_bytes]) |
| | | |
| | | # end the outer while loop and triminate this function |
| | | run = False |
| | | |
| | | |
| | | |
| | | |
| | | |