Exemple #1
0
def publish_hfl_data():

    # subscribe the HFL request to receive the timestamp and file name

    while ecal.ok():
        ret, msg, time = hfl_subscr_obj.receive(500)
        # print("---:: ", ret, msg, time, type(msg))
        if msg is not None:
            hfl_req_proto_obj.ParseFromString(msg)
            idx_req = hfl_req_proto_obj.image_index
            # timestamp = int(timestamp)
            print("--->", idx_req, h5_filename)
            h5file_obj = H5ReaderSequence(h5_filename)
            timestamp, inten_data, dist_data = h5file_obj.loadData(
                h5_filename, int(idx_req))
            print("timestamp :: ", timestamp)
            hfl_resp_proto_obj.timestamp = int(timestamp)
            hfl_resp_proto_obj.HFL_image_index = int(idx_req)
            if inten_data != '' or dist_data != '':
                hfl_resp_proto_obj.intensity_image = inten_data
                hfl_resp_proto_obj.distance_image = dist_data
            else:
                hfl_resp_proto_obj.intensity_image = inten_data
                hfl_resp_proto_obj.distance_image = dist_data

            hfl_publs_obj.send(hfl_resp_proto_obj.SerializeToString())
    def define_subscr_callbacks(self):

        # For Image data
        self.lt5_img_subscr_obj.set_callback(self.predict_tracker_result)
        self.lt5_finl_subscr_obj.set_callback(self.abort_algo)
        while ecal.ok() and BEXIT:
            # print("#########################", BEXIT)
            time.sleep(0.1)
            if ALGO_READINESS:
                self.inform_tracker_ready()
Exemple #3
0
    def define_subscr_callbacks(self):

        self.pnt_cld_dvc_subscr_obj.set_callback(self.pub_pnt_cld_dvc_data)
        self.pnt_cld_data_subscr_obj.set_callback(self.pub_pnt_cld_points_data)
        self.pnt_cld_end_subscr_obj.set_callback(self.abort_algo)
        print("Point Cloud service initialized")
        while ecal.ok() and BEXIT:
            time.sleep(0.1)
            if SERVICE_READINESS:
                self.inform_model_loaded()
Exemple #4
0
    def define_subscr_callbacks(self):

        # For device data
        # Deprecating device request
        # self.h5_dvc_subscr_obj.set_callback(self.pub_dvc_data)
        # For Channel data
        self.h5_chnl_subscr_obj.set_callback(self.pub_chnl_data)
        # For Image data
        self.h5_img_subscr_obj.set_callback(self.pub_img_data)
        while ecal.ok():
            time.sleep(0.1)
