react-image-annotate-master-custom 0.0.1

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 (73) hide show
  1. package/Annotator/index.js +164 -0
  2. package/Annotator/reducers/combine-reducers.js +14 -0
  3. package/Annotator/reducers/convert-expanding-line-to-polygon.js +73 -0
  4. package/Annotator/reducers/fix-twisted.js +4 -0
  5. package/Annotator/reducers/general-reducer.js +1073 -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 +69 -0
  17. package/FullImageSegmentationAnnotator/index.js +7 -0
  18. package/HighlightBox/index.js +105 -0
  19. package/HistorySidebarBox/index.js +71 -0
  20. package/ImageCanvas/index.js +428 -0
  21. package/ImageCanvas/region-tools.js +165 -0
  22. package/ImageCanvas/styles.js +31 -0
  23. package/ImageCanvas/use-mouse.js +180 -0
  24. package/ImageCanvas/use-project-box.js +27 -0
  25. package/ImageCanvas/use-wasd-mode.js +62 -0
  26. package/ImageMask/index.js +133 -0
  27. package/ImageMask/load-image.js +25 -0
  28. package/ImageSelectorSidebarBox/index.js +60 -0
  29. package/KeyframeTimeline/get-time-string.js +27 -0
  30. package/KeyframeTimeline/index.js +233 -0
  31. package/KeyframesSelectorSidebarBox/index.js +93 -0
  32. package/LandingPage/index.js +159 -0
  33. package/MainLayout/icon-dictionary.js +104 -0
  34. package/MainLayout/index.js +359 -0
  35. package/MainLayout/styles.js +25 -0
  36. package/MainLayout/types.js +0 -0
  37. package/MainLayout/use-implied-video-regions.js +13 -0
  38. package/PointDistances/index.js +73 -0
  39. package/PreventScrollToParents/index.js +51 -0
  40. package/README.md +101 -0
  41. package/RegionLabel/index.js +197 -0
  42. package/RegionLabel/styles.js +48 -0
  43. package/RegionSelectAndTransformBoxes/index.js +166 -0
  44. package/RegionSelectorSidebarBox/index.js +248 -0
  45. package/RegionSelectorSidebarBox/styles.js +53 -0
  46. package/RegionShapes/index.js +275 -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/hooks/xpattern.js +1 -0
  66. package/index.js +3 -0
  67. package/lib.js +3 -0
  68. package/package.json +91 -0
  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
