Skip to content

Commit ad214d5

Browse files
committed
checkpoint, new fullsegmentation component and fix for default
highligh box
1 parent 4e6ff99 commit ad214d5

File tree

5 files changed

+105
-23
lines changed

5 files changed

+105
-23
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @flow
2+
import React from "react"
3+
import Annotator from "../Annotator"
4+
5+
export default ({ onExit, images }) => {
6+
return <Annotator images={images} onExit={onExit} />
7+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// @flow
2+
3+
import React from "react"
4+
5+
import { storiesOf } from "@storybook/react"
6+
import { action } from "@storybook/addon-actions"
7+
import exampleImage from "../ImageCanvas/seves_desk.story.jpg"
8+
9+
import FullImageSegmentationAnnotator from "./"
10+
11+
storiesOf("FullImageSegmentationAnnotator", module).add("Basic", () => (
12+
<div style={{ width: "100vw", height: "100vh" }}>
13+
<FullImageSegmentationAnnotator
14+
images={[
15+
{
16+
name: "Seve's Desk",
17+
src: exampleImage,
18+
},
19+
]}
20+
onExit={action("onExit")}
21+
/>
22+
</div>
23+
))

src/ImageCanvas/index.js

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,21 @@
11
// @flow weak
22

3-
import React, {
4-
Fragment,
5-
useRef,
6-
useState,
7-
useLayoutEffect,
8-
useEffect,
9-
} from "react"
3+
import React, { useRef, useState, useLayoutEffect } from "react"
104
import type { Node } from "react"
115
import { Matrix } from "transformation-matrix-js"
12-
import getImageData from "get-image-data"
136
import Crosshairs from "../Crosshairs"
14-
import type {
15-
Region,
16-
PixelRegion,
17-
Point,
18-
Polygon,
19-
Box,
20-
} from "./region-tools.js"
21-
import { getEnclosingBox } from "./region-tools.js"
7+
import type { Region, Point, Polygon, Box } from "./region-tools.js"
228
import { makeStyles } from "@material-ui/core/styles"
239
import styles from "./styles"
24-
import classnames from "classnames"
25-
import RegionLabel from "../RegionLabel"
26-
import LockIcon from "@material-ui/icons/Lock"
27-
import Paper from "@material-ui/core/Paper"
28-
import HighlightBox from "../HighlightBox"
2910
import PreventScrollToParents from "../PreventScrollToParents"
3011
import useWindowSize from "../hooks/use-window-size.js"
3112
import useMouse from "./use-mouse"
3213
import useProjectRegionBox from "./use-project-box"
33-
import useLoadImage from "../hooks/use-load-image"
3414
import useExcludePattern from "../hooks/use-exclude-pattern"
3515
import { useRafState } from "react-use"
3616
import PointDistances from "../PointDistances"
3717
import RegionTags from "../RegionTags"
18+
import ImageMask from "../ImageMask"
3819
import RegionSelectAndTransformBoxes from "../RegionSelectAndTransformBoxes"
3920
import VideoOrImageCanvasBackground from "../VideoOrImageCanvasBackground"
4021
import useEventCallback from "use-event-callback"
@@ -63,6 +44,8 @@ type Props = {
6344
allowedArea?: { x: number, y: number, w: number, h: number },
6445
RegionEditLabel?: Node,
6546
videoPlaying?: boolean,
47+
mask?: ImageData,
48+
maskVersion?: any,
6649

6750
onChangeRegion: (Region) => any,
6851
onBeginRegionEdit: (Region) => any,
@@ -100,11 +83,13 @@ export default ({
10083
regionClsList,
10184
regionTagList,
10285
showCrosshairs,
103-
showHighlightBox,
86+
showHighlightBox = true,
10487
showPointDistances,
10588
allowedArea,
10689
RegionEditLabel = null,
10790
videoPlaying = false,
91+
mask,
92+
maskVersion,
10893

10994
onImageOrVideoLoaded,
11095
onChangeRegion,
@@ -474,6 +459,7 @@ export default ({
474459
{...mouseEvents}
475460
>
476461
<>
462+
{mask && <ImageMask maskVersion={maskVersion} imageData={mask} />}
477463
<canvas className={classes.canvas} ref={canvasEl} />
478464
<VideoOrImageCanvasBackground
479465
videoPlaying={videoPlaying}

src/ImageMask/index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// @flow
2+
3+
import React, { useState, useEffect, useMemo } from "react"
4+
5+
export default ({ imageData, maskVersion, opacity = 0.5 }) => {
6+
const [canvasRef, setCanvasRef] = useState(null)
7+
8+
useEffect(() => {
9+
if (!canvasRef) return
10+
const context = canvasRef.getContext("2d")
11+
context.putImageData(imageData, 0, 0)
12+
}, [canvasRef, imageData, maskVersion])
13+
14+
const style = useMemo(() => ({ opacity }), [opacity])
15+
16+
return (
17+
<canvas
18+
style={style}
19+
width={imageData.width}
20+
height={imageData.height}
21+
ref={setCanvasRef}
22+
/>
23+
)
24+
}

src/ImageMask/index.story.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// @flow
2+
3+
import React, { useState, useEffect, useReducer } from "react"
4+
5+
import { storiesOf } from "@storybook/react"
6+
import { action } from "@storybook/addon-actions"
7+
8+
import ImageMask from "./"
9+
10+
const [width, height] = [200, 200]
11+
12+
const uint8Array = new Uint8ClampedArray(4 * width * width)
13+
14+
for (let ri = 0; ri < width; ri++) {
15+
for (let ci = 0; ci < height; ci++) {
16+
uint8Array[(ri * width + ci) * 4 + 0] = Math.floor(Math.random() * 256)
17+
uint8Array[(ri * width + ci) * 4 + 1] = Math.floor(Math.random() * 256)
18+
uint8Array[(ri * width + ci) * 4 + 2] = Math.floor(Math.random() * 256)
19+
uint8Array[(ri * width + ci) * 4 + 3] = 255
20+
}
21+
}
22+
23+
const imageData = new ImageData(uint8Array, width, width)
24+
25+
storiesOf("ImageMask", module)
26+
.add("Basic", () => <ImageMask imageData={imageData} />)
27+
.add("Changing", () => {
28+
const [version, incVersion] = useReducer((state) => state + 1, 0)
29+
30+
// Notice how you don't need to allocate new memory
31+
useEffect(() => {
32+
setInterval(() => {
33+
for (let i = 0; i < uint8Array.length; i++) {
34+
if (i % 4 !== 3) {
35+
uint8Array[i] = Math.floor(Math.random() * 256)
36+
}
37+
}
38+
incVersion()
39+
}, 500)
40+
}, [])
41+
return <ImageMask maskVersion={version} imageData={imageData} />
42+
})

0 commit comments

Comments
 (0)