Пример #1
0
def get_detected_objects(stub):
    """ Get detected objects from gprc detection server. """
    request = detection_server_pb2.Empty()
    try:
        response = stub.GetDetectedObjects(request)
    except grpc.RpcError as err:
        logger.error(f'grpc error: {err.details()}') #pylint: disable=no-member
        logger.error('{}, {}'.format(err.code().name, err.code().value)) #pylint: disable=no-member
        exit(1)

    # Find valid detected objects in the response from the grpc server.
    # An invalid object is one with label == '' which the server will
    #   send if its stack is empty. This serves as a kind of flow control.
    # Note: ListFields returns a list of (FieldDescriptor, value) tuples
    #   for all fields in the protobuf message which are not empty.
    def make(obj):
        return DetectedObject(
            label = obj.label,
            score = obj.score,
            area = obj.area,
            centroid = Centroid(
                x = obj.centroid.x,
                y = obj.centroid.y
            )
        )
    return [make(obj) for (fd,v) in response.ListFields() for obj in v if obj.label != '']
Пример #2
0
def get_camera_intrinsic_parameters(stub):
    """ Get camera intrinsic params from gprc detection server. """
    request = detection_server_pb2.Empty()
    try:
        response = stub.GetCameraIntrinsicParameters(request)
        return response
    except grpc.RpcError as err:
        logger.error(err.details()) #pylint: disable=no-member
        logger.error('{}, {}'.format(err.code().name, err.code().value)) #pylint: disable=no-member
        exit(1)
def get_camera_resolution(stub):
    request = detection_server_pb2.Empty()
    try:
        response = stub.GetCameraResolution(request)
        print('Camera resolution fetched.')
        return response
    except grpc.RpcError as err:
        print(err.details()) #pylint: disable=no-member
        print('{}, {}'.format(err.code().name, err.code().value)) #pylint: disable=no-member
        exit(1)