-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAutoMultiReceiptExtractionExample.java
More file actions
47 lines (39 loc) · 1.87 KB
/
AutoMultiReceiptExtractionExample.java
File metadata and controls
47 lines (39 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import com.mindee.input.LocalInputSource;
import com.mindee.extraction.ExtractedImage;
import com.mindee.extraction.ImageExtractor;
import com.mindee.v1.MindeeClient;
import com.mindee.v1.parsing.common.PredictResponse;
import com.mindee.v1.parsing.common.Page;
import com.mindee.v1.product.multireceiptsdetector.MultiReceiptsDetectorV1;
import com.mindee.v1.product.multireceiptsdetector.MultiReceiptsDetectorV1Document;
import com.mindee.v1.product.receipt.ReceiptV5;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class AutoMultiReceiptExtractionExample {
private static final String API_KEY = "my-api-key";
private static final MindeeClient mindeeClient = new MindeeClient(API_KEY);
public static void main(String[] args) throws IOException, InterruptedException {
String myFilePath = "/path/to/the/file.ext";
processMultiReceipts(myFilePath);
}
private static void processMultiReceipts(String filePath) throws IOException, InterruptedException {
LocalInputSource inputSource = new LocalInputSource(new File(filePath));
PredictResponse<MultiReceiptsDetectorV1> resultSplit =
mindeeClient.parse(MultiReceiptsDetectorV1.class, inputSource);
ImageExtractor imageExtractor = new ImageExtractor(inputSource);
for (Page<MultiReceiptsDetectorV1Document> page : resultSplit.getDocument().getInference().getPages()) {
List<ExtractedImage> subImages = imageExtractor.extractImagesFromPage(
page.getPrediction().getReceipts(),
page.getPageId()
);
for (ExtractedImage subImage : subImages) {
// Optionally: write to a file
// subImage.writeToFile("/path/to/my/extracted/file/folder");
PredictResponse<ReceiptV5> resultReceipt =
mindeeClient.parse(ReceiptV5.class, subImage.asInputSource());
System.out.println(resultReceipt.getDocument().toString());
}
}
}
}