Skip to content

Feature: Modify Allowed Area #85

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 3 commits into from
Aug 18, 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
4 changes: 2 additions & 2 deletions src/Annotator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import useEventCallback from "use-event-callback"
import makeImmutable, { without } from "seamless-immutable"

type Props = {
taskDescription: string,
taskDescription?: string,
allowedArea?: { x: number, y: number, w: number, h: number },
regionTagList?: Array<string>,
regionClsList?: Array<string>,
Expand Down Expand Up @@ -68,7 +68,7 @@ export const Annotator = ({
imageTagList = [],
imageClsList = [],
keyframes = {},
taskDescription,
taskDescription = "",
fullImageSegmentationMode = false,
RegionEditLabel,
videoSrc,
Expand Down
57 changes: 28 additions & 29 deletions src/Annotator/index.story.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ import Annotator from "./"

import { testRegions } from "../ImageCanvas/index.story"

const middlewares = [
(store) => (next) => (action) => {
actionAddon(action.type)(action)
return next(action)
},
]

storiesOf("Annotator", module)
.add("Basic", () => (
<Annotator
onExit={actionAddon("onExit")}
middlewares={[
(store) => (next) => (action) => {
actionAddon(action.type)(action)
return next(action)
},
]}
middlewares={middlewares}
labelImages
regionClsList={["Alpha", "Beta", "Charlie", "Delta"]}
regionTagList={["tag1", "tag2", "tag3"]}
Expand Down Expand Up @@ -112,12 +114,7 @@ storiesOf("Annotator", module)
.add("Annotator w/o No Region Labels or Image Labels", () => (
<Annotator
onExit={actionAddon("onExit")}
middlewares={[
(store) => (next) => (action) => {
actionAddon(action.type)(action)
return next(action)
},
]}
middlewares={middlewares}
images={[
{
src: exampleImage,
Expand All @@ -132,12 +129,7 @@ storiesOf("Annotator", module)
onExit={actionAddon("onExit")}
enabledTools={[]}
showTags={false}
middlewares={[
(store) => (next) => (action) => {
actionAddon(action.type)(action)
return next(action)
},
]}
middlewares={middlewares}
images={[
{
src: exampleImage,
Expand Down Expand Up @@ -195,12 +187,7 @@ storiesOf("Annotator", module)
.add("Car Annotation", () => (
<Annotator
onExit={actionAddon("onExit")}
middlewares={[
(store) => (next) => (action) => {
actionAddon(action.type)(action)
return next(action)
},
]}
middlewares={middlewares}
labelImages
regionClsList={["Car", "Sign", "Construction Barrier"]}
regionTagList={["Moving", "Stopped", "Obstacle"]}
Expand Down Expand Up @@ -650,18 +637,30 @@ storiesOf("Annotator", module)
.add("CORs Error (Pixel Segmentation)", () => (
<Annotator
onExit={actionAddon("onExit")}
middlewares={[
(store) => (next) => (action) => {
actionAddon(action.type)(action)
return next(action)
middlewares={middlewares}
labelImages
fullImageSegmentationMode
regionClsList={["Alpha", "Beta", "Charlie", "Delta"]}
images={[
{
src: "https://placebear.com/200/300",
name: "Frame 0036",
},
]}
/>
))
.add("Modify Allowed Area", () => (
<Annotator
onExit={actionAddon("onExit")}
middlewares={middlewares}
labelImages
fullImageSegmentationMode
allowedArea={{ x: 0, y: 0.6, w: 0.3, h: 0.3 }}
enabledTools={["modify-allowed-area"]}
regionClsList={["Alpha", "Beta", "Charlie", "Delta"]}
images={[
{
src: "https://placebear.com/200/300",
src: exampleImage,
name: "Frame 0036",
},
]}
Expand Down
31 changes: 28 additions & 3 deletions src/Annotator/reducers/general-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const getRandomId = () => Math.random().toString().split(".")[1]
export default (state: MainLayoutState, action: Action) => {
if (
state.allowedArea &&
state.selectedTool !== "modify-allowed-area" &&
["MOUSE_DOWN", "MOUSE_UP", "MOUSE_MOVE"].includes(action.type)
) {
const aa = state.allowedArea
Expand Down Expand Up @@ -241,6 +242,17 @@ export default (state: MainLayoutState, action: Action) => {
}
case "MOVE_REGION": {
const { regionId } = state.mode
if (regionId === "$$allowed_area") {
const {
allowedArea: { w, h },
} = state
return setIn(state, ["allowedArea"], {
x: x - w / 2,
y: y - h / 2,
w,
h,
})
}
const regionIndex = getRegionIndex(regionId)
if (regionIndex === null) return state
return setIn(
Expand All @@ -255,9 +267,6 @@ export default (state: MainLayoutState, action: Action) => {
freedom: [xFree, yFree],
original: { x: ox, y: oy, w: ow, h: oh },
} = state.mode
const regionIndex = getRegionIndex(regionId)
if (regionIndex === null) return state
const box = activeImage.regions[regionIndex]

const dx = xFree === 0 ? ox : xFree === -1 ? Math.min(ox + ow, x) : ox
const dw =
Expand All @@ -282,6 +291,19 @@ export default (state: MainLayoutState, action: Action) => {
state = setIn(state, ["mode", "freedom"], [xFree, yFree * -1])
}

if (regionId === "$$allowed_area") {
return setIn(state, ["allowedArea"], {
x: dx,
w: dw,
y: dy,
h: dh,
})
}

const regionIndex = getRegionIndex(regionId)
if (regionIndex === null) return state
const box = activeImage.regions[regionIndex]

return setIn(state, [...pathToActiveImage, "regions", regionIndex], {
...box,
x: dx,
Expand Down Expand Up @@ -699,6 +721,9 @@ export default (state: MainLayoutState, action: Action) => {
} else if (action.selectedTool === "show-mask") {
return setIn(state, ["showMask"], !state.showMask)
}
if (action.selectedTool === "modify-allowed-area" && !state.allowedArea) {
state = setIn(state, ["allowedArea"], { x: 0, y: 0, w: 1, h: 1 })
}
state = setIn(state, ["mode"], null)
return setIn(state, ["selectedTool"], action.selectedTool)
}
Expand Down
134 changes: 0 additions & 134 deletions src/IconTools/index.js

This file was deleted.

21 changes: 20 additions & 1 deletion src/ImageCanvas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type Props = {
zoomOnAllowedArea?: boolean,
fullImageSegmentationMode?: boolean,
autoSegmentationOptions?: Object,
modifyingAllowedArea?: boolean,

onChangeRegion: (Region) => any,
onBeginRegionEdit: (Region) => any,
Expand Down Expand Up @@ -126,6 +127,7 @@ export const ImageCanvas = ({
onChangeVideoPlaying,
onRegionClassAdded,
zoomOnAllowedArea = true,
modifyingAllowedArea = false,
}: Props) => {
const classes = useStyles()

Expand Down Expand Up @@ -325,7 +327,24 @@ export const ImageCanvas = ({
{imageLoaded && !dragging && (
<RegionSelectAndTransformBoxes
key="regionSelectAndTransformBoxes"
regions={regions}
regions={
!modifyingAllowedArea || !allowedArea
? regions
: [
{
type: "box",
id: "$$allowed_area",
cls: "allowed_area",
highlighted: true,
x: allowedArea.x,
y: allowedArea.y,
w: allowedArea.w,
h: allowedArea.h,
visible: true,
color: "#ff0",
},
]
}
mouseEvents={mouseEvents}
projectRegionBox={projectRegionBox}
dragWithPrimary={dragWithPrimary}
Expand Down
10 changes: 10 additions & 0 deletions src/ImageCanvas/index.story.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,13 @@ storiesOf("ImageCanvas", module)
{...events}
/>
))
.add("Modify Allowed Area", () => (
<ImageCanvas
showTags
regions={[]}
imageSrc={exampleImage}
modifyingAllowedArea
allowedArea={{ x: 0.6, y: 0.6, w: 0.2, h: 0.2 }}
{...events}
/>
))
4 changes: 4 additions & 0 deletions src/MainLayout/icon-dictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
faHandPaper,
faSearch,
faMask,
faEdit,
} from "@fortawesome/free-solid-svg-icons"
import FullscreenIcon from "@material-ui/icons/Fullscreen"

Expand Down Expand Up @@ -63,6 +64,9 @@ export const iconDictionary = {
"show-mask": () => (
<FontAwesomeIcon style={faStyle} size="xs" fixedWidth icon={faMask} />
),
"modify-allowed-area": () => (
<FontAwesomeIcon style={faStyle} size="xs" fixedWidth icon={faEdit} />
),
window: FullscreenIcon,
}

Expand Down
Loading