Skip to content

Commit 37d55c4

Browse files
committed
add type for keyframe-based video annotation, add type for video frame
support. Restrcuture reducers
1 parent ebe7a5e commit 37d55c4

File tree

6 files changed

+79
-16
lines changed

6 files changed

+79
-16
lines changed

src/Annotator/index.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ import type {
1010
Action
1111
} from "../MainLayout/types"
1212
import SettingsProvider from "../SettingsProvider"
13-
import reducer from "./reducer"
13+
14+
import combineReducers from "./reducers/combine-reducers.js"
15+
import generalReducer from "./reducers/general-reducer.js"
16+
import imageReducer from "./reducers/image-reducer.js"
17+
import videoReducer from "./reducers/video-reducer.js"
18+
1419
import makeImmutable from "seamless-immutable"
1520

1621
type Props = {
@@ -32,7 +37,8 @@ type Props = {
3237
export const Annotator = ({
3338
images,
3439
allowedArea,
35-
selectedImage = images.length > 0 ? images[0].src : undefined,
40+
selectedImage = images && images.length > 0 ? images[0].src : undefined,
41+
selectedVideoTime = 0,
3642
showPointDistances,
3743
pointDistancePrecision,
3844
showTags = true,
@@ -42,10 +48,13 @@ export const Annotator = ({
4248
imageTagList = [],
4349
imageClsList = [],
4450
taskDescription,
51+
videoSrc,
4552
onExit
4653
}: Props) => {
54+
if (!images) return 'Missing required prop "images" or "videoSrc"'
4755
const [state, dispatchToReducer] = useReducer(
48-
reducer,
56+
combineReducers(generalReducer),
57+
// reducer,
4958
makeImmutable({
5059
showTags,
5160
allowedArea,
@@ -82,7 +91,7 @@ export const Annotator = ({
8291

8392
return (
8493
<SettingsProvider>
85-
<MainLayout debug state={state} dispatch={dispatch} />
94+
<MainLayout state={state} dispatch={dispatch} />
8695
</SettingsProvider>
8796
)
8897
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default (...reducers) => (state, action) => {
2+
for (const reducer of reducers) {
3+
state = reducer(state, action)
4+
}
5+
return state
6+
}

src/Annotator/reducer.js renamed to src/Annotator/reducers/general-reducer.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22

3-
import type { MainLayoutState, Action } from "../MainLayout/types"
4-
import { moveRegion } from "../ImageCanvas/region-tools.js"
3+
import type { MainLayoutState, Action } from "../../MainLayout/types"
4+
import { moveRegion } from "../../ImageCanvas/region-tools.js"
55
import { setIn, updateIn } from "seamless-immutable"
66
import moment from "moment"
77
import isEqual from "lodash/isEqual"
@@ -28,13 +28,11 @@ const typesToSaveWithHistory = {
2828
DELETE_REGION: "Delete Region"
2929
}
3030

31-
let lastMouseMoveCall = Date.now()
32-
3331
export default (state: MainLayoutState, action: Action) => {
3432
// Throttle certain actions
3533
if (action.type === "MOUSE_MOVE") {
36-
if (Date.now() - lastMouseMoveCall < 16) return state
37-
lastMouseMoveCall = Date.now()
34+
if (Date.now() - ((state: any).lastMouseMoveCall || 0) < 16) return state
35+
state = setIn(state, ["lastMouseMoveCall"], Date.now())
3836
}
3937
if (!action.type.includes("MOUSE")) {
4038
state = setIn(state, ["lastAction"], action)
@@ -554,7 +552,6 @@ export default (state: MainLayoutState, action: Action) => {
554552
}
555553
}
556554
return state
557-
// return setIn(state, [""]
558555
}
559556
case "SELECT_TOOL": {
560557
state = setIn(state, ["mode"], null)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @flow
2+
3+
import type {
4+
MainLayoutImageAnnotationState,
5+
Action
6+
} from "../../MainLayout/types"
7+
8+
export default (state: MainLayoutState, action: Action) => {
9+
return state
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @flow
2+
3+
import type {
4+
MainLayoutVideoAnnotationState,
5+
Action
6+
} from "../../MainLayout/types"
7+
8+
export default (state: MainLayoutVideoAnnotationState, action: Action) => {
9+
return state
10+
}

src/MainLayout/types.js

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export type Image = {
2222
name: string,
2323
regions?: Array<Region>,
2424
pixelSize?: { w: number, h: number },
25-
realSize?: { w: number, h: number, unitName: string }
25+
realSize?: { w: number, h: number, unitName: string },
26+
videoTime?: number
2627
}
2728

2829
export type Mode =
@@ -39,19 +40,17 @@ export type Mode =
3940
|}
4041
| {| mode: "MOVE_REGION" |}
4142

42-
export type MainLayoutState = {|
43+
export type MainLayoutStateBase = {|
44+
annotationType: "video" | "image",
4345
fullScreen?: boolean,
4446
settingsOpen?: boolean,
4547
minRegionSize?: number,
4648
showTags: boolean,
4749
showPointDistances?: boolean,
4850
pointDistancePrecision?: number,
49-
selectedImage?: string,
5051
selectedTool: ToolEnum,
5152
mode: Mode,
5253
taskDescription: string,
53-
images: Array<Image>,
54-
labelImages?: boolean,
5554
allowedArea?: { x: number, y: number, w: number, h: number },
5655
regionClsList?: Array<string>,
5756
regionTagList?: Array<string>,
@@ -61,6 +60,38 @@ export type MainLayoutState = {|
6160
history: Array<{ time: Date, state: MainLayoutState, name: string }>
6261
|}
6362

63+
export type MainLayoutImageAnnotationState = {|
64+
...MainLayoutStateBase,
65+
annotationType: "image",
66+
67+
selectedImage?: string,
68+
images: Array<Image>,
69+
labelImages?: boolean,
70+
71+
// If the selectedImage corresponds to a frame of a video
72+
selectedVideoTime?: number
73+
|}
74+
75+
export type MainLayoutVideoAnnotationState = {|
76+
...MainLayoutStateBase,
77+
annotationType: "video",
78+
79+
videoSrc: string,
80+
currentVideoTime: number,
81+
keyframes: {
82+
[time: number]: {
83+
time: number,
84+
regions: Array<Region>
85+
}
86+
},
87+
pixelSize?: { w: number, h: number },
88+
realSize?: { w: number, h: number, unitName: string }
89+
|}
90+
91+
export type MainLayoutState =
92+
| MainLayoutImageAnnotationState
93+
| MainLayoutVideoAnnotationState
94+
6495
export type Action =
6596
| {| type: "@@INIT" |}
6697
| {| type: "SELECT_IMAGE", image: Image |}

0 commit comments

Comments
 (0)