1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package rekognition
4
5import (
6	"context"
7	"fmt"
8	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
9	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
10	"github.com/aws/aws-sdk-go-v2/service/rekognition/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Gets the text detection results of a Amazon Rekognition Video analysis started
16// by StartTextDetection. Text detection with Amazon Rekognition Video is an
17// asynchronous operation. You start text detection by calling StartTextDetection
18// which returns a job identifier (JobId) When the text detection operation
19// finishes, Amazon Rekognition publishes a completion status to the Amazon Simple
20// Notification Service topic registered in the initial call to StartTextDetection.
21// To get the results of the text detection operation, first check that the status
22// value published to the Amazon SNS topic is SUCCEEDED. if so, call
23// GetTextDetection and pass the job identifier (JobId) from the initial call of
24// StartLabelDetection. GetTextDetection returns an array of detected text
25// (TextDetections) sorted by the time the text was detected, up to 50 words per
26// frame of video. Each element of the array includes the detected text, the
27// precentage confidence in the acuracy of the detected text, the time the text was
28// detected, bounding box information for where the text was located, and unique
29// identifiers for words and their lines. Use MaxResults parameter to limit the
30// number of text detections returned. If there are more results than specified in
31// MaxResults, the value of NextToken in the operation response contains a
32// pagination token for getting the next set of results. To get the next page of
33// results, call GetTextDetection and populate the NextToken request parameter with
34// the token value returned from the previous call to GetTextDetection.
35func (c *Client) GetTextDetection(ctx context.Context, params *GetTextDetectionInput, optFns ...func(*Options)) (*GetTextDetectionOutput, error) {
36	if params == nil {
37		params = &GetTextDetectionInput{}
38	}
39
40	result, metadata, err := c.invokeOperation(ctx, "GetTextDetection", params, optFns, c.addOperationGetTextDetectionMiddlewares)
41	if err != nil {
42		return nil, err
43	}
44
45	out := result.(*GetTextDetectionOutput)
46	out.ResultMetadata = metadata
47	return out, nil
48}
49
50type GetTextDetectionInput struct {
51
52	// Job identifier for the text detection operation for which you want results
53	// returned. You get the job identifer from an initial call to StartTextDetection.
54	//
55	// This member is required.
56	JobId *string
57
58	// Maximum number of results to return per paginated call. The largest value you
59	// can specify is 1000.
60	MaxResults *int32
61
62	// If the previous response was incomplete (because there are more labels to
63	// retrieve), Amazon Rekognition Video returns a pagination token in the response.
64	// You can use this pagination token to retrieve the next set of text.
65	NextToken *string
66
67	noSmithyDocumentSerde
68}
69
70type GetTextDetectionOutput struct {
71
72	// Current status of the text detection job.
73	JobStatus types.VideoJobStatus
74
75	// If the response is truncated, Amazon Rekognition Video returns this token that
76	// you can use in the subsequent request to retrieve the next set of text.
77	NextToken *string
78
79	// If the job fails, StatusMessage provides a descriptive error message.
80	StatusMessage *string
81
82	// An array of text detected in the video. Each element contains the detected text,
83	// the time in milliseconds from the start of the video that the text was detected,
84	// and where it was detected on the screen.
85	TextDetections []types.TextDetectionResult
86
87	// Version number of the text detection model that was used to detect text.
88	TextModelVersion *string
89
90	// Information about a video that Amazon Rekognition analyzed. Videometadata is
91	// returned in every page of paginated responses from a Amazon Rekognition video
92	// operation.
93	VideoMetadata *types.VideoMetadata
94
95	// Metadata pertaining to the operation's result.
96	ResultMetadata middleware.Metadata
97
98	noSmithyDocumentSerde
99}
100
101func (c *Client) addOperationGetTextDetectionMiddlewares(stack *middleware.Stack, options Options) (err error) {
102	err = stack.Serialize.Add(&awsAwsjson11_serializeOpGetTextDetection{}, middleware.After)
103	if err != nil {
104		return err
105	}
106	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpGetTextDetection{}, middleware.After)
107	if err != nil {
108		return err
109	}
110	if err = addSetLoggerMiddleware(stack, options); err != nil {
111		return err
112	}
113	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
114		return err
115	}
116	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
117		return err
118	}
119	if err = addResolveEndpointMiddleware(stack, options); err != nil {
120		return err
121	}
122	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
123		return err
124	}
125	if err = addRetryMiddlewares(stack, options); err != nil {
126		return err
127	}
128	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
129		return err
130	}
131	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
132		return err
133	}
134	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
135		return err
136	}
137	if err = addClientUserAgent(stack); err != nil {
138		return err
139	}
140	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
141		return err
142	}
143	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
144		return err
145	}
146	if err = addOpGetTextDetectionValidationMiddleware(stack); err != nil {
147		return err
148	}
149	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetTextDetection(options.Region), middleware.Before); err != nil {
150		return err
151	}
152	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
153		return err
154	}
155	if err = addResponseErrorMiddleware(stack); err != nil {
156		return err
157	}
158	if err = addRequestResponseLogging(stack, options); err != nil {
159		return err
160	}
161	return nil
162}
163
164// GetTextDetectionAPIClient is a client that implements the GetTextDetection
165// operation.
166type GetTextDetectionAPIClient interface {
167	GetTextDetection(context.Context, *GetTextDetectionInput, ...func(*Options)) (*GetTextDetectionOutput, error)
168}
169
170var _ GetTextDetectionAPIClient = (*Client)(nil)
171
172// GetTextDetectionPaginatorOptions is the paginator options for GetTextDetection
173type GetTextDetectionPaginatorOptions struct {
174	// Maximum number of results to return per paginated call. The largest value you
175	// can specify is 1000.
176	Limit int32
177
178	// Set to true if pagination should stop if the service returns a pagination token
179	// that matches the most recent token provided to the service.
180	StopOnDuplicateToken bool
181}
182
183// GetTextDetectionPaginator is a paginator for GetTextDetection
184type GetTextDetectionPaginator struct {
185	options   GetTextDetectionPaginatorOptions
186	client    GetTextDetectionAPIClient
187	params    *GetTextDetectionInput
188	nextToken *string
189	firstPage bool
190}
191
192// NewGetTextDetectionPaginator returns a new GetTextDetectionPaginator
193func NewGetTextDetectionPaginator(client GetTextDetectionAPIClient, params *GetTextDetectionInput, optFns ...func(*GetTextDetectionPaginatorOptions)) *GetTextDetectionPaginator {
194	if params == nil {
195		params = &GetTextDetectionInput{}
196	}
197
198	options := GetTextDetectionPaginatorOptions{}
199	if params.MaxResults != nil {
200		options.Limit = *params.MaxResults
201	}
202
203	for _, fn := range optFns {
204		fn(&options)
205	}
206
207	return &GetTextDetectionPaginator{
208		options:   options,
209		client:    client,
210		params:    params,
211		firstPage: true,
212	}
213}
214
215// HasMorePages returns a boolean indicating whether more pages are available
216func (p *GetTextDetectionPaginator) HasMorePages() bool {
217	return p.firstPage || p.nextToken != nil
218}
219
220// NextPage retrieves the next GetTextDetection page.
221func (p *GetTextDetectionPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*GetTextDetectionOutput, error) {
222	if !p.HasMorePages() {
223		return nil, fmt.Errorf("no more pages available")
224	}
225
226	params := *p.params
227	params.NextToken = p.nextToken
228
229	var limit *int32
230	if p.options.Limit > 0 {
231		limit = &p.options.Limit
232	}
233	params.MaxResults = limit
234
235	result, err := p.client.GetTextDetection(ctx, &params, optFns...)
236	if err != nil {
237		return nil, err
238	}
239	p.firstPage = false
240
241	prevToken := p.nextToken
242	p.nextToken = result.NextToken
243
244	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
245		p.nextToken = nil
246	}
247
248	return result, nil
249}
250
251func newServiceMetadataMiddleware_opGetTextDetection(region string) *awsmiddleware.RegisterServiceMetadata {
252	return &awsmiddleware.RegisterServiceMetadata{
253		Region:        region,
254		ServiceID:     ServiceID,
255		SigningName:   "rekognition",
256		OperationName: "GetTextDetection",
257	}
258}
259