Skip to content

Adding schema files to download #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions frontend/public/schema/image_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"hash": { "type": "string" },
"filename": { "type": "string" },
"exifdata": {
"type": "object",
"properties": {
"Make": { "type": "string" },
"Model": { "type": "string" },
"DateTimeOriginal": { "type": "integer" },
"ModifyDate": { "type": "integer" },
"CreateDate": { "type": "integer" },
"GPSLatitudeRef": { "type": "string" },
"GPSLatitude": { "type": "number" },
"GPSLongitudeRef": { "type": "string" },
"GPSLongitude": { "type": "number" },
"GPSAltitudeRef": { "type": "integer" },
"GPSAltitude": { "type": "number" },
"GPSTimeStamp": {
"type": "array",
"items": { "type": "integer" }
},
"GPSDateStamp": { "type": "string" },
"ExifImageWidth": { "type": "integer" },
"ExifImageHeight": { "type": "integer" }
},
"required": [
"Make",
"Model",
"DateTimeOriginal",
"ModifyDate",
"CreateDate",
"GPSLatitudeRef",
"GPSLatitude",
"GPSLongitudeRef",
"GPSLongitude",
"GPSAltitudeRef",
"GPSAltitude",
"GPSTimeStamp",
"GPSDateStamp",
"ExifImageWidth",
"ExifImageHeight"
]
},
"metadata": {
"type": "array",
"items": {
"type": "object",
"properties": {
"score": { "type": "string" },
"correction": { "type": "string" },
"remove": { "type": "boolean" },
"is_tf": { "type": "boolean" },
"id": { "type": "string" },
"label": { "type": "string" },
"area": {
"type": "object",
"properties": {
"x1": { "type": "number" },
"y1": { "type": "number" },
"x2": { "type": "number" },
"y2": { "type": "number" }
},
"required": ["x1", "y1", "x2", "y2"]
}
},
"required": [
"score",
"correction",
"remove",
"is_tf",
"id",
"label",
"area"
]
}
}
},
"required": ["hash", "filename", "exifdata", "metadata"]
}
38 changes: 38 additions & 0 deletions frontend/public/schema/image_schema.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Image Schema Description

**hash** (String): A hash associated with the image file.

**filename** (String): The filename of the image.

**exifdata** (Object): An object that contains EXIF data with the following properties:

- **Make** (String): The manufacturer of the camera that took the image.
- **Model** (String): The camera model that took the image.
- **DateTimeOriginal** (Integer): The original date and time the image was taken, represented as a Unix timestamp.
- **ModifyDate** (Integer): The date and time the image was last modified, represented as a Unix timestamp.
- **CreateDate** (Integer): The date and time the image was created, represented as a Unix timestamp.
- **GPSLatitudeRef** (String): The reference for latitude (usually "N" or "S").
- **GPSLatitude** (Number): The latitude coordinate of where the image was taken.
- **GPSLongitudeRef** (String): The reference for longitude (usually "E" or "W").
- **GPSLongitude** (Number): The longitude coordinate of where the image was taken.
- **GPSAltitudeRef** (Integer): The reference for altitude (usually 0).
- **GPSAltitude** (Number): The altitude where the image was taken.
- **GPSTimeStamp** (Array): The GPS timestamp of when the image was taken, represented as an array of integers [hours, minutes, seconds].
- **GPSDateStamp** (String): The GPS date when the image was taken.
- **ExifImageWidth** (Integer): The width of the original image.
- **ExifImageHeight** (Integer): The height of the original image.

**metadata** (Array): An array of objects where each object represents a detected item with the following properties:

- **score** (String): The confidence score of the AI model for the detection.
- **correction** (String): A correction applied to the AI model's prediction. This is usually empty if no correction is applied.
- **remove** (Boolean): A flag indicating whether this detection should be removed. False means the detection is valid.
- **is_tf** (Boolean): A flag indicating if the detection is a true positive (true) or false positive (false).
- **id** (String): A unique identifier for the detection.
- **label** (String): The label of the detected item (e.g., "Plastic film").
area (Object): An object that contains the coordinates of the detected area with the following properties:
- **x1** (Number): The x-coordinate of the top left corner of the detected area.
- **y1** (Number): The y-coordinate of the top left corner of the detected area.
- **x2** (Number): The x-coordinate of the bottom right corner of the detected area.
- **y2** (Number): The y-coordinate of the bottom right corner of the detected area.
Please note that all of the properties described above are required. If any property is missing or if a property's value is of an incorrect type, the JSON will not validate against the schema.
55 changes: 55 additions & 0 deletions frontend/public/schema/summary_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"detected_objects": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"count": { "type": "integer", "minimum": 0 },
"hashes": { "type": "array", "items": { "type": "string" } }
},
"required": ["name", "count", "hashes"]
}
},
"no_detection_hashes": {
"type": "array",
"items": { "type": "string" }
},
"unique_detections": { "type": "integer", "minimum": 0 },
"total_detections": { "type": "integer", "minimum": 0 },
"gps": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"type": "object",
"properties": {
"coordinate": {
"type": "object",
"properties": {
"lat": { "type": "number" },
"lng": { "type": "number" }
},
"required": ["lat", "lng"]
},
"hash": { "type": "string" }
},
"required": ["coordinate", "hash"]
}
}
},
"required": ["list"]
}
},
"required": [
"detected_objects",
"no_detection_hashes",
"unique_detections",
"total_detections",
"gps"
]
}
22 changes: 22 additions & 0 deletions frontend/public/schema/summary_schema.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Summary Schema Description

