Skip to content
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

React UI: Semi-automatic segmentation #1398

Merged
merged 5 commits into from
Apr 14, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Dedicated message with clarifications when share is unmounted (https://github.com/opencv/cvat/pull/1373)
- Ability to create one tracked point (https://github.com/opencv/cvat/pull/1383)
- Tutorial: instructions for CVAT over HTTPS
- Added deep extreme cut (semi-automatic segmentation) to the new UI (https://github.com/opencv/cvat/pull/1398)

### Changed
- Increase preview size of a task till 256, 256 on the server
Expand Down
10 changes: 4 additions & 6 deletions cvat-ui/src/actions/plugins-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function checkPluginsAsync(): ThunkAction {
GIT_INTEGRATION: false,
TF_ANNOTATION: false,
TF_SEGMENTATION: false,
DEXTR_SEGMENTATION: false,
};

const promises: Promise<boolean>[] = [
Expand All @@ -41,15 +42,12 @@ export function checkPluginsAsync(): ThunkAction {
PluginChecker.check(SupportedPlugins.GIT_INTEGRATION),
PluginChecker.check(SupportedPlugins.TF_ANNOTATION),
PluginChecker.check(SupportedPlugins.TF_SEGMENTATION),
PluginChecker.check(SupportedPlugins.DEXTR_SEGMENTATION),
];

const values = await Promise.all(promises);
[plugins.ANALYTICS] = values;
[, plugins.AUTO_ANNOTATION] = values;
[,, plugins.GIT_INTEGRATION] = values;
[,,, plugins.TF_ANNOTATION] = values;
[,,,, plugins.TF_SEGMENTATION] = values;

[plugins.ANALYTICS, plugins.AUTO_ANNOTATION, plugins.GIT_INTEGRATION,
plugins.TF_ANNOTATION, plugins.TF_SEGMENTATION, plugins.DEXTR_SEGMENTATION] = values;
dispatch(pluginActions.checkedAllPlugins(plugins));
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright (C) 2020 Intel Corporation
//
// SPDX-License-Identifier: MIT

import React, { useState } from 'react';
import { connect } from 'react-redux';
import Checkbox, { CheckboxChangeEvent } from 'antd/lib/checkbox';
import Tooltip from 'antd/lib/tooltip';

import { Canvas } from 'cvat-canvas';
import { CombinedState } from 'reducers/interfaces';
import { activate as activatePlugin, deactivate as deactivatePlugin } from 'utils/dextr-utils';


interface StateToProps {
pluginEnabled: boolean;
canvasInstance: Canvas;
}

interface DispatchToProps {
activate(canvasInstance: Canvas): void;
deactivate(canvasInstance: Canvas): void;
}

function mapStateToProps(state: CombinedState): StateToProps {
const {
plugins: {
list,
},
annotation: {
canvas: {
instance: canvasInstance,
},
},
} = state;

return {
canvasInstance,
pluginEnabled: list.DEXTR_SEGMENTATION,
};
}

function mapDispatchToProps(): DispatchToProps {
return {
activate(canvasInstance: Canvas): void {
activatePlugin(canvasInstance);
},
deactivate(canvasInstance: Canvas): void {
deactivatePlugin(canvasInstance);
},
};
}

function DEXTRPlugin(props: StateToProps & DispatchToProps): JSX.Element | null {
const {
pluginEnabled,
canvasInstance,
activate,
deactivate,
} = props;
const [pluginActivated, setActivated] = useState(false);

return (
pluginEnabled ? (
<Tooltip title='Make AI polygon from at least 4 extreme points using deep extreme cut'>
<Checkbox
style={{ marginTop: 5 }}
checked={pluginActivated}
onChange={(event: CheckboxChangeEvent): void => {
setActivated(event.target.checked);
if (event.target.checked) {
activate(canvasInstance);
} else {
deactivate(canvasInstance);
}
}}
>
Make AI polygon
</Checkbox>
</Tooltip>
) : null
);
}

export default connect(
mapStateToProps,
mapDispatchToProps,
)(DEXTRPlugin);

// TODO: Add dialog window with cancel button
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SPDX-License-Identifier: MIT

import React from 'react';

import { Row, Col } from 'antd/lib/grid';
import Select from 'antd/lib/select';
import Button from 'antd/lib/button';
Expand All @@ -15,6 +14,7 @@ import Text from 'antd/lib/typography/Text';
import { RectDrawingMethod } from 'cvat-canvas';
import { ShapeType } from 'reducers/interfaces';
import { clamp } from 'utils/math';
import DEXTRPlugin from './dextr-plugin';

interface Props {
shapeType: ShapeType;
Expand Down Expand Up @@ -81,6 +81,9 @@ function DrawShapePopoverComponent(props: Props): JSX.Element {
</Select>
</Col>
</Row>
{
shapeType === ShapeType.POLYGON && <DEXTRPlugin />
}
{
shapeType === ShapeType.RECTANGLE ? (
<>
Expand Down
1 change: 1 addition & 0 deletions cvat-ui/src/reducers/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export enum SupportedPlugins {
AUTO_ANNOTATION = 'AUTO_ANNOTATION',
TF_ANNOTATION = 'TF_ANNOTATION',
TF_SEGMENTATION = 'TF_SEGMENTATION',
DEXTR_SEGMENTATION = 'DEXTR_SEGMENTATION',
ANALYTICS = 'ANALYTICS',
}

Expand Down
6 changes: 6 additions & 0 deletions cvat-ui/src/reducers/plugins-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import { PluginsActionTypes, PluginActions } from 'actions/plugins-actions';
import { registerGitPlugin } from 'utils/git-utils';
import { registerDEXTRPlugin } from 'utils/dextr-utils';
import {
PluginsState,
} from './interfaces';
Expand All @@ -16,6 +17,7 @@ const defaultState: PluginsState = {
AUTO_ANNOTATION: false,
TF_ANNOTATION: false,
TF_SEGMENTATION: false,
DEXTR_SEGMENTATION: false,
ANALYTICS: false,
},
};
Expand All @@ -39,6 +41,10 @@ export default function (
registerGitPlugin();
}

if (!state.list.DEXTR_SEGMENTATION && list.DEXTR_SEGMENTATION) {
registerDEXTRPlugin();
}

return {
...state,
initialized: true,
Expand Down
Loading