Documentation ¶
Overview ¶
Package medifor contains a basic client library for dialing and communicating with MediFor services.
Index ¶
- Variables
- func CheckDetectionScore(detection *pb.Detection) error
- func EnsureIDAndOutput(req Request) error
- func FusedScore(f *pb.Fusion) (float64, error)
- func IDVersionFromDetection(d *pb.AnnotatedDetection) (id, version string, err error)
- func MustDetectionReq(req Request) *pb.Detection
- func NewDetectionReq(req Request) (*pb.Detection, error)
- func NewImageCameraMatchRequest(probePath string, opts ...ManipOpt) *pb.ImageCameraMatchRequest
- func NewImageCamerasRequest(probePath string, opts ...ManipOpt) *pb.ImageCamerasRequest
- func NewImageManipulationRequest(imgPath string, opts ...ManipOpt) *pb.ImageManipulationRequest
- func NewImageSpliceRequest(donorPath, probePath string, opts ...ManipOpt) *pb.ImageSpliceRequest
- func NewVideoManipulationRequest(vidPath string, opts ...ManipOpt) *pb.VideoManipulationRequest
- func ParseAnalyticID(id string) (name, version string)
- type Client
- func (c *Client) Close() error
- func (c *Client) Detect(ctx context.Context, detection *pb.Detection) (err error)
- func (c *Client) DetectImageCameraMatch(ctx context.Context, req *pb.ImageCameraMatchRequest) (*pb.ImageCameraMatch, error)
- func (c *Client) DetectImageCameras(ctx context.Context, req *pb.ImageCamerasRequest) (*pb.ImageCameras, error)
- func (c *Client) DetectImageManipulation(ctx context.Context, req *pb.ImageManipulationRequest) (*pb.ImageManipulation, error)
- func (c *Client) DetectImageSplice(ctx context.Context, req *pb.ImageSpliceRequest) (*pb.ImageSplice, error)
- func (c *Client) DetectReq(ctx context.Context, req Request) (*pb.Detection, error)
- func (c *Client) DetectVideoCameraMatch(ctx context.Context, req *pb.VideoCameraMatchRequest) (*pb.VideoCameraMatch, error)
- func (c *Client) DetectVideoManipulation(ctx context.Context, req *pb.VideoManipulationRequest) (*pb.VideoManipulation, error)
- func (c *Client) Health(ctx context.Context) (*healthpb.HealthCheckResponse, error)
- type FusionClient
- func (c *FusionClient) Close() error
- func (c *FusionClient) Fuse(ctx context.Context, fusion *pb.Fusion) (err error)
- func (c *FusionClient) FuseDetections(ctx context.Context, ds []*pb.AnnotatedDetection) (fusion *pb.Fusion, err error)
- func (c *FusionClient) FuseImageManipulation(ctx context.Context, req *pb.FuseImageManipulationRequest) (*pb.ImageManipulation, error)
- func (c *FusionClient) FuseVideoManipulation(ctx context.Context, req *pb.FuseVideoManipulationRequest) (*pb.VideoManipulation, error)
- func (c *FusionClient) Health(ctx context.Context) (*healthpb.HealthCheckResponse, error)
- type ManipOpt
- type MultiClient
- type Option
- func WithDial(opts ...grpc.DialOption) Option
- func WithFusionInputTranslator(t PathTranslator) Option
- func WithHealthy() Option
- func WithInputTranslator(t PathTranslator) Option
- func WithMTLS(caCertPath, clientCertPath, clientKeyPath string) Option
- func WithOutputTranslator(t PathTranslator) Option
- func WithWaitForBackend() Option
- type PathTranslator
- type Request
Constants ¶
This section is empty.
Variables ¶
var DefaultPathTranslator = defaultTranslator{}
DefaultPathTranslator provides no-op Translate and Untranslate methods.
Functions ¶
func CheckDetectionScore ¶
CheckDetectionScore returns an error if a response score is not in [0, 1], otherwise nil. A nil detection object results in no error, since that would produce a default 0 score.
func EnsureIDAndOutput ¶
EnsureIDAndOutput checks that a request object contains a RequestID, and that its output directory ends with that ID. If either of those things is not true, it remedies that fact before sending the request.
func FusedScore ¶
FusedScore pulls the score from a Fusion object.
func IDVersionFromDetection ¶
func IDVersionFromDetection(d *pb.AnnotatedDetection) (id, version string, err error)
IDVersionFromDetection gets the analytic ID and version from an AnnotatedDetection proto.
func MustDetectionReq ¶
MustDetectionReq calls NewDetectionReq and panics if an error occurs.
func NewDetectionReq ¶
NewDetectionReq creates a detection object from a given request proto. It doesn't do anything special with the request (like set its ID). That should be done by the caller.
func NewImageCameraMatchRequest ¶
func NewImageCameraMatchRequest(probePath string, opts ...ManipOpt) *pb.ImageCameraMatchRequest
NewImageCameraMatchRequest creates a new ImageCameraMatchRequest from the given probe and camera ID.
func NewImageCamerasRequest ¶
func NewImageCamerasRequest(probePath string, opts ...ManipOpt) *pb.ImageCamerasRequest
NewImageCamerasRequest creates a new ImageCamerasRequest from the given probe and camera ID.
func NewImageManipulationRequest ¶
func NewImageManipulationRequest(imgPath string, opts ...ManipOpt) *pb.ImageManipulationRequest
NewImageManipulationRequest creates a new ImageManipulationRequest from the given image path. It determines the mime type from the file extension. It creates a unique request ID and appends it to the output directory prefix. If the output prefix is unspecified in the options, it is set to a location based on the OS temp directory.
func NewImageSpliceRequest ¶
func NewImageSpliceRequest(donorPath, probePath string, opts ...ManipOpt) *pb.ImageSpliceRequest
NewImageSpliceRequest creates a new ImageSpliceRequest from the given probe and donor image paths. Works similarly to NewImageManipulationRequest.
func NewVideoManipulationRequest ¶
func NewVideoManipulationRequest(vidPath string, opts ...ManipOpt) *pb.VideoManipulationRequest
NewVideoManipulationRequest creates a new VideoManipulationRequest from the given video path. Works similarly to NewImageManipulationRequest.
func ParseAnalyticID ¶
ParseAnalyticID separates the ID into name and version components if possible.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a client library for speaking to MediFor services (e.g., analytic indicators) over gRPC.
func (*Client) Detect ¶
Detect calls the endpoint corresponding to the request type in the given Detection, and fills in the response and status on reply. The request ID can be omitted. One will be assigned if not present.
func (*Client) DetectImageCameraMatch ¶
func (c *Client) DetectImageCameraMatch(ctx context.Context, req *pb.ImageCameraMatchRequest) (*pb.ImageCameraMatch, error)
DetectImageCameraMatch calls the corresponding endpoint, with file name translation, if registered. A request ID will be assigned if not present.
func (*Client) DetectImageCameras ¶
func (c *Client) DetectImageCameras(ctx context.Context, req *pb.ImageCamerasRequest) (*pb.ImageCameras, error)
DetectImageCameras calls the corresponding endpoint, with file name translation, if registered. A request ID will be assigned if not present.
func (*Client) DetectImageManipulation ¶
func (c *Client) DetectImageManipulation(ctx context.Context, req *pb.ImageManipulationRequest) (*pb.ImageManipulation, error)
DetectImageManipulation calls the corresponding endpoint, with file name translation, if registered. A request ID will be assigned if not present.
func (*Client) DetectImageSplice ¶
func (c *Client) DetectImageSplice(ctx context.Context, req *pb.ImageSpliceRequest) (*pb.ImageSplice, error)
DetectImageSplice calls the corresponding endpoint, with file name translation, if registered. A request ID will be assigned if not present.
func (*Client) DetectReq ¶
DetectReq creates a Detection from a given request, and calls Detect on it before returning it. It is valid to have a non-nil detection *and* a non-nil error. The detection, in that case, will contain the relevant endpoint error information in its status field, and the error will contain the call stack leading to it.
func (*Client) DetectVideoCameraMatch ¶
func (c *Client) DetectVideoCameraMatch(ctx context.Context, req *pb.VideoCameraMatchRequest) (*pb.VideoCameraMatch, error)
DetectVideoCameraMatch calls the corresponding endpoint, with file name translation, if registered. A request ID will be assigned if not present.
func (*Client) DetectVideoManipulation ¶
func (c *Client) DetectVideoManipulation(ctx context.Context, req *pb.VideoManipulationRequest) (*pb.VideoManipulation, error)
DetectVideoManipulation calls the corresponding endpoint, with file name translation, if registered. A request ID will be assigned if not present.
type FusionClient ¶
type FusionClient struct {
// contains filtered or unexported fields
}
FusionClient is a client library for speaking to MediFor Analytic Fusion Services over gRPC
func NewFusionClient ¶
NewFusionClient creates a new medfifor fusion client and dials the host
func (*FusionClient) Close ¶
func (c *FusionClient) Close() error
Close closes the underlying connection to the host.
func (*FusionClient) Fuse ¶
Fuse calls the endpoint corresponding to the request type in the given Fusion, fills in the response and status on reply. The request ID can be left off, and will be assigned if missing.
func (*FusionClient) FuseDetections ¶
func (c *FusionClient) FuseDetections(ctx context.Context, ds []*pb.AnnotatedDetection) (fusion *pb.Fusion, err error)
FuseDetections calls the endpoint corresponding to the request type in the first of a slice of AnnotatedDetection protos. All protos are assumed to have the same underlying request, and their responses are converted into inputs for fusion.
func (*FusionClient) FuseImageManipulation ¶
func (c *FusionClient) FuseImageManipulation(ctx context.Context, req *pb.FuseImageManipulationRequest) (*pb.ImageManipulation, error)
FuseImageManipulation calls fusion with the given request.
func (*FusionClient) FuseVideoManipulation ¶
func (c *FusionClient) FuseVideoManipulation(ctx context.Context, req *pb.FuseVideoManipulationRequest) (*pb.VideoManipulation, error)
FuseVideoManipulation calls fusion with the given request.
func (*FusionClient) Health ¶
func (c *FusionClient) Health(ctx context.Context) (*healthpb.HealthCheckResponse, error)
Health sends a health check request and returns a response proto.
type ManipOpt ¶
type ManipOpt func(*manipConfig)
ManipOpt is an option passed to image or video manipulation detection request creation functions for optional values.
func WithDeviceID ¶
WithDeviceID sets the device ID on a manipulation request. Default is empty. Not all manipulation types will make use of this.
func WithOutputPrefix ¶
WithOutputPrefix sets the output prefix to the given value. If not called, the default is used, based on operating systsem temporary directory.
type MultiClient ¶
MultiClient is a client manager that handles multiple clients at once, allowing one-request-at-a-time mode against a set of clients.
func NewMultiClient ¶
func NewMultiClient(ctx context.Context, hostPorts []string, opts ...Option) (client *MultiClient, err error)
NewMultiClient creates a new multiclient, where every client uses the same options.
func (*MultiClient) CallWithClient ¶
func (c *MultiClient) CallWithClient(ctx context.Context, f func(context.Context, *Client) error) error
CallWithClient calls the specific function with the next available client, if any.
func (*MultiClient) Close ¶
func (c *MultiClient) Close() error
Close closes all underlying clients. Waits for all outstanding CallWithClient calls to finish.
type Option ¶
type Option func(o *mfcOpts) error
Option changes aspects of client creation.
func WithDial ¶
func WithDial(opts ...grpc.DialOption) Option
WithDial sets a particular gRPC dial option when creating the client. For example, to use an insecure connection, you can do the following:
client, err := NewClient(ctx, hostPort, WithDial(grpc.WithInsecure()))
Note, the above is the default, so this is merely an example of something you *could* do.
func WithFusionInputTranslator ¶
func WithFusionInputTranslator(t PathTranslator) Option
WithFusionInputTranslator sets the input URI translator for fusion inputs (which are all analytic outputs, not the original source data). Works like WithInputTranslator, but affects only the analytic output portion of a fusion request.
func WithHealthy ¶
func WithHealthy() Option
WithHealthy sets an option that causes client creation to fail if the service does not immediately send a "SERVING" health response. Otherwise creation may succeed where requests fail.
func WithInputTranslator ¶
func WithInputTranslator(t PathTranslator) Option
WithInputTranslator sets the input URI translator to be the given function. When present, this will translate any URI in a request proto by passing it through the provided translation function before sending the request. Operates on URIs in requests. Defaults to DefaultPathTranslator.
func WithMTLS ¶
WithMTLS creates an option for MTLS authentication, using a server CA file, a client cert PEM, and a client private key file.
func WithOutputTranslator ¶
func WithOutputTranslator(t PathTranslator) Option
WithOutputTranslator sets the output directory and response URI translation mechanism to the given function. Similar to WithInputTranslator, but operates on the output directory in requests, and on all URIs in responses.
func WithWaitForBackend ¶
func WithWaitForBackend() Option
WithWaitForBackend blocks the dialer until the backend is ready. Do not use for buffered connections, just for production.