Libraryless. Click here for Pure Java version (7340L/44K).
1 | sclass FaceDataSet {
|
2 | S csvSnippetID = #1032472; |
3 | |
4 | // by imageURL |
5 | new Map<S, Entry> entryMap; |
6 | new L<Entry> entries; |
7 | |
8 | class Entry {
|
9 | S imageURL; |
10 | File imageFile; |
11 | new Set<DoubleRect> facePositions; |
12 | int w, h; |
13 | |
14 | *(S *imageURL) {
|
15 | imageFile = downloadImage(imageURL); |
16 | } |
17 | |
18 | BufferedImage image() {
|
19 | var img = loadImage2(imageFile); |
20 | if (img == null) print(imageFile + " not found"); |
21 | else {
|
22 | w = img.getWidth(); |
23 | h = img.getHeight(); |
24 | } |
25 | ret img; |
26 | } |
27 | |
28 | BufferedImage markedImage(int width default w()) {
|
29 | var img = scaleToWidth(image(), width); |
30 | int height = img.getHeight(); |
31 | for (var face : facePositions) {
|
32 | Rect r = scaleRect_floor(face, width, height); |
33 | drawBox(img, r, Color.red, 0.5); |
34 | } |
35 | ret img; |
36 | } |
37 | |
38 | int w() { if (w == 0) image(); ret w; }
|
39 | int h() { if (h == 0) image(); ret h; }
|
40 | } |
41 | |
42 | File imagesDir() { ret javaxCachesDir("Google Face Data Set"); }
|
43 | |
44 | File downloadImage(S url) {
|
45 | File file = newFile(imagesDir(), md5FileName(url) + fileExtension(url)); |
46 | if (file.length() == 0) null; |
47 | if (!file.exists()) try {
|
48 | loadBinaryPageToFile(url, file); |
49 | } catch e {
|
50 | if (containsExceptionOfType FileNotFoundException(e)) |
51 | // as a warning for future generations! |
52 | saveBinaryFile(file, new byte[0]); |
53 | } |
54 | ret file.exists() ? file : null; |
55 | } |
56 | |
57 | void load {
|
58 | for (LS row : parseExtendedCSV_iterator(loadSnippet(csvSnippetID))) {
|
59 | for n to 3: pcall {
|
60 | int i = n*5; |
61 | S imageURL = convertHttpToHttps(row.get(i++)); |
62 | Entry e = entryMap.get(imageURL); |
63 | if (e == null) {
|
64 | e = new Entry(imageURL); |
65 | if (e.imageFile == null) continue with print("Skipping " + e.imageURL);
|
66 | entryMap.put(imageURL, e); |
67 | entries.add(e); |
68 | } |
69 | |
70 | e.facePositions.add(doubleRectFromPoints( |
71 | parseDouble(row.get(i)), // left column (x1) |
72 | parseDouble(row.get(i+2)), // top row (y1) |
73 | parseDouble(row.get(i+1)), // right column (x2) |
74 | parseDouble(row.get(i+3)), // bottom row (y2) |
75 | )); |
76 | } |
77 | } |
78 | |
79 | print("Have " + nEntries(entries));
|
80 | } |
81 | } |
82 | |
83 | /* Row begins: |
84 | URL of image1 (string) |
85 | Top-left column of the face bounding box in image1 normalized by width (float) |
86 | Bottom-right column of the face bounding box in image1 normalized by width (float) |
87 | Top-left row of the face bounding box in image1 normalized by height (float) |
88 | Bottom-right row of the face bounding box in image1 normalized by height (float) |
89 | */ |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx
No comments. add comment
| Snippet ID: | #1032475 |
| Snippet name: | FaceDataSet |
| Eternal ID of this version: | #1032475/21 |
| Text MD5: | cc3c073aeafe9e8c034dfe36e83b5208 |
| Transpilation MD5: | 5e8e5428e9d0325fb5c581abfaac9acc |
| Author: | stefan |
| Category: | javax / parsing |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2021-09-08 08:18:43 |
| Source code size: | 2701 bytes / 89 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 425 / 635 |
| Version history: | 20 change(s) |
| Referenced in: | [show references] |