@searpent/react-image-annotate 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/.babelrc +6 -0
  2. package/.env +1 -0
  3. package/.flowconfig +2 -0
  4. package/.github/workflows/release-on-master.yml +32 -0
  5. package/.github/workflows/test.yml +16 -0
  6. package/.prettierrc +3 -0
  7. package/.releaserc.js +18 -0
  8. package/.storybook/addons.js +2 -0
  9. package/.storybook/config.js +16 -0
  10. package/LICENSE +21 -0
  11. package/README.md +101 -0
  12. package/package.json +93 -0
  13. package/public/favicon.ico +0 -0
  14. package/public/index.html +38 -0
  15. package/src/Annotator/bike-pic.png +0 -0
  16. package/src/Annotator/bike-pic2.png +0 -0
  17. package/src/Annotator/dab-keyframes.story.json +1 -0
  18. package/src/Annotator/index.js +206 -0
  19. package/src/Annotator/index.story.js +727 -0
  20. package/src/Annotator/poses.story.js +150 -0
  21. package/src/Annotator/reducers/combine-reducers.js +7 -0
  22. package/src/Annotator/reducers/convert-expanding-line-to-polygon.js +53 -0
  23. package/src/Annotator/reducers/fix-twisted.js +6 -0
  24. package/src/Annotator/reducers/general-reducer.js +914 -0
  25. package/src/Annotator/reducers/get-active-image.js +21 -0
  26. package/src/Annotator/reducers/get-implied-video-regions.js +115 -0
  27. package/src/Annotator/reducers/history-handler.js +60 -0
  28. package/src/Annotator/reducers/image-reducer.js +23 -0
  29. package/src/Annotator/reducers/video-reducer.js +85 -0
  30. package/src/Annotator/video.story.js +51 -0
  31. package/src/ClassSelectionMenu/index.js +108 -0
  32. package/src/Crosshairs/index.js +64 -0
  33. package/src/DebugSidebarBox/index.js +36 -0
  34. package/src/DemoSite/Editor.js +235 -0
  35. package/src/DemoSite/ErrorBoundaryDialog.js +34 -0
  36. package/src/DemoSite/index.js +41 -0
  37. package/src/DemoSite/index.story.js +10 -0
  38. package/src/DemoSite/simple-segmentation-example.json +572 -0
  39. package/src/FullImageSegmentationAnnotator/hard1.story.jpg +0 -0
  40. package/src/FullImageSegmentationAnnotator/hard2.story.jpg +0 -0
  41. package/src/FullImageSegmentationAnnotator/hard3.story.jpg +0 -0
  42. package/src/FullImageSegmentationAnnotator/index.js +7 -0
  43. package/src/FullImageSegmentationAnnotator/index.story.js +177 -0
  44. package/src/FullImageSegmentationAnnotator/orange.story.png +0 -0
  45. package/src/HighlightBox/index.js +143 -0
  46. package/src/HistorySidebarBox/index.js +78 -0
  47. package/src/ImageCanvas/dancing-man.story.jpg +0 -0
  48. package/src/ImageCanvas/index.js +488 -0
  49. package/src/ImageCanvas/index.story.js +214 -0
  50. package/src/ImageCanvas/mouse_mask.story.png +0 -0
  51. package/src/ImageCanvas/region-tools.js +171 -0
  52. package/src/ImageCanvas/seves_desk.story.jpg +0 -0
  53. package/src/ImageCanvas/styles.js +27 -0
  54. package/src/ImageCanvas/use-mouse.js +168 -0
  55. package/src/ImageCanvas/use-project-box.js +23 -0
  56. package/src/ImageCanvas/use-wasd-mode.js +50 -0
  57. package/src/ImageMask/index.js +127 -0
  58. package/src/ImageMask/load-image.js +32 -0
  59. package/src/ImageSelectorSidebarBox/index.js +54 -0
  60. package/src/KeyframeTimeline/get-time-string.js +25 -0
  61. package/src/KeyframeTimeline/index.js +223 -0
  62. package/src/KeyframesSelectorSidebarBox/index.js +93 -0
  63. package/src/LandingPage/content.md +57 -0
  64. package/src/LandingPage/github-markdown.css +964 -0
  65. package/src/LandingPage/index.js +147 -0
  66. package/src/MainLayout/icon-dictionary.js +79 -0
  67. package/src/MainLayout/index.js +420 -0
  68. package/src/MainLayout/index.story.js +240 -0
  69. package/src/MainLayout/styles.js +26 -0
  70. package/src/MainLayout/types.js +156 -0
  71. package/src/MainLayout/use-implied-video-regions.js +17 -0
  72. package/src/PointDistances/index.js +90 -0
  73. package/src/PreventScrollToParents/index.js +48 -0
  74. package/src/PreventScrollToParents/index.story.js +23 -0
  75. package/src/RegionLabel/index.js +201 -0
  76. package/src/RegionLabel/styles.js +51 -0
  77. package/src/RegionSelectAndTransformBoxes/index.js +234 -0
  78. package/src/RegionSelectorSidebarBox/index.js +216 -0
  79. package/src/RegionSelectorSidebarBox/styles.js +54 -0
  80. package/src/RegionShapes/index.js +236 -0
  81. package/src/RegionTags/index.js +130 -0
  82. package/src/SettingsDialog/index.js +58 -0
  83. package/src/SettingsProvider/index.js +44 -0
  84. package/src/Shortcuts/ShortcutField.js +44 -0
  85. package/src/Shortcuts/index.js +129 -0
  86. package/src/ShortcutsManager/index.js +162 -0
  87. package/src/Sidebar/index.js +117 -0
  88. package/src/SidebarBoxContainer/index.js +93 -0
  89. package/src/SmallToolButton/index.js +57 -0
  90. package/src/TagsSidebarBox/index.js +93 -0
  91. package/src/TaskDescriptionSidebarBox/index.js +43 -0
  92. package/src/Theme/index.js +36 -0
  93. package/src/VideoOrImageCanvasBackground/index.js +170 -0
  94. package/src/colors.js +32 -0
  95. package/src/hooks/use-event-callback.js +11 -0
  96. package/src/hooks/use-exclude-pattern.js +27 -0
  97. package/src/hooks/use-load-image.js +21 -0
  98. package/src/hooks/use-window-size.js +46 -0
  99. package/src/hooks/xpattern.js +1 -0
  100. package/src/hooks/xpattern.png +0 -0
  101. package/src/index.js +18 -0
  102. package/src/lib.js +7 -0
  103. package/src/screenshot.png +0 -0
  104. package/src/site.css +5 -0
  105. package/src/stories.js +2 -0
  106. package/src/utils/get-from-local-storage.js +7 -0
  107. package/src/utils/get-hotkey-help-text.js +11 -0
  108. package/src/utils/get-landmarks-with-transform.js +23 -0
  109. package/src/utils/set-in-local-storage.js +6 -0
