Skip to content

Commit

Permalink
added ui to indicate tracking progress
Browse files Browse the repository at this point in the history
  • Loading branch information
hxhxhx88 committed Oct 20, 2023
1 parent d22ece3 commit 9e057dc
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 121 deletions.
100 changes: 0 additions & 100 deletions app/frontend/src/component/panel/TrackOverlay.tsx

This file was deleted.

13 changes: 12 additions & 1 deletion app/frontend/src/component/panel/entity/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import intl from 'react-intl-universal';
import shallow from 'zustand/shallow';
import {css} from '@emotion/react';

import {Space, Card, Typography, Button, Popconfirm} from 'antd';
import {Space, Card, Typography, Button, Popconfirm, Progress, Spin} from 'antd';
import {EditOutlined, DeleteOutlined} from '@ant-design/icons';

import {useStore as useAnnoStore} from 'state/annotate/annotation';
import {useStore as useRenderStore} from 'state/annotate/render';
import {useStore as useUIStore} from 'state/annotate/ui';

import {EditColor} from 'common/constant';
import {convertRGBA2Hex} from 'common/color';
Expand Down Expand Up @@ -146,6 +147,7 @@ export const EntityCard: FC<{
</Popconfirm>,
]}
>
<TrackingProgress eid={entityId} />
<Paragraph style={{marginBottom: 0}}>
<Text strong style={{marginRight: 4}}>
{intl.get('frame')}
Expand Down Expand Up @@ -177,3 +179,12 @@ export const EntityCard: FC<{
</Card>
);
};

const TrackingProgress: FC<{eid: string}> = ({eid}) => {
const progress = useUIStore(s => s.tracking[eid]);
return progress === undefined ? null : progress > 0 ? (
<Progress percent={progress * 100} showInfo={false} />
) : (
<Spin size="small" style={{margin: '8px 0'}} />
);
};
34 changes: 29 additions & 5 deletions app/frontend/src/component/panel/menu/mask.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import intl from 'react-intl-universal';
import {v4 as uuidv4} from 'uuid';
import {Component, EntityId, MaskComponent, SliceIndex} from 'type/annotation';
import {TrackingContext} from 'state/annotate/ui';
import {useStore as useUIStore} from 'state/annotate/ui';
import {useStore as useRenderStore} from 'state/annotate/render';
import {useStore as useAnnoStore} from 'state/annotate/annotation';
import {Action} from './common';
Expand All @@ -14,7 +14,8 @@ export function useActions(mask: MaskComponent, eid: EntityId): Action[] {
const config = useContext(ConfigContext);

const isLastSlice = useRenderStore(s => s.sliceIndex + 1 === s.sliceUrls.length);
// const setTracking = useUIStore(s => s.setTracking);
const setTracking = useUIStore(s => s.setTracking);
const deleteTracking = useUIStore(s => s.deleteTracking);

const sliceSize = useRenderStore(s => s.sliceSize);
const currentSliceIndex = useRenderStore(s => s.sliceIndex);
Expand All @@ -24,10 +25,11 @@ export function useActions(mask: MaskComponent, eid: EntityId): Action[] {
const commitDraftComponents = useAnnoStore(s => s.commitDraftComponents);

const track = useCallback(
({mask}: TrackingContext) => {
(mask: MaskComponent) => {
if (!sliceSize) {
return;
}
setTracking(eid, 0);

const {rle, offset} = mask;
const {
Expand Down Expand Up @@ -61,6 +63,9 @@ export function useActions(mask: MaskComponent, eid: EntityId): Action[] {
return;
}

const total = req.subsequent_frame_urls.length;
let maxFrameIndex = 0;

// one or more results might be concatecated together
const resultJsonStrs = splitJSONs(new TextDecoder().decode(value));
const newComponents: {sliceIndex: SliceIndex; component: Component}[] = [];
Expand All @@ -78,6 +83,12 @@ export function useActions(mask: MaskComponent, eid: EntityId): Action[] {
mask: {coco_encoded_rle, width, height},
} = resultJson;

if (fidx > maxFrameIndex) {
// made progress
maxFrameIndex = fidx;
setTracking(eid, maxFrameIndex / total);
}

const counts = rleCountsFromStringCOCO(coco_encoded_rle);
const mask = shrink({counts, size: {width, height}});
if (!mask) {
Expand All @@ -103,15 +114,28 @@ export function useActions(mask: MaskComponent, eid: EntityId): Action[] {
})
.catch(error => {
console.error('fetch error:', error);
})
.finally(() => {
deleteTracking(eid);
});
},
[addComponents, commitDraftComponents, currentSliceIndex, currentSliceUrl, eid, sliceSize, subsequentSliceUrls]
[
addComponents,
commitDraftComponents,
currentSliceIndex,
currentSliceUrl,
deleteTracking,
eid,
setTracking,
sliceSize,
subsequentSliceUrls,
]
);

return [
{
title: intl.get('menu.auto_track'),
fn: () => track({mask, entityId: eid}),
fn: () => track(mask),
disableReason: isLastSlice
? intl.get('menu.auto_track_unapplicable_last_slice')
: !config.track_enabled
Expand Down
4 changes: 0 additions & 4 deletions app/frontend/src/page/annotate/Panel/Loaded.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {leftSidebarWidth, statusBarHeight, sliderHeight, rightSidebarWidth} from
import {ActionBar} from 'component/panel/ActionBar';
import {EntityBar} from 'component/panel/EntityBar';
import {Canvas} from './Canvas';
import {TrackOverlay} from 'component/panel/TrackOverlay';

export const PanelLoaded: FC<{
video: Video;
Expand Down Expand Up @@ -72,9 +71,6 @@ export const PanelLoaded: FC<{
}}
/>
</div>
<TrackOverlay
style={{background: 'rgba(0,0,0,0.8)', position: 'absolute', left: 0, top: 0, width: '100%', height: '100%'}}
/>
<SyncingDisableInteractionMask />
<MonitorAnnotation videoId={video.id} />
</div>
Expand Down
22 changes: 11 additions & 11 deletions app/frontend/src/state/annotate/ui.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {MaskComponent} from 'type/annotation';
import create from 'zustand';
import {immer} from 'zustand/middleware/immer';

Expand All @@ -11,8 +10,9 @@ export type State = {
mouseClient: [number, number] | undefined;
setMouseClient: (mouseClient: [number, number] | undefined) => void;

tracking: TrackingContext | undefined;
setTracking: (ctx: TrackingContext | undefined) => void;
tracking: {[key: string /* entity id */]: number /* progress in [0, 1] */};
setTracking: (entityId: string, progress: number) => void;
deleteTracking: (entityId: string) => void;
};

export const useStore = create<State>()(
Expand All @@ -31,16 +31,16 @@ export const useStore = create<State>()(
});
},

tracking: undefined,
setTracking: (ctx: TrackingContext | undefined) => {
tracking: {},
setTracking: (entityId: string, progress: number) => {
set(s => {
s.tracking = ctx;
s.tracking[entityId] = progress;
});
},
deleteTracking: (entityId: string) => {
set(s => {
delete s.tracking[entityId];
});
},
}))
);

export type TrackingContext = {
entityId: string;
mask: MaskComponent;
};

0 comments on commit 9e057dc

Please sign in to comment.