Beispiel #1
0
    def _process_car_inference_result(self, conn, msg_data):
        '''
        Description: process car_inference_result message
        Input:
            conn: a socket connection
            msg_data: message data.
        Returns: True or False
        '''
        request = pb2.CarInferenceResult()
        response = pb2.CommonResponse()
        msg_name = msg_name = pb2._COMMONRESPONSE.full_name
        inference_dict = {}
        if not self._parse_protobuf(request, msg_data):
            self._response_error_unknown(conn)
            return False

        app_id = request.frame_index.app_id
        channel_id = request.frame_index.channel_id
        frame_id = request.frame_index.frame_id
        object_id = request.object_id

        if not self.app_manager.is_app_exist(app_id):
            logging.error("app_id: %s not exist", app_id)
            response.ret = pb2.kErrorAppLost
            response.message = "app_id: %s not exist" % (app_id)
            self.send_message(conn, response, msg_name)
            return False

        channel_dir = os.path.join(self.storage_dir, app_id, channel_id)
        stack_list = os.listdir(channel_dir)
        stack_list.sort()
        current_stack = int(frame_id) // (MAX_SUB_DIRECTORY_NUM * FRAME_GAP)
        stack_directory = "stack_{}/".format(current_stack)
        object_dir = os.path.join(channel_dir, stack_directory, frame_id,
                                  object_id)
        if request.type == pb2.kCarColor:
            inference_dict["color_confidence"] = request.confidence
            inference_dict["color"] = request.value
        elif request.type == pb2.kCarBrand:
            inference_dict["brand_confidence"] = request.confidence
            inference_dict["brand"] = request.value
        elif request.type == pb2.kCarPlate:
            inference_dict["plate_confidence"] = request.confidence
            inference_dict["plate"] = request.value
        else:
            logging.error("unknown type %d", request.type)
            self._response_error_unknown(conn)
            return False

        if not self._save_inference_result(object_dir, inference_dict):
            self._response_error_unknown(conn)
            return False
        self.app_manager.set_heartbeat(conn.fileno())
        response.ret = pb2.kErrorNone
        response.message = "car inference process succeed"
        self.send_message(conn, response, msg_name)

        return True
def protobuf_car_brand_inference(object_id, frame_id):
    send_request = video_pb.CarInferenceResult()
    send_request.frame_index.app_id = APP_NAME
    send_request.frame_index.channel_id = CHANNEL_ID
    send_request.frame_index.channel_name = CHANNEL_NAME
    send_request.frame_index.frame_id = frame_id
    send_request.object_id = object_id
    send_request.type = video_pb.kCarBrand
    send_request.confidence = 0.8
    send_request.value = "BMW"

    return send_request.SerializeToString()