@@ -0,0 +1,488 @@
1
+ // @flow weak
2
+
3
+ import React, {
4
+ useRef,
5
+ useState,
6
+ useLayoutEffect,
7
+ useEffect,
8
+ useMemo,
9
+ } from "react"
10
+ import type { Node } from "react"
11
+ import { Matrix } from "transformation-matrix-js"
12
+ import Crosshairs from "../Crosshairs"
13
+ import type {
14
+ Region,
15
+ Point,
16
+ Polygon,
17
+ Box,
18
+ Keypoints,
19
+ KeypointsDefinition,
20
+ } from "./region-tools.js"
21
+ import { makeStyles } from "@mui/styles"
22
+ import { createTheme, ThemeProvider } from "@mui/material/styles"
23
+ import styles from "./styles"
24
+ import PreventScrollToParents from "../PreventScrollToParents"
25
+ import useWindowSize from "../hooks/use-window-size.js"
26
+ import useMouse from "./use-mouse"
27
+ import useProjectRegionBox from "./use-project-box"
28
+ import useExcludePattern from "../hooks/use-exclude-pattern"
29
+ import { useRafState } from "react-use"
30
+ import PointDistances from "../PointDistances"
31
+ import RegionTags from "../RegionTags"
32
+ import RegionLabel from "../RegionLabel"
33
+ import ImageMask from "../ImageMask"
34
+ import RegionSelectAndTransformBoxes from "../RegionSelectAndTransformBoxes"
35
+ import VideoOrImageCanvasBackground from "../VideoOrImageCanvasBackground"
36
+ import useEventCallback from "use-event-callback"
37
+ import RegionShapes from "../RegionShapes"
38
+ import useWasdMode from "./use-wasd-mode"
39
+
40
+ const theme = createTheme()
41
+ const useStyles = makeStyles((theme) => styles)
42
+
43
+ type Props = {
44
+ regions: Array<Region>,
45
+ imageSrc?: string,
46
+ videoSrc?: string,
47
+ videoTime?: number,
48
+ keypointDefinitions?: KeypointDefinitions,
49
+ onMouseMove?: ({ x: number, y: number }) => any,
50
+ onMouseDown?: ({ x: number, y: number }) => any,
51
+ onMouseUp?: ({ x: number, y: number }) => any,
52
+ dragWithPrimary?: boolean,
53
+ zoomWithPrimary?: boolean,
54
+ createWithPrimary?: boolean,
55
+ showTags?: boolean,
56
+ realSize?: { width: number, height: number, unitName: string },
57
+ showCrosshairs?: boolean,
58
+ showMask?: boolean,
59
+ showHighlightBox?: boolean,
60
+ showPointDistances?: boolean,
61
+ pointDistancePrecision?: number,
62
+ regionClsList?: Array<string>,
63
+ regionTagList?: Array<string>,
64
+ allowedArea?: { x: number, y: number, w: number, h: number },
65
+ RegionEditLabel?: Node,
66
+ videoPlaying?: boolean,
67
+ zoomOnAllowedArea?: boolean,
68
+ fullImageSegmentationMode?: boolean,
69
+ autoSegmentationOptions?: Object,
70
+ modifyingAllowedArea?: boolean,
71
+ allowComments?: Boolean,
72
+ onChangeRegion: (Region) => any,
73
+ onBeginRegionEdit: (Region) => any,
74
+ onCloseRegionEdit: (Region) => any,
75
+ onDeleteRegion: (Region) => any,
76
+ onBeginBoxTransform: (Box, [number, number]) => any,
77
+ onBeginMovePolygonPoint: (Polygon, index: number) => any,
78
+ onBeginMoveKeypoint: (Keypoints, index: number) => any,
79
+ onAddPolygonPoint: (Polygon, point: [number, number], index: number) => any,
80
+ onSelectRegion: (Region) => any,
81
+ onBeginMovePoint: (Point) => any,
82
+ onImageOrVideoLoaded: ({
83
+ naturalWidth: number,
84
+ naturalHeight: number,
85
+ duration?: number,
86
+ }) => any,
87
+ onChangeVideoTime: (number) => any,
88
+ onRegionClassAdded: () => {},
89
+ onChangeVideoPlaying?: Function,
90
+ }
91
+
92
+ const getDefaultMat = (allowedArea = null, { iw, ih } = {}) => {
93
+ let mat = Matrix.from(1, 0, 0, 1, -10, -10)
94
+ if (allowedArea && iw) {
95
+ mat = mat
96
+ .translate(allowedArea.x * iw, allowedArea.y * ih)
97
+ .scaleU(allowedArea.w + 0.05)
98
+ }
99
+ return mat
100
+ }
101
+
102
+ export const ImageCanvas = ({
103
+ regions,
104
+ imageSrc,
105
+ videoSrc,
106
+ videoTime,
107
+ realSize,
108
+ showTags,
109
+ onMouseMove = (p) => null,
110
+ onMouseDown = (p) => null,
111
+ onMouseUp = (p) => null,
112
+ dragWithPrimary = false,
113
+ zoomWithPrimary = false,
114
+ createWithPrimary = false,
115
+ pointDistancePrecision = 0,
116
+ regionClsList,
117
+ regionTagList,
118
+ showCrosshairs,
119
+ showHighlightBox = true,
120
+ showPointDistances,
121
+ allowedArea,
122
+ RegionEditLabel = null,
123
+ videoPlaying = false,
124
+ showMask = true,
125
+ fullImageSegmentationMode,
126
+ autoSegmentationOptions,
127
+ onImageOrVideoLoaded,
128
+ onChangeRegion,
129
+ onBeginRegionEdit,
130
+ onCloseRegionEdit,
131
+ onBeginBoxTransform,
132
+ onBeginMovePolygonPoint,
133
+ onAddPolygonPoint,
134
+ onBeginMoveKeypoint,
135
+ onSelectRegion,
136
+ onBeginMovePoint,
137
+ onDeleteRegion,
138
+ onChangeVideoTime,
139
+ onChangeVideoPlaying,
140
+ onRegionClassAdded,
141
+ zoomOnAllowedArea = true,
142
+ modifyingAllowedArea = false,
143
+ keypointDefinitions,
144
+ allowComments,
145
+ }: Props) => {
146
+ const classes = useStyles()
147
+
148
+ const canvasEl = useRef(null)
149
+ const layoutParams = useRef({})
150
+ const [dragging, changeDragging] = useRafState(false)
151
+ const [maskImagesLoaded, changeMaskImagesLoaded] = useRafState(0)
152
+ const [zoomStart, changeZoomStart] = useRafState(null)
153
+ const [zoomEnd, changeZoomEnd] = useRafState(null)
154
+ const [mat, changeMat] = useRafState(getDefaultMat())
155
+ const maskImages = useRef({})
156
+ const windowSize = useWindowSize()
157
+
158
+ const getLatestMat = useEventCallback(() => mat)
159
+ useWasdMode({ getLatestMat, changeMat })
160
+
161
+ const { mouseEvents, mousePosition } = useMouse({
162
+ canvasEl,
163
+ dragging,
164
+ mat,
165
+ layoutParams,
166
+ changeMat,
167
+ zoomStart,
168
+ zoomEnd,
169
+ changeZoomStart,
170
+ changeZoomEnd,
171
+ changeDragging,
172
+ zoomWithPrimary,
173
+ dragWithPrimary,
174
+ onMouseMove,
175
+ onMouseDown,
176
+ onMouseUp,
177
+ })
178
+
179
+ useLayoutEffect(() => changeMat(mat.clone()), [windowSize])
180
+
181
+ const innerMousePos = mat.applyToPoint(
182
+ mousePosition.current.x,
183
+ mousePosition.current.y
184
+ )
185
+
186
+ const projectRegionBox = useProjectRegionBox({ layoutParams, mat })
187
+
188
+ const [imageDimensions, changeImageDimensions] = useState()
189
+ const imageLoaded = Boolean(imageDimensions && imageDimensions.naturalWidth)
190
+
191
+ const onVideoOrImageLoaded = useEventCallback(
192
+ ({ naturalWidth, naturalHeight, duration }) => {
193
+ const dims = { naturalWidth, naturalHeight, duration }
194
+ if (onImageOrVideoLoaded) onImageOrVideoLoaded(dims)
195
+ changeImageDimensions(dims)
196
+ // Redundant update to fix rerendering issues
197
+ setTimeout(() => changeImageDimensions(dims), 10)
198
+ }
199
+ )
200
+
201
+ const excludePattern = useExcludePattern()
202
+
203
+ const canvas = canvasEl.current
204
+ if (canvas && imageLoaded) {
205
+ const { clientWidth, clientHeight } = canvas
206
+
207
+ const fitScale = Math.max(
208
+ imageDimensions.naturalWidth / (clientWidth - 20),
209
+ imageDimensions.naturalHeight / (clientHeight - 20)
210
+ )
211
+
212
+ const [iw, ih] = [
213
+ imageDimensions.naturalWidth / fitScale,
214
+ imageDimensions.naturalHeight / fitScale,
215
+ ]
216
+
217
+ layoutParams.current = {
218
+ iw,
219
+ ih,
220
+ fitScale,
221
+ canvasWidth: clientWidth,
222
+ canvasHeight: clientHeight,
223
+ }
224
+ }
225
+
226
+ useEffect(() => {
227
+ if (!imageLoaded) return
228
+ changeMat(
229
+ getDefaultMat(
230
+ zoomOnAllowedArea ? allowedArea : null,
231
+ layoutParams.current
232
+ )
233
+ )
234
+ // eslint-disable-next-line
235
+ }, [imageLoaded])
236
+
237
+ useLayoutEffect(() => {
238
+ if (!imageDimensions) return
239
+ const { clientWidth, clientHeight } = canvas
240
+ canvas.width = clientWidth
241
+ canvas.height = clientHeight
242
+ const context = canvas.getContext("2d")
243
+
244
+ context.save()
245
+ context.transform(...mat.clone().inverse().toArray())
246
+
247
+ const { iw, ih } = layoutParams.current
248
+
249
+ if (allowedArea) {
250
+ // Pattern to indicate the NOT allowed areas
251
+ const { x, y, w, h } = allowedArea
252
+ context.save()
253
+ context.globalAlpha = 1
254
+ const outer = [
255
+ [0, 0],
256
+ [iw, 0],
257
+ [iw, ih],
258
+ [0, ih],
259
+ ]
260
+ const inner = [
261
+ [x * iw, y * ih],
262
+ [x * iw + w * iw, y * ih],
263
+ [x * iw + w * iw, y * ih + h * ih],
264
+ [x * iw, y * ih + h * ih],
265
+ ]
266
+ context.moveTo(...outer[0])
267
+ outer.forEach((p) => context.lineTo(...p))
268
+ context.lineTo(...outer[0])
269
+ context.closePath()
270
+
271
+ inner.reverse()
272
+ context.moveTo(...inner[0])
273
+ inner.forEach((p) => context.lineTo(...p))
274
+ context.lineTo(...inner[0])
275
+
276
+ context.fillStyle = excludePattern || "#f00"
277
+ context.fill()
278
+
279
+ context.restore()
280
+ }
281
+
282
+ context.restore()
283
+ })
284
+
285
+ const { iw, ih } = layoutParams.current
286
+
287
+ let zoomBox =
288
+ !zoomStart || !zoomEnd
289
+ ? null
290
+ : {
291
+ ...mat.clone().inverse().applyToPoint(zoomStart.x, zoomStart.y),
292
+ w: (zoomEnd.x - zoomStart.x) / mat.a,
293
+ h: (zoomEnd.y - zoomStart.y) / mat.d,
294
+ }
295
+ if (zoomBox) {
296
+ if (zoomBox.w < 0) {
297
+ zoomBox.x += zoomBox.w
298
+ zoomBox.w *= -1
299
+ }
300
+ if (zoomBox.h < 0) {
301
+ zoomBox.y += zoomBox.h
302
+ zoomBox.h *= -1
303
+ }
304
+ }
305
+
306
+ const imagePosition = {
307
+ topLeft: mat.clone().inverse().applyToPoint(0, 0),
308
+ bottomRight: mat.clone().inverse().applyToPoint(iw, ih),
309
+ }
310
+
311
+ const highlightedRegion = useMemo(() => {
312
+ const highlightedRegions = regions.filter((r) => r.highlighted)
313
+ if (highlightedRegions.length !== 1) return null
314
+ return highlightedRegions[0]
315
+ }, [regions])
316
+
317
+ return (
318
+ <ThemeProvider theme={theme}>
319
+ <div
320
+ style={{
321
+ width: "100%",
322
+ height: "100%",
323
+ maxHeight: "calc(100vh - 68px)",
324
+ position: "relative",
325
+ overflow: "hidden",
326
+ cursor: createWithPrimary
327
+ ? "crosshair"
328
+ : dragging
329
+ ? "grabbing"
330
+ : dragWithPrimary
331
+ ? "grab"
332
+ : zoomWithPrimary
333
+ ? mat.a < 1
334
+ ? "zoom-out"
335
+ : "zoom-in"
336
+ : undefined,
337
+ }}
338
+ >
339
+ {showCrosshairs && (
340
+ <Crosshairs key="crossHairs" mousePosition={mousePosition} />
341
+ )}
342
+ {imageLoaded && !dragging && (
343
+ <RegionSelectAndTransformBoxes
344
+ key="regionSelectAndTransformBoxes"
345
+ regions={
346
+ !modifyingAllowedArea || !allowedArea
347
+ ? regions
348
+ : [
349
+ {
350
+ type: "box",
351
+ id: "$$allowed_area",
352
+ cls: "allowed_area",
353
+ highlighted: true,
354
+ x: allowedArea.x,
355
+ y: allowedArea.y,
356
+ w: allowedArea.w,
357
+ h: allowedArea.h,
358
+ visible: true,
359
+ color: "#ff0",
360
+ },
361
+ ]
362
+ }
363
+ mouseEvents={mouseEvents}
364
+ projectRegionBox={projectRegionBox}
365
+ dragWithPrimary={dragWithPrimary}
366
+ createWithPrimary={createWithPrimary}
367
+ zoomWithPrimary={zoomWithPrimary}
368
+ onBeginMovePoint={onBeginMovePoint}
369
+ onSelectRegion={onSelectRegion}
370
+ layoutParams={layoutParams}
371
+ mat={mat}
372
+ onBeginBoxTransform={onBeginBoxTransform}
373
+ onBeginMovePolygonPoint={onBeginMovePolygonPoint}
374
+ onBeginMoveKeypoint={onBeginMoveKeypoint}
375
+ onAddPolygonPoint={onAddPolygonPoint}
376
+ showHighlightBox={showHighlightBox}
377
+ />
378
+ )}
379
+ {imageLoaded && showTags && !dragging && (
380
+ <PreventScrollToParents key="regionTags">
381
+ <RegionTags
382
+ regions={regions}
383
+ projectRegionBox={projectRegionBox}
384
+ mouseEvents={mouseEvents}
385
+ regionClsList={regionClsList}
386
+ regionTagList={regionTagList}
387
+ onBeginRegionEdit={onBeginRegionEdit}
388
+ onChangeRegion={onChangeRegion}
389
+ onCloseRegionEdit={onCloseRegionEdit}
390
+ onDeleteRegion={onDeleteRegion}
391
+ layoutParams={layoutParams}
392
+ imageSrc={imageSrc}
393
+ RegionEditLabel={RegionEditLabel}
394
+ onRegionClassAdded={onRegionClassAdded}
395
+ allowComments={allowComments}
396
+ />
397
+ </PreventScrollToParents>
398
+ )}
399
+ {!showTags && highlightedRegion && (
400
+ <div key="topLeftTag" className={classes.fixedRegionLabel}>
401
+ <RegionLabel
402
+ disableClose
403
+ allowedClasses={regionClsList}
404
+ allowedTags={regionTagList}
405
+ onChange={onChangeRegion}
406
+ onDelete={onDeleteRegion}
407
+ editing
408
+ region={highlightedRegion}
409
+ imageSrc={imageSrc}
410
+ allowComments={allowComments}
411
+ />
412
+ </div>
413
+ )}
414
+
415
+ {zoomWithPrimary && zoomBox !== null && (
416
+ <div
417
+ key="zoomBox"
418
+ style={{
419
+ position: "absolute",
420
+ zIndex: 1,
421
+ border: "1px solid #fff",
422
+ pointerEvents: "none",
423
+ left: zoomBox.x,
424
+ top: zoomBox.y,
425
+ width: zoomBox.w,
426
+ height: zoomBox.h,
427
+ }}
428
+ />
429
+ )}
430
+ {showPointDistances && (
431
+ <PointDistances
432
+ key="pointDistances"
433
+ regions={regions}
434
+ realSize={realSize}
435
+ projectRegionBox={projectRegionBox}
436
+ pointDistancePrecision={pointDistancePrecision}
437
+ />
438
+ )}
439
+ <PreventScrollToParents
440
+ style={{ width: "100%", height: "100%" }}
441
+ {...mouseEvents}
442
+ >
443
+ <>
444
+ {fullImageSegmentationMode && (
445
+ <ImageMask
446
+ hide={!showMask}
447
+ autoSegmentationOptions={autoSegmentationOptions}
448
+ imagePosition={imagePosition}
449
+ regionClsList={regionClsList}
450
+ imageSrc={imageSrc}
451
+ regions={regions}
452
+ />
453
+ )}
454
+ <canvas
455
+ style={{ opacity: 0.25 }}
456
+ className={classes.canvas}
457
+ ref={canvasEl}
458
+ />
459
+ <RegionShapes
460
+ mat={mat}
461
+ keypointDefinitions={keypointDefinitions}
462
+ imagePosition={imagePosition}
463
+ regions={regions}
464
+ fullSegmentationMode={fullImageSegmentationMode}
465
+ />
466
+ <VideoOrImageCanvasBackground
467
+ videoPlaying={videoPlaying}
468
+ imagePosition={imagePosition}
469
+ mouseEvents={mouseEvents}
470
+ onLoad={onVideoOrImageLoaded}
471
+ videoTime={videoTime}
472
+ videoSrc={videoSrc}
473
+ imageSrc={imageSrc}
474
+ useCrossOrigin={fullImageSegmentationMode}
475
+ onChangeVideoTime={onChangeVideoTime}
476
+ onChangeVideoPlaying={onChangeVideoPlaying}
477
+ />
478
+ </>
479
+ </PreventScrollToParents>
480
+ <div className={classes.zoomIndicator}>
481
+ {((1 / mat.a) * 100).toFixed(0)}%
482
+ </div>
483
+ </div>
484
+ </ThemeProvider>
485
+ )
486
+ }
487
+
488
+ export default ImageCanvas
@@ -0,0 +1,214 @@
1
+ import React from "react"
2
+
3
+ import { storiesOf } from "@storybook/react"
4
+ import { action } from "@storybook/addon-actions"
5
+
6
+ import ImageCanvas from "./"
7
+ import exampleMask from "./mouse_mask.story.png"
8
+ import exampleImage from "./seves_desk.story.jpg"
9
+ import dancingManImage from "./dancing-man.story.jpg"
10
+
11
+ export const testRegions = [
12
+ {
13
+ type: "point",
14
+ id: "point1",
15
+ cls: "Paper",
16
+ highlighted: true,
17
+ x: 0.8,
18
+ y: 0.5,
19
+ visible: true,
20
+ color: "#f00",
21
+ },
22
+ {
23
+ type: "point",
24
+ id: "point2",
25
+ cls: "Dude's Head",
26
+ tags: ["human", "head", "male"],
27
+ x: 0.1,
28
+ y: 0.15,
29
+ visible: true,
30
+ color: "#0F0",
31
+ },
32
+ {
33
+ type: "box",
34
+ id: "box1",
35
+ cls: "Business Card",
36
+ highlighted: true,
37
+ x: 0.315,
38
+ y: 0.63,
39
+ w: 0.067,
40
+ h: 0.045,
41
+ visible: true,
42
+ color: "#ff0",
43
+ },
44
+ {
45
+ type: "polygon",
46
+ id: "polygon1",
47
+ cls: "Laptop",
48
+ tags: ["Electronic Device"],
49
+ editingLabels: true,
50
+ highlighted: true,
51
+ points: [
52
+ [0.4019, 0.5065],
53
+ [0.407, 0.5895],
54
+ [0.4157, 0.6801],
55
+ [0.6579, 0.656],
56
+ [0.6115, 0.5674],
57
+ [0.5792, 0.4895],
58
+ ],
59
+ visible: true,
60
+ color: "#f0f",
61
+ },
62
+ {
63
+ type: "polygon",
64
+ id: "polygon2",
65
+ open: true,
66
+ points: [
67
+ [0.1201, 0.5987],
68
+ [0.0674, 0.7063],
69
+ [0.0726, 0.7477],
70
+ [0.2132, 0.7311],
71
+ ],
72
+ visible: true,
73
+ color: "#00f",
74
+ },
75
+ {
76
+ type: "pixel",
77
+ id: "pixel1",
78
+ cls: "Mouse",
79
+ tags: ["Electronic Device"],
80
+ sx: 0.7433,
81
+ sy: 0.5847,
82
+ w: 0.83 - 0.7433,
83
+ h: 0.67 - 0.5847,
84
+ src: exampleMask,
85
+ visible: true,
86
+ color: "#00f",
87
+ },
88
+ ]
89
+
90
+ const events = {
91
+ // Ignore common mouse movements, they fill the action log
92
+ onMouseMove: () => null, //action("onMouseMove"),
93
+ onMouseDown: () => null, //action("onMouseDown"),
94
+ onMouseUp: () => null, //action("onMouseUp"),
95
+
96
+ onChangeRegion: action("onChangeRegion"),
97
+ onBeginRegionEdit: action("onBeginRegionEdit"),
98
+ onCloseRegionEdit: action("onCloseRegionEdit"),
99
+
100
+ onSelectRegion: action("onSelectRegion"),
101
+
102
+ onBeginBoxTransform: action("onBeginBoxTransform"),
103
+
104
+ onBeginMovePolygonPoint: action("onBeginMovePolygonPoint"),
105
+ onAddPolygonPoint: action("onAddPolygonPoint"),
106
+ onClosePolygon: action("onClosePolygon"),
107
+
108
+ onBeginMoveKeypoint: action("onBeginMoveKeypoint"),
109
+
110
+ onBeginMovePoint: action("onBeginMovePoint"),
111
+ onDeleteRegion: action("onDeleteRegion"),
112
+ }
113
+
114
+ storiesOf("ImageCanvas", module)
115
+ .add("Basic", () => (
116
+ <ImageCanvas
117
+ regions={testRegions}
118
+ imageSrc={exampleImage}
119
+ showTags
120
+ {...events}
121
+ />
122
+ ))
123
+ .add("Zoom Tool Selected", () => (
124
+ <ImageCanvas
125
+ showTags
126
+ regions={testRegions}
127
+ imageSrc={exampleImage}
128
+ zoomWithPrimary
129
+ {...events}
130
+ />
131
+ ))
132
+ .add("Allowed Area", () => (
133
+ <ImageCanvas
134
+ showTags
135
+ regions={[]}
136
+ imageSrc={exampleImage}
137
+ zoomWithPrimary
138
+ allowedArea={{ x: 0.25, y: 0.25, w: 0.5, h: 0.5 }}
139
+ {...events}
140
+ />
141
+ ))
142
+ .add("Allowed Area (2)", () => (
143
+ <ImageCanvas
144
+ showTags
145
+ regions={[]}
146
+ imageSrc={exampleImage}
147
+ zoomWithPrimary
148
+ allowedArea={{ x: 0.6, y: 0.6, w: 0.2, h: 0.2 }}
149
+ {...events}
150
+ />
151
+ ))
152
+ .add("Modify Allowed Area", () => (
153
+ <ImageCanvas
154
+ showTags
155
+ regions={[]}
156
+ imageSrc={exampleImage}
157
+ modifyingAllowedArea
158
+ allowedArea={{ x: 0.6, y: 0.6, w: 0.2, h: 0.2 }}
159
+ {...events}
160
+ />
161
+ ))
162
+ .add("Poses", () => (
163
+ <ImageCanvas
164
+ keypointDefinitions={{
165
+ human: {
166
+ connections: [
167
+ ["head", "sternum"],
168
+ ["sternum", "leftElbow"],
169
+ ["sternum", "rightElbow"],
170
+ ],
171
+ landmarks: {
172
+ head: {
173
+ label: "Head",
174
+ color: "#f00",
175
+ defaultPosition: [0, -0.05],
176
+ },
177
+ sternum: {
178
+ label: "Torso",
179
+ color: "#0f0",
180
+ defaultPosition: [0, 0],
181
+ },
182
+ leftElbow: {
183
+ label: "Left Elbow",
184
+ color: "#00f",
185
+ defaultPosition: [-0.05, 0],
186
+ },
187
+ rightElbow: {
188
+ label: "Right Elbow",
189
+ color: "#00f",
190
+ defaultPosition: [0.05, 0],
191
+ },
192
+ },
193
+ },
194
+ }}
195
+ regions={[
196
+ {
197
+ type: "keypoints",
198
+ id: "keypoints1",
199
+ keypointsDefinitionId: "human",
200
+ highlighted: true,
201
+ points: {
202
+ head: { x: 0.54, y: 0.2 },
203
+ sternum: { x: 0.57, y: 0.3 },
204
+ leftElbow: { x: 0.4, y: 0.39 },
205
+ rightElbow: { x: 0.7, y: 0.32 },
206
+ },
207
+ visible: true,
208
+ },
209
+ ]}
210
+ imageSrc={dancingManImage}
211
+ showTags
212
+ {...events}
213
+ />
214
+ ))