Exemple #5
0
def subscribe_signl_names():

    ecal.initialize(sys.argv, "Detector mask subscriber")
    subscribe_sig_names_obj = ecal.subscriber(topic_name="Pixel_Response")
    rdr_sig_response = AlgoInterface_pb2.LabelResponse()

    while ecal.ok():
        ret, msg, time = subscribe_sig_names_obj.receive(500)
        print("---:: ", ret, msg, time, type(msg))
        if msg is not None:
            rdr_sig_response.ParseFromString(msg)
            object_attibute_lst = rdr_sig_response.NextAttr
            # print("object_attibute :: ", object_attibute_lst)

            for evry_obj_attr in object_attibute_lst:
                track_id = evry_obj_attr.trackID
                # print("track_id ::> ", track_id)
                class_obj = evry_obj_attr.type.object_class
                # print("class_obj :: ", class_obj)
                x1 = evry_obj_attr.ROI[0].X
                y1 = evry_obj_attr.ROI[0].Y

                x2 = evry_obj_attr.ROI[1].X
                y2 = evry_obj_attr.ROI[1].Y

                x3 = evry_obj_attr.ROI[2].X
                y3 = evry_obj_attr.ROI[2].Y

                x4 = evry_obj_attr.ROI[3].X
                y4 = evry_obj_attr.ROI[3].Y

                print("ordinates :: ", x1, x2, x3, x4, y1, y2, y3, y4)

                mask = evry_obj_attr.mask
                with open('img.txt', 'w+') as fhandle:
                    fhandle.write(str(mask))

                nparr = np.fromstring(mask, np.uint8)

                print("nparr :: ", nparr)
                re_img_np_ary = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
                img_shape = re_img_np_ary.shape
                print("shape::", img_shape)
                cv2.imwrite('color_img.jpg', re_img_np_ary)
                cv2.imshow('Color image', re_img_np_ary)
                cv2.waitKey(0)
                cv2.destroyAllWindows()
    def subscribe_ecal_msgs(self):

        print "Subscribing to the signals.........."
        # Publish the signal values
        bsig_obj = None
        # Subscribe on the algo interface object
        bsig_proto_req_obj = Radar_pb2.BsigDataRequest()
        bsig_proto_resp_obj = Radar_pb2.BsigDataResponse()
        while ecal.ok():
            ret, msg, time = self.bsig_subscr_obj.receive(500)
            # print("---:: ", ret, msg, time, type(msg))
            if msg is not None:
                start_time = datetime.now()
                bsig_proto_req_obj.ParseFromString(msg)
                bsig_pth = bsig_proto_req_obj.bsigPath
                obj_num = bsig_proto_req_obj.objectIdCount
                tmstamp_rdr = bsig_proto_req_obj.timestamp
                # Segregate object signals and non-object signals
                cmn_signals = [ech_sig for ech_sig in bsig_proto_req_obj.signalNames if '%' not in str(ech_sig)]
                obj_signals = [ech_sig for ech_sig in bsig_proto_req_obj.signalNames if '%' in str(ech_sig)]
                print "--> ", bsig_pth, obj_num
                # print "cmn_signals :: ",
                # if len(cmn_signals) == 1 and 'TimeStamp' in str(cmn_signals[0])

                try:
                    if bsig_obj is None:
                        print "{{{{"
                        bsig_obj = signalreader.BsigReader(bsig_pth)
                    # print("bsig_obj >> ", bsig_obj)
                    # Read and Publish the common signals velocity, acceleration just once
                    print "Reading common signals..."
                    for ech_cmn_signal in cmn_signals:
                        cmn_sig_val_lst = list(bsig_obj.signal(ech_cmn_signal))
                        # print "cmn_sig_val_lst >> ", cmn_sig_val_lst
                        if len(cmn_signals) == 1 and 'TimeStamp' in str(cmn_signals[0]):
                            # self.publ_timestamps()
                            self.bsig_tmstamp_lst.extend(cmn_sig_val_lst)
                        if self.bsig_tmstamp_lst:
                            # Get the index/sample count for the timestamp
                            if tmstamp_rdr != -1:
                                try:
                                    sample_cnt = self.bsig_tmstamp_lst.index(tmstamp_rdr)
                                    # print "cmn_sig_val_lst :: ", cmn_sig_val_lst
                                    print "sample_cnt >> ", sample_cnt, cmn_sig_val_lst[sample_cnt]
                                    cmn_sig_val_lst = [cmn_sig_val_lst[sample_cnt]]
                                except ValueError as e:
                                    print "No signal value for this timestamp %d and signal %s" % (tmstamp_rdr, ech_cmn_signal)
                                    pass
                        else:
                            print "TimeStamp data not fetched from Bsig file"
                            continue

                        ech_sig_data = bsig_proto_resp_obj.eachSigValues.add()
                        # If data is present for signal send the values else do not send anything
                        # print "cmn_sig_val_lst :: ", cmn_sig_val_lst
                        if cmn_sig_val_lst:
                            ech_sig_data.signalName = ech_cmn_signal
                            ech_sig_data.objectId = -1
                            for ech_sig_val in cmn_sig_val_lst:
                                ech_sig_data.signalvalues.append(ech_sig_val)
                        # else:
                        #     ech_sig_data.signalvalues.append(0)
                    # Iterate over the objects
                    if tmstamp_rdr != -1:
                        for ech_obj_num in range(0, obj_num):
                            print "Reading signals for object %s" % str(ech_obj_num)
                            # print("ech_obj_num > ", ech_obj_num)
                            # Parse the signal names and iterate over them
                            for ech_signal in obj_signals:
                                if '%' in str(ech_signal):
                                    ech_signal = ech_signal.replace('%', str(ech_obj_num))
                                print("ech_signal > ", ech_signal)
                                obj_sig_val_lst = list(bsig_obj.signal(ech_signal))
                                ech_obj_sig_data = bsig_proto_resp_obj.eachSigValues.add()
                                # If data is present for signal send the values else do not send anything
                                if obj_sig_val_lst:
                                    if self.bsig_tmstamp_lst:
                                        # Get the index/sample count for the timestamp
                                        if tmstamp_rdr != -1:
                                            try:
                                                sample_cnt = self.bsig_tmstamp_lst.index(tmstamp_rdr)
                                                # print "cmn_sig_val_lst :: ", cmn_sig_val_lst
                                                print "sample_cnt >> ", sample_cnt, obj_sig_val_lst[sample_cnt]
                                                obj_sig_val_lst = [obj_sig_val_lst[sample_cnt]]
                                            except ValueError as e:
                                                print "No signal value for this timestamp %d and signal %s" % (
                                                tmstamp_rdr, ech_signal)
                                                pass
                                    else:
                                        print "TimeStamp data not fetched from Bsig file"
                                        continue
                                    ech_obj_sig_data.signalName = ech_signal
                                    ech_obj_sig_data.objectId = ech_obj_num
                                    for ech_obj_sig_val in obj_sig_val_lst:
                                        ech_obj_sig_data.signalvalues.append(ech_obj_sig_val)
                                # else:
                                #     ech_obj_sig_data.signalvalues.append(0)
                except signalreader.SignalReaderException, e:
                    print "Signal not found", str(e)
                data_payload = bsig_proto_resp_obj.SerializeToString()
                # print "data_payload :: ", data_payload
                self.bsig_pub_obj.send(data_payload)
                end_time = datetime.now()
                duration = end_time - start_time
                print("duration :: ", duration.total_seconds(), duration.total_seconds()/60)
        roi_min_obj2.X = -1
        roi_min_obj2.Y = -1

        # Create ROI object for Xmax, Ymax
        roi_max_obj3 = nextattr_obj.ROI.add()
        roi_max_obj3.X = -1
        roi_max_obj3.Y = -1

        roi_max_obj4 = nextattr_obj.ROI.add()
        roi_max_obj4.X = -1
        roi_max_obj4.Y = -1
        publisher_roi_obj.send(lbl_response_obj.SerializeToString())


#eCAL Subscriber begins here
while ecal.ok():
    # Subscribe for the message which is an image encoded through protobuf
    ret, msg, time = subscriber_obj.receive(500)
    # print("---:: ", ret, msg, time, type(msg))
    if msg is not None:
        ld_req_obj.ParseFromString(msg)
        print("received image", datetime.now())
        # print("ld_req_obj :: ", ld_req_obj)
        img_data_obj = ld_req_obj.base_image
        print("recieved_timestamp :: ", ld_req_obj.recieved_timestamp)
        img_data_str = img_data_obj
        nparr = np.fromstring(img_data_str, np.uint8)
        # print("nparr :: ", nparr)
        re_img_np_ary = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
        # print("re_img_np_ary :: ", re_img_np_ary)
        img_shape = re_img_np_ary.shape