**detected_objects** (Array): An array of objects where each object represents a detected item with the following properties:

- **name** (String): The name of the detected item (e.g., "Plastic film").
- **count** (Integer): The count of the detected item. This number should be a non-negative integer.
- **hashes** (Array): An array of strings where each string represents a hash associated with the detected item.

**no_detection_hashes** (Array): An array of strings where each string represents a hash that is associated with items not detected.

**unique_detections** (Integer): The count of unique detections. This number should be a non-negative integer.

**total_detections** (Integer): The total count of detections. This number should be a non-negative integer.

**gps** (Object): An object that contains GPS information with the following properties:

- **list** (Array): An array of objects where each object represents a GPS location with the following properties:

- **coordinate** (Object): An object that contains the GPS coordinates with the following properties:
- **lat** (Number): The latitude of the location.
- **lng** (Number): The longitude of the location.
- **hash** (String): A hash associated with the location.
85 changes: 45 additions & 40 deletions frontend/src/lib/store/images.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { imagedb, dataURLtoBlob } from '@/lib/imagedb'
import { saveAs } from 'file-saver'
import TensorFlow from '@/lib/tensorflow'
import JSZip from 'jszip'
import lodash from 'lodash'
import { defineStore } from 'pinia'
import type { _GettersTree } from 'pinia'
import { log } from '@/lib/logging'
import PQueue from 'p-queue'
import { DrawCanvas } from '@/lib/draw'
import { resizeImage } from '@/lib/util'
import { dataURLtoBlob, imagedb } from '@/lib/imagedb'
import { log } from '@/lib/logging'
import {
Display,
Progress,
BaseImage,
Capacity,
Summary,
Display,
PAGE_SIZE,
StorageCapacity,
BaseImage,
Progress,
SaveData,
StorageCapacity,
Summary,
TrashObject,
} from '@/lib/models'
import TensorFlow from '@/lib/tensorflow'
import { getStaticFiles, resizeImage } from '@/lib/util'
import { saveAs } from 'file-saver'
import JSZip from 'jszip'
import lodash from 'lodash'
import PQueue from 'p-queue'
import type { _GettersTree } from 'pinia'
import { defineStore } from 'pinia'

let initialized = false

Expand Down Expand Up @@ -133,30 +133,21 @@ export const useImageStore = defineStore<
this.capacity = await StorageCapacity.getCapacity()
},
async do_sampleupload() {
const sample_files = async () => {
const files = [
'sample01.jpg',
'sample02.jpg',
'sample03.jpg',
'sample05.jpg',
'sample06.jpg',
'sample07.jpg',
'sample08.jpg',
]
const retval = []
for (let i = 0; i < files.length; i++) {
const file = files[i]
const url = `/samples/${file}`
const blob = await fetch(url).then((r) => r.blob())
retval.push(
new File([blob], file, {
type: blob.type,
}),
)
}
return retval
}
const files = await sample_files()
const blobs = await getStaticFiles([
'/samples/sample01.jpg',
'/samples/sample02.jpg',
'/samples/sample03.jpg',
'/samples/sample05.jpg',
'/samples/sample06.jpg',
'/samples/sample07.jpg',
'/samples/sample08.jpg',
])
const files = blobs.map(
(f) =>
new File([f.blob], f.filePath.substring(9), {
type: f.blob.type,
}),
)
await this.doupload(files)
},

Expand Down Expand Up @@ -325,7 +316,21 @@ export const useImageStore = defineStore<
const zp = this.zip

return new Promise(async (resolve) => {
zp.total = await imagedb.savedata.count()
const schemaFilePaths = [
'/schema/image_schema.json',
'/schema/image_schema.md',
'/schema/summary_schema.json',
'/schema/summary_schema.md',
]

zp.total =
(await imagedb.savedata.count()) + schemaFilePaths.length

const schemaFiles = await getStaticFiles(schemaFilePaths)
schemaFiles.map((r) =>
folder!.file(r.filePath.substring(1), r.blob),
)

await imagedb.savedata.each((image: SaveData) => {
zp.current = image.filename ?? ''
const blob = dataURLtoBlob(image!.processeddataUrl!)
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export const invertImageData = (data: ImageData) => {
return data
}


export function Timer(callback: Function, time: number) {
// @ts-ignore
this.setTimeout(callback, time)
Expand Down Expand Up @@ -129,3 +128,12 @@ Timer.prototype.add = function (time: number) {
this.setTimeout(this.callback, time)
}
}

export const getStaticFiles = (filePaths: string[]) =>
Promise.all(
filePaths.map((path) =>
fetch(path)
.then((r) => r.blob())
.then((blob) => ({ filePath: path, blob })),
),
)