Skip to content

Commit

Permalink
export annotation json
Browse files Browse the repository at this point in the history
  • Loading branch information
16Yongjin committed Jul 24, 2020
1 parent 1951c2e commit e99b44e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = {
{ accessibility: 'no-public' }
],
'@typescript-eslint/camelcase': 'off',
'@typescript-eslint/ban-ts-ignore': 'off'
'@typescript-eslint/ban-ts-ignore': 'off',
'@typescript-eslint/member-delimiter-style': 'off'
}
}
2 changes: 1 addition & 1 deletion src/utils/export/bbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const processExportBBox = (datasets: Dataset[]) => {
}
})

return exportData
return JSON.stringify(exportData)
}

export const serializeBBoxDataset = ({ annotations, path }: Dataset) => {
Expand Down
29 changes: 28 additions & 1 deletion src/utils/file/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path'
import { remote } from 'electron'
import { readdir } from 'mz/fs'
import { readdir, writeFile } from 'mz/fs'

export const showFolderDialog = async () => {
const { filePaths, canceled } = await remote.dialog.showOpenDialog({
Expand All @@ -26,3 +26,30 @@ export const readImagePaths = async (dirPath: string) => {

return imagePaths
}

interface SaveFileInterface {
defaultPath: string
file: string
}

export const saveFile = async ({ defaultPath, file }: SaveFileInterface) => {
const win = remote.getCurrentWindow()
try {
const dialogOptions = {
title: 'Save Annotation json',
defaultPath: `${defaultPath}/output.json`,
filters: [{ name: 'JSON', extensions: ['json'] }]
}

const { canceled, filePath } = await remote.dialog.showSaveDialog(
win,
dialogOptions
)

if (canceled || !filePath) return

await writeFile(filePath, file)
} catch (e) {
remote.dialog.showErrorBox('Failed to save annotation file', e.toString())
}
}
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from '@/utils/import'
export * from '@/utils/show'
export * from '@/utils/draw'
export * from '@/utils/edit'
export * from '@/utils/file'

export enum Tool {
Draw,
Expand Down
6 changes: 5 additions & 1 deletion src/views/annotator/BBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { UserAction, MultipleDrawAction } from '@/models/user/actions'
import {
Tool,
toDataUrl,
saveFile,
BBoxEditTool,
createBBoxDrawTool,
createBBoxFromDetector,
Expand Down Expand Up @@ -98,8 +99,11 @@ export default class BBox extends Annotator {
}
exportAnnotation() {
if (!this.project) return
const exportData = processExportBBox(this.datasets)
console.log(exportData)
saveFile({ defaultPath: this.project.info.path, file: exportData })
}
attachAnnotationInteraction(bbox: Annotation) {
Expand Down

0 comments on commit e99b44e

Please sign in to comment.