@searpent/react-image-annotate 2.0.0 → 2.0.3

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 (174) hide show
  1. package/Annotator/index.js +169 -0
  2. package/Annotator/reducers/combine-reducers.js +14 -0
  3. package/Annotator/reducers/convert-expanding-line-to-polygon.js +73 -0
  4. package/{src/Annotator → Annotator}/reducers/fix-twisted.js +3 -5
  5. package/Annotator/reducers/general-reducer.js +1058 -0
  6. package/Annotator/reducers/get-active-image.js +27 -0
  7. package/Annotator/reducers/get-implied-video-regions.js +180 -0
  8. package/Annotator/reducers/history-handler.js +38 -0
  9. package/Annotator/reducers/image-reducer.js +20 -0
  10. package/Annotator/reducers/video-reducer.js +88 -0
  11. package/ClassSelectionMenu/index.js +135 -0
  12. package/Crosshairs/index.js +53 -0
  13. package/DebugSidebarBox/index.js +20 -0
  14. package/DemoSite/Editor.js +194 -0
  15. package/DemoSite/ErrorBoundaryDialog.js +64 -0
  16. package/DemoSite/index.js +40 -0
  17. package/FullImageSegmentationAnnotator/index.js +7 -0
  18. package/GroupSelectorSidebarBox/index.js +63 -0
  19. package/HighlightBox/index.js +99 -0
  20. package/HistorySidebarBox/index.js +71 -0
  21. package/ImageCanvas/index.js +424 -0
  22. package/ImageCanvas/region-tools.js +165 -0
  23. package/{src/ImageCanvas → ImageCanvas}/styles.js +12 -8
  24. package/ImageCanvas/use-mouse.js +180 -0
  25. package/ImageCanvas/use-project-box.js +27 -0
  26. package/ImageCanvas/use-wasd-mode.js +62 -0
  27. package/ImageMask/index.js +133 -0
  28. package/ImageMask/load-image.js +25 -0
  29. package/ImageSelectorSidebarBox/index.js +60 -0
  30. package/KeyframeTimeline/get-time-string.js +27 -0
  31. package/KeyframeTimeline/index.js +233 -0
  32. package/KeyframesSelectorSidebarBox/index.js +93 -0
  33. package/LandingPage/index.js +159 -0
  34. package/MainLayout/icon-dictionary.js +104 -0
  35. package/MainLayout/index.js +366 -0
  36. package/{src/MainLayout → MainLayout}/styles.js +6 -7
  37. package/MainLayout/types.js +0 -0
  38. package/MainLayout/use-implied-video-regions.js +13 -0
  39. package/PointDistances/index.js +73 -0
  40. package/PreventScrollToParents/index.js +51 -0
  41. package/RegionLabel/index.js +191 -0
  42. package/{src/RegionLabel → RegionLabel}/styles.js +12 -15
  43. package/RegionSelectAndTransformBoxes/index.js +167 -0
  44. package/RegionSelectorSidebarBox/index.js +248 -0
  45. package/{src/RegionSelectorSidebarBox → RegionSelectorSidebarBox}/styles.js +13 -14
  46. package/RegionShapes/index.js +274 -0
  47. package/RegionTags/index.js +138 -0
  48. package/SettingsDialog/index.js +52 -0
  49. package/SettingsProvider/index.js +53 -0
  50. package/Shortcuts/ShortcutField.js +46 -0
  51. package/Shortcuts/index.js +133 -0
  52. package/ShortcutsManager/index.js +155 -0
  53. package/Sidebar/index.js +69 -0
  54. package/SidebarBoxContainer/index.js +93 -0
  55. package/SmallToolButton/index.js +42 -0
  56. package/TagsSidebarBox/index.js +105 -0
  57. package/TaskDescriptionSidebarBox/index.js +58 -0
  58. package/Theme/index.js +30 -0
  59. package/VideoOrImageCanvasBackground/index.js +151 -0
  60. package/colors.js +14 -0
  61. package/hooks/use-event-callback.js +10 -0
  62. package/hooks/use-exclude-pattern.js +24 -0
  63. package/hooks/use-load-image.js +26 -0
  64. package/hooks/use-window-size.js +46 -0
  65. package/{src/hooks → hooks}/xpattern.js +1 -1
  66. package/index.js +3 -0
  67. package/lib.js +3 -0
  68. package/package.json +1 -1
  69. package/stories.js +5 -0
  70. package/utils/get-from-local-storage.js +7 -0
  71. package/utils/get-hotkey-help-text.js +9 -0
  72. package/utils/get-landmarks-with-transform.js +40 -0
  73. package/utils/set-in-local-storage.js +3 -0
  74. package/.babelrc +0 -6
  75. package/.env +0 -1
  76. package/.flowconfig +0 -2
  77. package/.github/workflows/release-on-master.yml +0 -32
  78. package/.github/workflows/test.yml +0 -16
  79. package/.prettierrc +0 -3
  80. package/.releaserc.js +0 -18
  81. package/.storybook/addons.js +0 -2
  82. package/.storybook/config.js +0 -16
  83. package/LICENSE +0 -21
  84. package/public/favicon.ico +0 -0
  85. package/public/index.html +0 -38
  86. package/src/Annotator/bike-pic.png +0 -0
  87. package/src/Annotator/bike-pic2.png +0 -0
  88. package/src/Annotator/dab-keyframes.story.json +0 -1
  89. package/src/Annotator/index.js +0 -206
  90. package/src/Annotator/index.story.js +0 -727
  91. package/src/Annotator/poses.story.js +0 -150
  92. package/src/Annotator/reducers/combine-reducers.js +0 -7
  93. package/src/Annotator/reducers/convert-expanding-line-to-polygon.js +0 -53
  94. package/src/Annotator/reducers/general-reducer.js +0 -914
  95. package/src/Annotator/reducers/get-active-image.js +0 -21
  96. package/src/Annotator/reducers/get-implied-video-regions.js +0 -115
  97. package/src/Annotator/reducers/history-handler.js +0 -60
  98. package/src/Annotator/reducers/image-reducer.js +0 -23
  99. package/src/Annotator/reducers/video-reducer.js +0 -85
  100. package/src/Annotator/video.story.js +0 -51
  101. package/src/ClassSelectionMenu/index.js +0 -108
  102. package/src/Crosshairs/index.js +0 -64
  103. package/src/DebugSidebarBox/index.js +0 -36
  104. package/src/DemoSite/Editor.js +0 -235
  105. package/src/DemoSite/ErrorBoundaryDialog.js +0 -34
  106. package/src/DemoSite/index.js +0 -41
  107. package/src/DemoSite/index.story.js +0 -10
  108. package/src/DemoSite/simple-segmentation-example.json +0 -572
  109. package/src/FullImageSegmentationAnnotator/hard1.story.jpg +0 -0
  110. package/src/FullImageSegmentationAnnotator/hard2.story.jpg +0 -0
  111. package/src/FullImageSegmentationAnnotator/hard3.story.jpg +0 -0
  112. package/src/FullImageSegmentationAnnotator/index.js +0 -7
  113. package/src/FullImageSegmentationAnnotator/index.story.js +0 -177
  114. package/src/FullImageSegmentationAnnotator/orange.story.png +0 -0
  115. package/src/HighlightBox/index.js +0 -143
  116. package/src/HistorySidebarBox/index.js +0 -78
  117. package/src/ImageCanvas/dancing-man.story.jpg +0 -0
  118. package/src/ImageCanvas/index.js +0 -488
  119. package/src/ImageCanvas/index.story.js +0 -214
  120. package/src/ImageCanvas/mouse_mask.story.png +0 -0
  121. package/src/ImageCanvas/region-tools.js +0 -171
  122. package/src/ImageCanvas/seves_desk.story.jpg +0 -0
  123. package/src/ImageCanvas/use-mouse.js +0 -168
  124. package/src/ImageCanvas/use-project-box.js +0 -23
  125. package/src/ImageCanvas/use-wasd-mode.js +0 -50
  126. package/src/ImageMask/index.js +0 -127
  127. package/src/ImageMask/load-image.js +0 -32
  128. package/src/ImageSelectorSidebarBox/index.js +0 -54
  129. package/src/KeyframeTimeline/get-time-string.js +0 -25
  130. package/src/KeyframeTimeline/index.js +0 -223
  131. package/src/KeyframesSelectorSidebarBox/index.js +0 -93
  132. package/src/LandingPage/content.md +0 -57
  133. package/src/LandingPage/github-markdown.css +0 -964
  134. package/src/LandingPage/index.js +0 -147
  135. package/src/MainLayout/icon-dictionary.js +0 -79
  136. package/src/MainLayout/index.js +0 -420
  137. package/src/MainLayout/index.story.js +0 -240
  138. package/src/MainLayout/types.js +0 -156
  139. package/src/MainLayout/use-implied-video-regions.js +0 -17
  140. package/src/PointDistances/index.js +0 -90
  141. package/src/PreventScrollToParents/index.js +0 -48
  142. package/src/PreventScrollToParents/index.story.js +0 -23
  143. package/src/RegionLabel/index.js +0 -201
  144. package/src/RegionSelectAndTransformBoxes/index.js +0 -234
  145. package/src/RegionSelectorSidebarBox/index.js +0 -216
  146. package/src/RegionShapes/index.js +0 -236
  147. package/src/RegionTags/index.js +0 -130
  148. package/src/SettingsDialog/index.js +0 -58
  149. package/src/SettingsProvider/index.js +0 -44
  150. package/src/Shortcuts/ShortcutField.js +0 -44
  151. package/src/Shortcuts/index.js +0 -129
  152. package/src/ShortcutsManager/index.js +0 -162
  153. package/src/Sidebar/index.js +0 -117
  154. package/src/SidebarBoxContainer/index.js +0 -93
  155. package/src/SmallToolButton/index.js +0 -57
  156. package/src/TagsSidebarBox/index.js +0 -93
  157. package/src/TaskDescriptionSidebarBox/index.js +0 -43
  158. package/src/Theme/index.js +0 -36
  159. package/src/VideoOrImageCanvasBackground/index.js +0 -170
  160. package/src/colors.js +0 -32
  161. package/src/hooks/use-event-callback.js +0 -11
  162. package/src/hooks/use-exclude-pattern.js +0 -27
  163. package/src/hooks/use-load-image.js +0 -21
  164. package/src/hooks/use-window-size.js +0 -46
  165. package/src/hooks/xpattern.png +0 -0
  166. package/src/index.js +0 -18
  167. package/src/lib.js +0 -7
  168. package/src/screenshot.png +0 -0
  169. package/src/site.css +0 -5
  170. package/src/stories.js +0 -2
  171. package/src/utils/get-from-local-storage.js +0 -7
  172. package/src/utils/get-hotkey-help-text.js +0 -11
  173. package/src/utils/get-landmarks-with-transform.js +0 -23
  174. package/src/utils/set-in-local-storage.js +0 -6
@@ -1,488 +0,0 @@
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
@@ -1,214 +0,0 @@
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
- ))