@@ -0,0 +1,428 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread";
2
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ import React, { useRef, useState, useLayoutEffect, useEffect, useMemo } from "react";
5
+ import { Matrix } from "transformation-matrix-js";
6
+ import Crosshairs from "../Crosshairs";
7
+ import { makeStyles } from "@mui/styles";
8
+ import { createTheme, ThemeProvider } from "@mui/material/styles";
9
+ import styles from "./styles";
10
+ import PreventScrollToParents from "../PreventScrollToParents";
11
+ import useWindowSize from "../hooks/use-window-size.js";
12
+ import useMouse from "./use-mouse";
13
+ import useProjectRegionBox from "./use-project-box";
14
+ import useExcludePattern from "../hooks/use-exclude-pattern";
15
+ import { useRafState } from "react-use";
16
+ import PointDistances from "../PointDistances";
17
+ import RegionTags from "../RegionTags";
18
+ import RegionLabel from "../RegionLabel";
19
+ import ImageMask from "../ImageMask";
20
+ import RegionSelectAndTransformBoxes from "../RegionSelectAndTransformBoxes";
21
+ import VideoOrImageCanvasBackground from "../VideoOrImageCanvasBackground";
22
+ import useEventCallback from "use-event-callback";
23
+ import RegionShapes from "../RegionShapes";
24
+ import useWasdMode from "./use-wasd-mode";
25
+ var theme = createTheme();
26
+ var useStyles = makeStyles(function (theme) {
27
+ return styles;
28
+ });
29
+
30
+ var getDefaultMat = function getDefaultMat() {
31
+ var allowedArea = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
32
+
33
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
34
+ iw = _ref.iw,
35
+ ih = _ref.ih;
36
+
37
+ var mat = Matrix.from(1, 0, 0, 1, -10, -10);
38
+
39
+ if (allowedArea && iw) {
40
+ mat = mat.translate(allowedArea.x * iw, allowedArea.y * ih).scaleU(allowedArea.w + 0.05);
41
+ }
42
+
43
+ return mat;
44
+ };
45
+
46
+ export var ImageCanvas = function ImageCanvas(_ref2) {
47
+ var regions = _ref2.regions,
48
+ imageSrc = _ref2.imageSrc,
49
+ videoSrc = _ref2.videoSrc,
50
+ videoTime = _ref2.videoTime,
51
+ realSize = _ref2.realSize,
52
+ showTags = _ref2.showTags,
53
+ hideRegionLabel = _ref2.hideRegionLabel,
54
+ _ref2$onMouseMove = _ref2.onMouseMove,
55
+ onMouseMove = _ref2$onMouseMove === void 0 ? function (p) {
56
+ return null;
57
+ } : _ref2$onMouseMove,
58
+ _ref2$onMouseDown = _ref2.onMouseDown,
59
+ onMouseDown = _ref2$onMouseDown === void 0 ? function (p) {
60
+ return null;
61
+ } : _ref2$onMouseDown,
62
+ _ref2$onMouseUp = _ref2.onMouseUp,
63
+ onMouseUp = _ref2$onMouseUp === void 0 ? function (p) {
64
+ return null;
65
+ } : _ref2$onMouseUp,
66
+ _ref2$dragWithPrimary = _ref2.dragWithPrimary,
67
+ dragWithPrimary = _ref2$dragWithPrimary === void 0 ? false : _ref2$dragWithPrimary,
68
+ _ref2$zoomWithPrimary = _ref2.zoomWithPrimary,
69
+ zoomWithPrimary = _ref2$zoomWithPrimary === void 0 ? false : _ref2$zoomWithPrimary,
70
+ _ref2$createWithPrima = _ref2.createWithPrimary,
71
+ createWithPrimary = _ref2$createWithPrima === void 0 ? false : _ref2$createWithPrima,
72
+ _ref2$pointDistancePr = _ref2.pointDistancePrecision,
73
+ pointDistancePrecision = _ref2$pointDistancePr === void 0 ? 0 : _ref2$pointDistancePr,
74
+ regionClsList = _ref2.regionClsList,
75
+ regionTagList = _ref2.regionTagList,
76
+ showCrosshairs = _ref2.showCrosshairs,
77
+ _ref2$showHighlightBo = _ref2.showHighlightBox,
78
+ showHighlightBox = _ref2$showHighlightBo === void 0 ? true : _ref2$showHighlightBo,
79
+ showPointDistances = _ref2.showPointDistances,
80
+ allowedArea = _ref2.allowedArea,
81
+ _ref2$RegionEditLabel = _ref2.RegionEditLabel,
82
+ RegionEditLabel = _ref2$RegionEditLabel === void 0 ? null : _ref2$RegionEditLabel,
83
+ _ref2$videoPlaying = _ref2.videoPlaying,
84
+ videoPlaying = _ref2$videoPlaying === void 0 ? false : _ref2$videoPlaying,
85
+ _ref2$showMask = _ref2.showMask,
86
+ showMask = _ref2$showMask === void 0 ? true : _ref2$showMask,
87
+ fullImageSegmentationMode = _ref2.fullImageSegmentationMode,
88
+ autoSegmentationOptions = _ref2.autoSegmentationOptions,
89
+ onImageOrVideoLoaded = _ref2.onImageOrVideoLoaded,
90
+ onChangeRegion = _ref2.onChangeRegion,
91
+ onBeginRegionEdit = _ref2.onBeginRegionEdit,
92
+ onCloseRegionEdit = _ref2.onCloseRegionEdit,
93
+ onBeginBoxTransform = _ref2.onBeginBoxTransform,
94
+ onBeginMovePolygonPoint = _ref2.onBeginMovePolygonPoint,
95
+ onAddPolygonPoint = _ref2.onAddPolygonPoint,
96
+ onBeginMoveKeypoint = _ref2.onBeginMoveKeypoint,
97
+ onSelectRegion = _ref2.onSelectRegion,
98
+ onBeginMovePoint = _ref2.onBeginMovePoint,
99
+ onDeleteRegion = _ref2.onDeleteRegion,
100
+ onChangeVideoTime = _ref2.onChangeVideoTime,
101
+ onChangeVideoPlaying = _ref2.onChangeVideoPlaying,
102
+ onRegionClassAdded = _ref2.onRegionClassAdded,
103
+ _ref2$zoomOnAllowedAr = _ref2.zoomOnAllowedArea,
104
+ zoomOnAllowedArea = _ref2$zoomOnAllowedAr === void 0 ? true : _ref2$zoomOnAllowedAr,
105
+ _ref2$modifyingAllowe = _ref2.modifyingAllowedArea,
106
+ modifyingAllowedArea = _ref2$modifyingAllowe === void 0 ? false : _ref2$modifyingAllowe,
107
+ keypointDefinitions = _ref2.keypointDefinitions,
108
+ allowComments = _ref2.allowComments;
109
+ var classes = useStyles();
110
+ var canvasEl = useRef(null);
111
+ var layoutParams = useRef({});
112
+
113
+ var _useRafState = useRafState(false),
114
+ _useRafState2 = _slicedToArray(_useRafState, 2),
115
+ dragging = _useRafState2[0],
116
+ changeDragging = _useRafState2[1];
117
+
118
+ var _useRafState3 = useRafState(0),
119
+ _useRafState4 = _slicedToArray(_useRafState3, 2),
120
+ maskImagesLoaded = _useRafState4[0],
121
+ changeMaskImagesLoaded = _useRafState4[1];
122
+
123
+ var _useRafState5 = useRafState(null),
124
+ _useRafState6 = _slicedToArray(_useRafState5, 2),
125
+ zoomStart = _useRafState6[0],
126
+ changeZoomStart = _useRafState6[1];
127
+
128
+ var _useRafState7 = useRafState(null),
129
+ _useRafState8 = _slicedToArray(_useRafState7, 2),
130
+ zoomEnd = _useRafState8[0],
131
+ changeZoomEnd = _useRafState8[1];
132
+
133
+ var _useRafState9 = useRafState(getDefaultMat()),
134
+ _useRafState10 = _slicedToArray(_useRafState9, 2),
135
+ mat = _useRafState10[0],
136
+ changeMat = _useRafState10[1];
137
+
138
+ var maskImages = useRef({});
139
+ var windowSize = useWindowSize();
140
+ var getLatestMat = useEventCallback(function () {
141
+ return mat;
142
+ });
143
+ useWasdMode({
144
+ getLatestMat: getLatestMat,
145
+ changeMat: changeMat
146
+ });
147
+
148
+ var _useMouse = useMouse({
149
+ canvasEl: canvasEl,
150
+ dragging: dragging,
151
+ mat: mat,
152
+ layoutParams: layoutParams,
153
+ changeMat: changeMat,
154
+ zoomStart: zoomStart,
155
+ zoomEnd: zoomEnd,
156
+ changeZoomStart: changeZoomStart,
157
+ changeZoomEnd: changeZoomEnd,
158
+ changeDragging: changeDragging,
159
+ zoomWithPrimary: zoomWithPrimary,
160
+ dragWithPrimary: dragWithPrimary,
161
+ onMouseMove: onMouseMove,
162
+ onMouseDown: onMouseDown,
163
+ onMouseUp: onMouseUp
164
+ }),
165
+ mouseEvents = _useMouse.mouseEvents,
166
+ mousePosition = _useMouse.mousePosition;
167
+
168
+ useLayoutEffect(function () {
169
+ return changeMat(mat.clone());
170
+ }, [windowSize]);
171
+ var innerMousePos = mat.applyToPoint(mousePosition.current.x, mousePosition.current.y);
172
+ var projectRegionBox = useProjectRegionBox({
173
+ layoutParams: layoutParams,
174
+ mat: mat
175
+ });
176
+
177
+ var _useState = useState(),
178
+ _useState2 = _slicedToArray(_useState, 2),
179
+ imageDimensions = _useState2[0],
180
+ changeImageDimensions = _useState2[1];
181
+
182
+ var imageLoaded = Boolean(imageDimensions && imageDimensions.naturalWidth);
183
+ var onVideoOrImageLoaded = useEventCallback(function (_ref3) {
184
+ var naturalWidth = _ref3.naturalWidth,
185
+ naturalHeight = _ref3.naturalHeight,
186
+ duration = _ref3.duration;
187
+ var dims = {
188
+ naturalWidth: naturalWidth,
189
+ naturalHeight: naturalHeight,
190
+ duration: duration
191
+ };
192
+ if (onImageOrVideoLoaded) onImageOrVideoLoaded(dims);
193
+ changeImageDimensions(dims); // Redundant update to fix rerendering issues
194
+
195
+ setTimeout(function () {
196
+ return changeImageDimensions(dims);
197
+ }, 10);
198
+ });
199
+ var excludePattern = useExcludePattern();
200
+ var canvas = canvasEl.current;
201
+
202
+ if (canvas && imageLoaded) {
203
+ var clientWidth = canvas.clientWidth,
204
+ clientHeight = canvas.clientHeight;
205
+ var fitScale = Math.max(imageDimensions.naturalWidth / (clientWidth - 20), imageDimensions.naturalHeight / (clientHeight - 20));
206
+
207
+ var _iw = imageDimensions.naturalWidth / fitScale,
208
+ _ih = imageDimensions.naturalHeight / fitScale;
209
+
210
+ layoutParams.current = {
211
+ iw: _iw,
212
+ ih: _ih,
213
+ fitScale: fitScale,
214
+ canvasWidth: clientWidth,
215
+ canvasHeight: clientHeight
216
+ };
217
+ }
218
+
219
+ useEffect(function () {
220
+ if (!imageLoaded) return;
221
+ changeMat(getDefaultMat(zoomOnAllowedArea ? allowedArea : null, layoutParams.current)); // eslint-disable-next-line
222
+ }, [imageLoaded]);
223
+ useLayoutEffect(function () {
224
+ if (!imageDimensions) return;
225
+ var clientWidth = canvas.clientWidth,
226
+ clientHeight = canvas.clientHeight;
227
+ canvas.width = clientWidth;
228
+ canvas.height = clientHeight;
229
+ var context = canvas.getContext("2d");
230
+ context.save();
231
+ context.transform.apply(context, _toConsumableArray(mat.clone().inverse().toArray()));
232
+ var _layoutParams$current = layoutParams.current,
233
+ iw = _layoutParams$current.iw,
234
+ ih = _layoutParams$current.ih;
235
+
236
+ if (allowedArea) {
237
+ // Pattern to indicate the NOT allowed areas
238
+ var x = allowedArea.x,
239
+ y = allowedArea.y,
240
+ w = allowedArea.w,
241
+ h = allowedArea.h;
242
+ context.save();
243
+ context.globalAlpha = 1;
244
+ var outer = [[0, 0], [iw, 0], [iw, ih], [0, ih]];
245
+ var inner = [[x * iw, y * ih], [x * iw + w * iw, y * ih], [x * iw + w * iw, y * ih + h * ih], [x * iw, y * ih + h * ih]];
246
+ context.moveTo.apply(context, _toConsumableArray(outer[0]));
247
+ outer.forEach(function (p) {
248
+ return context.lineTo.apply(context, _toConsumableArray(p));
249
+ });
250
+ context.lineTo.apply(context, _toConsumableArray(outer[0]));
251
+ context.closePath();
252
+ inner.reverse();
253
+ context.moveTo.apply(context, _toConsumableArray(inner[0]));
254
+ inner.forEach(function (p) {
255
+ return context.lineTo.apply(context, _toConsumableArray(p));
256
+ });
257
+ context.lineTo.apply(context, _toConsumableArray(inner[0]));
258
+ context.fillStyle = excludePattern || "#f00";
259
+ context.fill();
260
+ context.restore();
261
+ }
262
+
263
+ context.restore();
264
+ });
265
+ var _layoutParams$current2 = layoutParams.current,
266
+ iw = _layoutParams$current2.iw,
267
+ ih = _layoutParams$current2.ih;
268
+ var zoomBox = !zoomStart || !zoomEnd ? null : _objectSpread({}, mat.clone().inverse().applyToPoint(zoomStart.x, zoomStart.y), {
269
+ w: (zoomEnd.x - zoomStart.x) / mat.a,
270
+ h: (zoomEnd.y - zoomStart.y) / mat.d
271
+ });
272
+
273
+ if (zoomBox) {
274
+ if (zoomBox.w < 0) {
275
+ zoomBox.x += zoomBox.w;
276
+ zoomBox.w *= -1;
277
+ }
278
+
279
+ if (zoomBox.h < 0) {
280
+ zoomBox.y += zoomBox.h;
281
+ zoomBox.h *= -1;
282
+ }
283
+ }
284
+
285
+ var imagePosition = {
286
+ topLeft: mat.clone().inverse().applyToPoint(0, 0),
287
+ bottomRight: mat.clone().inverse().applyToPoint(iw, ih)
288
+ };
289
+ var highlightedRegion = useMemo(function () {
290
+ var highlightedRegions = regions.filter(function (r) {
291
+ return r.highlighted;
292
+ });
293
+ if (highlightedRegions.length !== 1) return null;
294
+ return highlightedRegions[0];
295
+ }, [regions]);
296
+ return React.createElement(ThemeProvider, {
297
+ theme: theme
298
+ }, React.createElement("div", {
299
+ style: {
300
+ width: "100%",
301
+ height: "100%",
302
+ maxHeight: "calc(100vh - 68px)",
303
+ position: "relative",
304
+ overflow: "hidden",
305
+ cursor: createWithPrimary ? "crosshair" : dragging ? "grabbing" : dragWithPrimary ? "grab" : zoomWithPrimary ? mat.a < 1 ? "zoom-out" : "zoom-in" : undefined
306
+ }
307
+ }, showCrosshairs && React.createElement(Crosshairs, {
308
+ key: "crossHairs",
309
+ mousePosition: mousePosition
310
+ }), imageLoaded && !dragging && React.createElement(RegionSelectAndTransformBoxes, {
311
+ key: "regionSelectAndTransformBoxes",
312
+ regions: !modifyingAllowedArea || !allowedArea ? regions : [{
313
+ type: "box",
314
+ id: "$$allowed_area",
315
+ cls: "allowed_area",
316
+ highlighted: true,
317
+ x: allowedArea.x,
318
+ y: allowedArea.y,
319
+ w: allowedArea.w,
320
+ h: allowedArea.h,
321
+ visible: true,
322
+ color: "#ff0"
323
+ }],
324
+ mouseEvents: mouseEvents,
325
+ projectRegionBox: projectRegionBox,
326
+ dragWithPrimary: dragWithPrimary,
327
+ createWithPrimary: createWithPrimary,
328
+ zoomWithPrimary: zoomWithPrimary,
329
+ onBeginMovePoint: onBeginMovePoint,
330
+ onSelectRegion: onSelectRegion,
331
+ layoutParams: layoutParams,
332
+ mat: mat,
333
+ onBeginBoxTransform: onBeginBoxTransform,
334
+ onBeginMovePolygonPoint: onBeginMovePolygonPoint,
335
+ onBeginMoveKeypoint: onBeginMoveKeypoint,
336
+ onAddPolygonPoint: onAddPolygonPoint,
337
+ showHighlightBox: showHighlightBox
338
+ }), imageLoaded && showTags && !dragging && React.createElement(PreventScrollToParents, {
339
+ style: {
340
+ display: hideRegionLabel ? "none" : ""
341
+ },
342
+ key: "regionTags"
343
+ }, React.createElement(RegionTags, {
344
+ regions: regions,
345
+ projectRegionBox: projectRegionBox,
346
+ mouseEvents: mouseEvents,
347
+ regionClsList: regionClsList,
348
+ regionTagList: regionTagList,
349
+ onBeginRegionEdit: onBeginRegionEdit,
350
+ onChangeRegion: onChangeRegion,
351
+ onCloseRegionEdit: onCloseRegionEdit,
352
+ onDeleteRegion: onDeleteRegion,
353
+ layoutParams: layoutParams,
354
+ imageSrc: imageSrc,
355
+ RegionEditLabel: RegionEditLabel,
356
+ onRegionClassAdded: onRegionClassAdded,
357
+ allowComments: allowComments
358
+ })), !showTags && highlightedRegion && React.createElement("div", {
359
+ key: "topLeftTag",
360
+ className: classes.fixedRegionLabel
361
+ }, React.createElement(RegionLabel, {
362
+ disableClose: true,
363
+ allowedClasses: regionClsList,
364
+ allowedTags: regionTagList,
365
+ onChange: onChangeRegion,
366
+ onDelete: onDeleteRegion,
367
+ editing: true,
368
+ region: highlightedRegion,
369
+ imageSrc: imageSrc,
370
+ allowComments: allowComments
371
+ })), zoomWithPrimary && zoomBox !== null && React.createElement("div", {
372
+ key: "zoomBox",
373
+ style: {
374
+ position: "absolute",
375
+ zIndex: 1,
376
+ border: "1px solid #fff",
377
+ pointerEvents: "none",
378
+ left: zoomBox.x,
379
+ top: zoomBox.y,
380
+ width: zoomBox.w,
381
+ height: zoomBox.h
382
+ }
383
+ }), showPointDistances && React.createElement(PointDistances, {
384
+ key: "pointDistances",
385
+ regions: regions,
386
+ realSize: realSize,
387
+ projectRegionBox: projectRegionBox,
388
+ pointDistancePrecision: pointDistancePrecision
389
+ }), React.createElement(PreventScrollToParents, Object.assign({
390
+ style: {
391
+ width: "100%",
392
+ height: "100%"
393
+ }
394
+ }, mouseEvents), React.createElement(React.Fragment, null, fullImageSegmentationMode && React.createElement(ImageMask, {
395
+ hide: !showMask,
396
+ autoSegmentationOptions: autoSegmentationOptions,
397
+ imagePosition: imagePosition,
398
+ regionClsList: regionClsList,
399
+ imageSrc: imageSrc,
400
+ regions: regions
401
+ }), React.createElement("canvas", {
402
+ style: {
403
+ opacity: 0.25
404
+ },
405
+ className: classes.canvas,
406
+ ref: canvasEl
407
+ }), React.createElement(RegionShapes, {
408
+ mat: mat,
409
+ keypointDefinitions: keypointDefinitions,
410
+ imagePosition: imagePosition,
411
+ regions: regions,
412
+ fullSegmentationMode: fullImageSegmentationMode
413
+ }), React.createElement(VideoOrImageCanvasBackground, {
414
+ videoPlaying: videoPlaying,
415
+ imagePosition: imagePosition,
416
+ mouseEvents: mouseEvents,
417
+ onLoad: onVideoOrImageLoaded,
418
+ videoTime: videoTime,
419
+ videoSrc: videoSrc,
420
+ imageSrc: imageSrc,
421
+ useCrossOrigin: fullImageSegmentationMode,
422
+ onChangeVideoTime: onChangeVideoTime,
423
+ onChangeVideoPlaying: onChangeVideoPlaying
424
+ }))), React.createElement("div", {
425
+ className: classes.zoomIndicator
426
+ }, (1 / mat.a * 100).toFixed(0), "%")));
427
+ };
428
+ export default ImageCanvas;
@@ -0,0 +1,165 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
+ export var getEnclosingBox = function getEnclosingBox(region) {
5
+ switch (region.type) {
6
+ case "polygon":
7
+ {
8
+ var box = {
9
+ x: Math.min.apply(Math, _toConsumableArray(region.points.map(function (_ref) {
10
+ var _ref2 = _slicedToArray(_ref, 2),
11
+ x = _ref2[0],
12
+ y = _ref2[1];
13
+
14
+ return x;
15
+ }))),
16
+ y: Math.min.apply(Math, _toConsumableArray(region.points.map(function (_ref3) {
17
+ var _ref4 = _slicedToArray(_ref3, 2),
18
+ x = _ref4[0],
19
+ y = _ref4[1];
20
+
21
+ return y;
22
+ }))),
23
+ w: 0,
24
+ h: 0
25
+ };
26
+ box.w = Math.max.apply(Math, _toConsumableArray(region.points.map(function (_ref5) {
27
+ var _ref6 = _slicedToArray(_ref5, 2),
28
+ x = _ref6[0],
29
+ y = _ref6[1];
30
+
31
+ return x;
32
+ }))) - box.x;
33
+ box.h = Math.max.apply(Math, _toConsumableArray(region.points.map(function (_ref7) {
34
+ var _ref8 = _slicedToArray(_ref7, 2),
35
+ x = _ref8[0],
36
+ y = _ref8[1];
37
+
38
+ return y;
39
+ }))) - box.y;
40
+ return box;
41
+ }
42
+
43
+ case "keypoints":
44
+ {
45
+ var minX = Math.min.apply(Math, _toConsumableArray(Object.values(region.points).map(function (_ref9) {
46
+ var x = _ref9.x,
47
+ y = _ref9.y;
48
+ return x;
49
+ })));
50
+ var minY = Math.min.apply(Math, _toConsumableArray(Object.values(region.points).map(function (_ref10) {
51
+ var x = _ref10.x,
52
+ y = _ref10.y;
53
+ return y;
54
+ })));
55
+ var maxX = Math.max.apply(Math, _toConsumableArray(Object.values(region.points).map(function (_ref11) {
56
+ var x = _ref11.x,
57
+ y = _ref11.y;
58
+ return x;
59
+ })));
60
+ var maxY = Math.max.apply(Math, _toConsumableArray(Object.values(region.points).map(function (_ref12) {
61
+ var x = _ref12.x,
62
+ y = _ref12.y;
63
+ return y;
64
+ })));
65
+ return {
66
+ x: minX,
67
+ y: minY,
68
+ w: maxX - minX,
69
+ h: maxY - minY
70
+ };
71
+ }
72
+
73
+ case "expanding-line":
74
+ {
75
+ var _box = {
76
+ x: Math.min.apply(Math, _toConsumableArray(region.points.map(function (_ref13) {
77
+ var x = _ref13.x,
78
+ y = _ref13.y;
79
+ return x;
80
+ }))),
81
+ y: Math.min.apply(Math, _toConsumableArray(region.points.map(function (_ref14) {
82
+ var x = _ref14.x,
83
+ y = _ref14.y;
84
+ return y;
85
+ }))),
86
+ w: 0,
87
+ h: 0
88
+ };
89
+ _box.w = Math.max.apply(Math, _toConsumableArray(region.points.map(function (_ref15) {
90
+ var x = _ref15.x,
91
+ y = _ref15.y;
92
+ return x;
93
+ }))) - _box.x;
94
+ _box.h = Math.max.apply(Math, _toConsumableArray(region.points.map(function (_ref16) {
95
+ var x = _ref16.x,
96
+ y = _ref16.y;
97
+ return y;
98
+ }))) - _box.y;
99
+ return _box;
100
+ }
101
+
102
+ case "line":
103
+ {
104
+ return {
105
+ x: region.x1,
106
+ y: region.y1,
107
+ w: 0,
108
+ h: 0
109
+ };
110
+ }
111
+
112
+ case "box":
113
+ {
114
+ return {
115
+ x: region.x,
116
+ y: region.y,
117
+ w: region.w,
118
+ h: region.h
119
+ };
120
+ }
121
+
122
+ case "point":
123
+ {
124
+ return {
125
+ x: region.x,
126
+ y: region.y,
127
+ w: 0,
128
+ h: 0
129
+ };
130
+ }
131
+
132
+ default:
133
+ {
134
+ return {
135
+ x: 0,
136
+ y: 0,
137
+ w: 0,
138
+ h: 0
139
+ };
140
+ }
141
+ }
142
+
143
+ throw new Error("unknown region");
144
+ };
145
+ export var moveRegion = function moveRegion(region, x, y) {
146
+ switch (region.type) {
147
+ case "point":
148
+ {
149
+ return _objectSpread({}, region, {
150
+ x: x,
151
+ y: y
152
+ });
153
+ }
154
+
155
+ case "box":
156
+ {
157
+ return _objectSpread({}, region, {
158
+ x: x - region.w / 2,
159
+ y: y - region.h / 2
160
+ });
161
+ }
162
+ }
163
+
164
+ return region;
165
+ };
@@ -0,0 +1,31 @@
1
+ import { grey } from "@mui/material/colors";
2
+ export default {
3
+ canvas: {
4
+ width: "100%",
5
+ height: "100%",
6
+ position: "relative",
7
+ zIndex: 1
8
+ },
9
+ zoomIndicator: {
10
+ position: "absolute",
11
+ bottom: 16,
12
+ right: 0,
13
+ backgroundColor: "rgba(0,0,0,0.4)",
14
+ color: "#fff",
15
+ opacity: 0.5,
16
+ fontWeight: "bolder",
17
+ fontSize: 14,
18
+ padding: 4
19
+ },
20
+ fixedRegionLabel: {
21
+ position: "absolute",
22
+ zIndex: 10,
23
+ top: 10,
24
+ left: 10,
25
+ opacity: 0.5,
26
+ transition: "opacity 500ms",
27
+ "&:hover": {
28
+ opacity: 1
29
+ }
30
+ }
31
+ };