@searpent/react-image-annotate 2.0.77 → 2.0.78
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.
- package/Annotator/exampleImages.js +41 -0
- package/Annotator/examplePhotos.js +6980 -0
- package/Annotator/index.js +417 -0
- package/Annotator/reducers/combine-reducers.js +14 -0
- package/Annotator/reducers/convert-expanding-line-to-polygon.js +73 -0
- package/{src/Annotator → Annotator}/reducers/fix-twisted.js +3 -5
- package/Annotator/reducers/general-reducer.js +1430 -0
- package/Annotator/reducers/get-active-image.js +27 -0
- package/Annotator/reducers/get-implied-video-regions.js +180 -0
- package/Annotator/reducers/history-handler.js +38 -0
- package/Annotator/reducers/image-reducer.js +20 -0
- package/Annotator/reducers/video-reducer.js +88 -0
- package/ClassSelectionMenu/index.js +140 -0
- package/Crosshairs/index.js +53 -0
- package/DebugSidebarBox/index.js +20 -0
- package/DemoSite/Editor.js +194 -0
- package/DemoSite/ErrorBoundaryDialog.js +64 -0
- package/DemoSite/index.js +40 -0
- package/Editor/annotation-plugin/annotation.js +697 -0
- package/Editor/index.js +93 -0
- package/Editor/readOnly.js +123 -0
- package/{src/Editor → Editor}/tools.js +2 -3
- package/Errorer/index.js +11 -0
- package/FullImageSegmentationAnnotator/index.js +7 -0
- package/GroupSelectorSidebarBox/index.js +63 -0
- package/GroupsEditorSidebarBox/index.js +138 -0
- package/HelpSidebarBox/index.js +58 -0
- package/HighlightBox/index.js +102 -0
- package/HistorySidebarBox/index.js +71 -0
- package/ImageCanvas/index.js +441 -0
- package/ImageCanvas/region-tools.js +165 -0
- package/{src/ImageCanvas → ImageCanvas}/styles.js +12 -8
- package/ImageCanvas/use-mouse.js +180 -0
- package/ImageCanvas/use-project-box.js +27 -0
- package/ImageCanvas/use-wasd-mode.js +62 -0
- package/ImageMask/index.js +133 -0
- package/ImageMask/load-image.js +25 -0
- package/ImageSelectorSidebarBox/index.js +60 -0
- package/KeyframeTimeline/get-time-string.js +27 -0
- package/KeyframeTimeline/index.js +233 -0
- package/KeyframesSelectorSidebarBox/index.js +93 -0
- package/LandingPage/index.js +159 -0
- package/Locker/index.js +11 -0
- package/MainLayout/RightSidebarItemsWrapper.js +19 -0
- package/MainLayout/icon-dictionary.js +104 -0
- package/MainLayout/index.js +526 -0
- package/{src/MainLayout → MainLayout}/styles.js +6 -7
- package/MainLayout/types.js +0 -0
- package/MainLayout/use-implied-video-regions.js +13 -0
- package/MetadataEditorSidebarBox/index.js +231 -0
- package/PageSelector/index.js +180 -0
- package/PointDistances/index.js +73 -0
- package/PreventScrollToParents/index.js +51 -0
- package/RegionLabel/index.js +232 -0
- package/{src/RegionLabel → RegionLabel}/styles.js +12 -15
- package/RegionSelectAndTransformBoxes/index.js +169 -0
- package/RegionSelectorSidebarBox/index.js +254 -0
- package/{src/RegionSelectorSidebarBox → RegionSelectorSidebarBox}/styles.js +13 -14
- package/RegionShapes/index.js +294 -0
- package/RegionTags/index.js +144 -0
- package/SettingsDialog/index.js +52 -0
- package/SettingsProvider/index.js +60 -0
- package/Shortcuts/ShortcutField.js +46 -0
- package/Shortcuts/index.js +133 -0
- package/ShortcutsManager/index.js +155 -0
- package/Sidebar/index.js +69 -0
- package/SidebarBoxContainer/index.js +93 -0
- package/SmallToolButton/index.js +42 -0
- package/TagsSidebarBox/index.js +105 -0
- package/TaskDescriptionSidebarBox/index.js +58 -0
- package/Theme/index.js +30 -0
- package/VideoOrImageCanvasBackground/index.js +151 -0
- package/colors.js +14 -0
- package/hooks/use-colors.js +127 -0
- package/hooks/use-event-callback.js +10 -0
- package/hooks/use-exclude-pattern.js +24 -0
- package/hooks/use-load-image.js +26 -0
- package/hooks/use-window-size.js +46 -0
- package/{src/hooks → hooks}/xpattern.js +1 -1
- package/index.js +3 -0
- package/lib.js +3 -0
- package/package.json +1 -1
- package/stories.js +5 -0
- package/utils/blocks-to-article.js +60 -0
- package/{src/utils → utils}/blocks-to-article.test.js +5 -8
- package/{src/utils → utils}/default-locked-until.js +2 -1
- package/{src/utils → utils}/filter-only-unique.js +1 -1
- package/utils/get-from-local-storage.js +7 -0
- package/utils/get-hotkey-help-text.js +9 -0
- package/utils/get-landmarks-with-transform.js +40 -0
- package/utils/photosToImages.js +85 -0
- package/utils/regions-groups.js +28 -0
- package/utils/regions-to-blocks.js +18 -0
- package/utils/saveable-actions-enum.js +3 -0
- package/utils/set-in-local-storage.js +3 -0
- package/utils/sleep.js +7 -0
- package/utils/uuid-to-hash.js +5 -0
- package/.babelrc +0 -6
- package/.env +0 -1
- package/.flowconfig +0 -2
- package/.github/workflows/release-on-master.yml +0 -32
- package/.github/workflows/test.yml +0 -16
- package/.prettierrc +0 -3
- package/.releaserc.js +0 -18
- package/.storybook/addons.js +0 -2
- package/.storybook/config.js +0 -16
- package/LICENSE +0 -21
- package/public/favicon.ico +0 -0
- package/public/index.html +0 -38
- package/src/Annotator/bike-pic.png +0 -0
- package/src/Annotator/bike-pic2.png +0 -0
- package/src/Annotator/dab-keyframes.story.json +0 -1
- package/src/Annotator/exampleImages.js +0 -48
- package/src/Annotator/examplePhotos.js +0 -7603
- package/src/Annotator/index.js +0 -380
- package/src/Annotator/index.story.js +0 -899
- package/src/Annotator/poses.story.js +0 -150
- package/src/Annotator/reducers/combine-reducers.js +0 -7
- package/src/Annotator/reducers/convert-expanding-line-to-polygon.js +0 -53
- package/src/Annotator/reducers/general-reducer.js +0 -1228
- package/src/Annotator/reducers/get-active-image.js +0 -21
- package/src/Annotator/reducers/get-implied-video-regions.js +0 -115
- package/src/Annotator/reducers/history-handler.js +0 -60
- package/src/Annotator/reducers/image-reducer.js +0 -23
- package/src/Annotator/reducers/video-reducer.js +0 -85
- package/src/Annotator/video.story.js +0 -51
- package/src/ClassSelectionMenu/index.js +0 -112
- package/src/Crosshairs/index.js +0 -64
- package/src/DebugSidebarBox/index.js +0 -36
- package/src/DemoSite/Editor.js +0 -235
- package/src/DemoSite/ErrorBoundaryDialog.js +0 -34
- package/src/DemoSite/index.js +0 -41
- package/src/DemoSite/index.story.js +0 -10
- package/src/DemoSite/simple-segmentation-example.json +0 -572
- package/src/Editor/annotation-plugin/annotation.js +0 -546
- package/src/Editor/index.js +0 -50
- package/src/Editor/readOnly.js +0 -31
- package/src/Errorer/index.js +0 -13
- package/src/FullImageSegmentationAnnotator/hard1.story.jpg +0 -0
- package/src/FullImageSegmentationAnnotator/hard2.story.jpg +0 -0
- package/src/FullImageSegmentationAnnotator/hard3.story.jpg +0 -0
- package/src/FullImageSegmentationAnnotator/index.js +0 -7
- package/src/FullImageSegmentationAnnotator/index.story.js +0 -177
- package/src/FullImageSegmentationAnnotator/orange.story.png +0 -0
- package/src/GroupSelectorSidebarBox/index.js +0 -48
- package/src/GroupsEditorSidebarBox/index.js +0 -108
- package/src/HelpSidebarBox/index.js +0 -43
- package/src/HighlightBox/index.js +0 -143
- package/src/HistorySidebarBox/index.js +0 -78
- package/src/ImageCanvas/dancing-man.story.jpg +0 -0
- package/src/ImageCanvas/index.js +0 -515
- package/src/ImageCanvas/index.story.js +0 -314
- package/src/ImageCanvas/mouse_mask.story.png +0 -0
- package/src/ImageCanvas/region-tools.js +0 -171
- package/src/ImageCanvas/seves_desk.story.jpg +0 -0
- package/src/ImageCanvas/use-mouse.js +0 -168
- package/src/ImageCanvas/use-project-box.js +0 -23
- package/src/ImageCanvas/use-wasd-mode.js +0 -50
- package/src/ImageMask/index.js +0 -127
- package/src/ImageMask/load-image.js +0 -32
- package/src/ImageSelectorSidebarBox/index.js +0 -54
- package/src/KeyframeTimeline/get-time-string.js +0 -25
- package/src/KeyframeTimeline/index.js +0 -223
- package/src/KeyframesSelectorSidebarBox/index.js +0 -93
- package/src/LandingPage/content.md +0 -57
- package/src/LandingPage/github-markdown.css +0 -964
- package/src/LandingPage/index.js +0 -147
- package/src/Locker/index.js +0 -13
- package/src/MainLayout/RightSidebarItemsWrapper.js +0 -21
- package/src/MainLayout/icon-dictionary.js +0 -79
- package/src/MainLayout/index.js +0 -564
- package/src/MainLayout/index.story.js +0 -240
- package/src/MainLayout/types.js +0 -171
- package/src/MainLayout/use-implied-video-regions.js +0 -17
- package/src/MetadataEditorSidebarBox/index.js +0 -160
- package/src/PageSelector/index.js +0 -159
- package/src/PointDistances/index.js +0 -90
- package/src/PreventScrollToParents/index.js +0 -48
- package/src/PreventScrollToParents/index.story.js +0 -23
- package/src/RegionLabel/index.js +0 -236
- package/src/RegionSelectAndTransformBoxes/index.js +0 -236
- package/src/RegionSelectorSidebarBox/index.js +0 -220
- package/src/RegionShapes/index.js +0 -254
- package/src/RegionTags/index.js +0 -136
- package/src/SettingsDialog/index.js +0 -58
- package/src/SettingsProvider/index.js +0 -57
- package/src/Shortcuts/ShortcutField.js +0 -44
- package/src/Shortcuts/index.js +0 -129
- package/src/ShortcutsManager/index.js +0 -162
- package/src/Sidebar/index.js +0 -117
- package/src/SidebarBoxContainer/index.js +0 -93
- package/src/SmallToolButton/index.js +0 -57
- package/src/TagsSidebarBox/index.js +0 -93
- package/src/TaskDescriptionSidebarBox/index.js +0 -43
- package/src/Theme/index.js +0 -36
- package/src/VideoOrImageCanvasBackground/index.js +0 -170
- package/src/colors.js +0 -32
- package/src/hooks/use-colors.js +0 -95
- package/src/hooks/use-event-callback.js +0 -11
- package/src/hooks/use-exclude-pattern.js +0 -27
- package/src/hooks/use-load-image.js +0 -21
- package/src/hooks/use-window-size.js +0 -46
- package/src/hooks/xpattern.png +0 -0
- package/src/index.js +0 -18
- package/src/lib.js +0 -7
- package/src/screenshot.png +0 -0
- package/src/site.css +0 -5
- package/src/stories.js +0 -2
- package/src/utils/blocks-to-article.js +0 -61
- package/src/utils/get-from-local-storage.js +0 -7
- package/src/utils/get-hotkey-help-text.js +0 -11
- package/src/utils/get-landmarks-with-transform.js +0 -23
- package/src/utils/photosToImages.js +0 -67
- package/src/utils/regions-groups.js +0 -19
- package/src/utils/regions-to-blocks.js +0 -16
- package/src/utils/saveable-actions-enum.js +0 -5
- package/src/utils/set-in-local-storage.js +0 -6
- package/src/utils/sleep.js +0 -3
- package/src/utils/uuid-to-hash.js +0 -5
- /package/{src/Editor → Editor}/annotation-plugin/annotation.css +0 -0
- /package/{src/Errorer → Errorer}/errorer.css +0 -0
- /package/{src/Locker → Locker}/locker.css +0 -0
- /package/{src/PageSelector → PageSelector}/page-selector.css +0 -0
- /package/{src/utils → utils}/next-group-id.js +0 -0
|
@@ -1,314 +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
|
-
export const testRegionsBoxes = [
|
|
91
|
-
{
|
|
92
|
-
type: "box",
|
|
93
|
-
id: "box1",
|
|
94
|
-
cls: "title",
|
|
95
|
-
highlighted: false,
|
|
96
|
-
groupHighlighted: false,
|
|
97
|
-
x: 0.315,
|
|
98
|
-
y: 0.63,
|
|
99
|
-
w: 0.067,
|
|
100
|
-
h: 0.045,
|
|
101
|
-
visible: true,
|
|
102
|
-
color: "#ff4133",
|
|
103
|
-
groupColor: "#2436ff",
|
|
104
|
-
groupId: "alpha",
|
|
105
|
-
text: "first box text"
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
type: "box",
|
|
109
|
-
id: "box2",
|
|
110
|
-
cls: "text",
|
|
111
|
-
highlighted: false,
|
|
112
|
-
groupHighlighted: false,
|
|
113
|
-
x: 0.415,
|
|
114
|
-
y: 0.63,
|
|
115
|
-
w: 0.067,
|
|
116
|
-
h: 0.045,
|
|
117
|
-
visible: true,
|
|
118
|
-
color: "#ff9924",
|
|
119
|
-
groupColor: "#2436ff",
|
|
120
|
-
groupId: "alpha",
|
|
121
|
-
text: "second box text"
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
type: "box",
|
|
125
|
-
id: "boxBeta1",
|
|
126
|
-
cls: "title",
|
|
127
|
-
highlighted: false,
|
|
128
|
-
groupHighlighted: false,
|
|
129
|
-
x: 0.315,
|
|
130
|
-
y: 0.43,
|
|
131
|
-
w: 0.067,
|
|
132
|
-
h: 0.045,
|
|
133
|
-
visible: true,
|
|
134
|
-
color: "#ff4133",
|
|
135
|
-
groupColor: "#78ffa7",
|
|
136
|
-
groupId: "beta",
|
|
137
|
-
text: "third box text"
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
type: "box",
|
|
141
|
-
id: "boxBeta2",
|
|
142
|
-
cls: "subtitle",
|
|
143
|
-
highlighted: false,
|
|
144
|
-
groupHighlighted: false,
|
|
145
|
-
x: 0.415,
|
|
146
|
-
y: 0.43,
|
|
147
|
-
w: 0.067,
|
|
148
|
-
h: 0.045,
|
|
149
|
-
visible: true,
|
|
150
|
-
color: "#ff9924",
|
|
151
|
-
groupColor: "#78ffa7",
|
|
152
|
-
groupId: "beta",
|
|
153
|
-
text: "fourth box text"
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
type: "box",
|
|
157
|
-
id: "boxBeta3",
|
|
158
|
-
cls: "text",
|
|
159
|
-
highlighted: false,
|
|
160
|
-
groupHighlighted: false,
|
|
161
|
-
x: 0.415,
|
|
162
|
-
y: 0.53,
|
|
163
|
-
w: 0.067,
|
|
164
|
-
h: 0.045,
|
|
165
|
-
visible: true,
|
|
166
|
-
color: "#007efc",
|
|
167
|
-
groupColor: "#78ffa7",
|
|
168
|
-
groupId: "beta",
|
|
169
|
-
text: "fifth box text"
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
type: "box",
|
|
173
|
-
id: "boxBeta4",
|
|
174
|
-
cls: "text",
|
|
175
|
-
highlighted: false,
|
|
176
|
-
groupHighlighted: false,
|
|
177
|
-
x: 0.415,
|
|
178
|
-
y: 0.73,
|
|
179
|
-
w: 0.067,
|
|
180
|
-
h: 0.045,
|
|
181
|
-
visible: true,
|
|
182
|
-
color: "#007efc",
|
|
183
|
-
groupColor: "#78ffa7",
|
|
184
|
-
groupId: "beta",
|
|
185
|
-
text: "sixth box text"
|
|
186
|
-
},
|
|
187
|
-
|
|
188
|
-
]
|
|
189
|
-
|
|
190
|
-
const events = {
|
|
191
|
-
// Ignore common mouse movements, they fill the action log
|
|
192
|
-
onMouseMove: () => null, //action("onMouseMove"),
|
|
193
|
-
onMouseDown: () => null, //action("onMouseDown"),
|
|
194
|
-
onMouseUp: () => null, //action("onMouseUp"),
|
|
195
|
-
|
|
196
|
-
onChangeRegion: action("onChangeRegion"),
|
|
197
|
-
onBeginRegionEdit: action("onBeginRegionEdit"),
|
|
198
|
-
onCloseRegionEdit: action("onCloseRegionEdit"),
|
|
199
|
-
|
|
200
|
-
onSelectRegion: action("onSelectRegion"),
|
|
201
|
-
|
|
202
|
-
onBeginBoxTransform: action("onBeginBoxTransform"),
|
|
203
|
-
|
|
204
|
-
onBeginMovePolygonPoint: action("onBeginMovePolygonPoint"),
|
|
205
|
-
onAddPolygonPoint: action("onAddPolygonPoint"),
|
|
206
|
-
onClosePolygon: action("onClosePolygon"),
|
|
207
|
-
|
|
208
|
-
onBeginMoveKeypoint: action("onBeginMoveKeypoint"),
|
|
209
|
-
|
|
210
|
-
onBeginMovePoint: action("onBeginMovePoint"),
|
|
211
|
-
onDeleteRegion: action("onDeleteRegion"),
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
storiesOf("ImageCanvas", module)
|
|
215
|
-
.add("Basic", () => (
|
|
216
|
-
<ImageCanvas
|
|
217
|
-
regions={testRegions}
|
|
218
|
-
imageSrc={exampleImage}
|
|
219
|
-
showTags
|
|
220
|
-
{...events}
|
|
221
|
-
/>
|
|
222
|
-
))
|
|
223
|
-
.add("Zoom Tool Selected", () => (
|
|
224
|
-
<ImageCanvas
|
|
225
|
-
showTags
|
|
226
|
-
regions={testRegions}
|
|
227
|
-
imageSrc={exampleImage}
|
|
228
|
-
zoomWithPrimary
|
|
229
|
-
{...events}
|
|
230
|
-
/>
|
|
231
|
-
))
|
|
232
|
-
.add("Allowed Area", () => (
|
|
233
|
-
<ImageCanvas
|
|
234
|
-
showTags
|
|
235
|
-
regions={[]}
|
|
236
|
-
imageSrc={exampleImage}
|
|
237
|
-
zoomWithPrimary
|
|
238
|
-
allowedArea={{ x: 0.25, y: 0.25, w: 0.5, h: 0.5 }}
|
|
239
|
-
{...events}
|
|
240
|
-
/>
|
|
241
|
-
))
|
|
242
|
-
.add("Allowed Area (2)", () => (
|
|
243
|
-
<ImageCanvas
|
|
244
|
-
showTags
|
|
245
|
-
regions={[]}
|
|
246
|
-
imageSrc={exampleImage}
|
|
247
|
-
zoomWithPrimary
|
|
248
|
-
allowedArea={{ x: 0.6, y: 0.6, w: 0.2, h: 0.2 }}
|
|
249
|
-
{...events}
|
|
250
|
-
/>
|
|
251
|
-
))
|
|
252
|
-
.add("Modify Allowed Area", () => (
|
|
253
|
-
<ImageCanvas
|
|
254
|
-
showTags
|
|
255
|
-
regions={[]}
|
|
256
|
-
imageSrc={exampleImage}
|
|
257
|
-
modifyingAllowedArea
|
|
258
|
-
allowedArea={{ x: 0.6, y: 0.6, w: 0.2, h: 0.2 }}
|
|
259
|
-
{...events}
|
|
260
|
-
/>
|
|
261
|
-
))
|
|
262
|
-
.add("Poses", () => (
|
|
263
|
-
<ImageCanvas
|
|
264
|
-
keypointDefinitions={{
|
|
265
|
-
human: {
|
|
266
|
-
connections: [
|
|
267
|
-
["head", "sternum"],
|
|
268
|
-
["sternum", "leftElbow"],
|
|
269
|
-
["sternum", "rightElbow"],
|
|
270
|
-
],
|
|
271
|
-
landmarks: {
|
|
272
|
-
head: {
|
|
273
|
-
label: "Head",
|
|
274
|
-
color: "#f00",
|
|
275
|
-
defaultPosition: [0, -0.05],
|
|
276
|
-
},
|
|
277
|
-
sternum: {
|
|
278
|
-
label: "Torso",
|
|
279
|
-
color: "#0f0",
|
|
280
|
-
defaultPosition: [0, 0],
|
|
281
|
-
},
|
|
282
|
-
leftElbow: {
|
|
283
|
-
label: "Left Elbow",
|
|
284
|
-
color: "#00f",
|
|
285
|
-
defaultPosition: [-0.05, 0],
|
|
286
|
-
},
|
|
287
|
-
rightElbow: {
|
|
288
|
-
label: "Right Elbow",
|
|
289
|
-
color: "#00f",
|
|
290
|
-
defaultPosition: [0.05, 0],
|
|
291
|
-
},
|
|
292
|
-
},
|
|
293
|
-
},
|
|
294
|
-
}}
|
|
295
|
-
regions={[
|
|
296
|
-
{
|
|
297
|
-
type: "keypoints",
|
|
298
|
-
id: "keypoints1",
|
|
299
|
-
keypointsDefinitionId: "human",
|
|
300
|
-
highlighted: true,
|
|
301
|
-
points: {
|
|
302
|
-
head: { x: 0.54, y: 0.2 },
|
|
303
|
-
sternum: { x: 0.57, y: 0.3 },
|
|
304
|
-
leftElbow: { x: 0.4, y: 0.39 },
|
|
305
|
-
rightElbow: { x: 0.7, y: 0.32 },
|
|
306
|
-
},
|
|
307
|
-
visible: true,
|
|
308
|
-
},
|
|
309
|
-
]}
|
|
310
|
-
imageSrc={dancingManImage}
|
|
311
|
-
showTags
|
|
312
|
-
{...events}
|
|
313
|
-
/>
|
|
314
|
-
))
|
|
Binary file
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
export type BaseRegion = {
|
|
4
|
-
id: string | number,
|
|
5
|
-
cls?: string,
|
|
6
|
-
locked?: boolean,
|
|
7
|
-
visible?: boolean,
|
|
8
|
-
color: string,
|
|
9
|
-
editingLabels?: boolean,
|
|
10
|
-
highlighted?: boolean,
|
|
11
|
-
tags?: Array<string>,
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type Point = {|
|
|
15
|
-
...$Exact<BaseRegion>,
|
|
16
|
-
type: "point",
|
|
17
|
-
x: number,
|
|
18
|
-
y: number,
|
|
19
|
-
|}
|
|
20
|
-
|
|
21
|
-
export type PixelRegion =
|
|
22
|
-
| {|
|
|
23
|
-
...$Exact<BaseRegion>,
|
|
24
|
-
type: "pixel",
|
|
25
|
-
sx: number,
|
|
26
|
-
sy: number,
|
|
27
|
-
w: number,
|
|
28
|
-
h: number,
|
|
29
|
-
src: string,
|
|
30
|
-
|}
|
|
31
|
-
| {|
|
|
32
|
-
...$Exact<BaseRegion>,
|
|
33
|
-
type: "pixel",
|
|
34
|
-
points: Array<[number, number]>,
|
|
35
|
-
|}
|
|
36
|
-
export type Box = {|
|
|
37
|
-
...$Exact<BaseRegion>,
|
|
38
|
-
type: "box",
|
|
39
|
-
x: number,
|
|
40
|
-
y: number,
|
|
41
|
-
w: number,
|
|
42
|
-
h: number,
|
|
43
|
-
|}
|
|
44
|
-
|
|
45
|
-
export type Polygon = {|
|
|
46
|
-
...$Exact<BaseRegion>,
|
|
47
|
-
type: "polygon",
|
|
48
|
-
open?: boolean,
|
|
49
|
-
points: Array<[number, number]>,
|
|
50
|
-
|}
|
|
51
|
-
|
|
52
|
-
export type Line = {|
|
|
53
|
-
...$Exact<BaseRegion>,
|
|
54
|
-
type: "line",
|
|
55
|
-
x1: number,
|
|
56
|
-
y1: number,
|
|
57
|
-
x2: number,
|
|
58
|
-
y2: number,
|
|
59
|
-
|}
|
|
60
|
-
|
|
61
|
-
export type ExpandingLine = {|
|
|
62
|
-
...$Exact<BaseRegion>,
|
|
63
|
-
type: "expanding-line",
|
|
64
|
-
points: Array<{ x: number, y: number, angle: number, width: number }>,
|
|
65
|
-
|}
|
|
66
|
-
|
|
67
|
-
export type KeypointDefinition = {|
|
|
68
|
-
label: string,
|
|
69
|
-
color: string,
|
|
70
|
-
defaultPosition: [number, number],
|
|
71
|
-
|}
|
|
72
|
-
|
|
73
|
-
export type KeypointId = string
|
|
74
|
-
|
|
75
|
-
export type KeypointsDefinition = {|
|
|
76
|
-
[id: string]: {
|
|
77
|
-
connections: Array<[KeypointId, KeypointId]>,
|
|
78
|
-
landmarks: {
|
|
79
|
-
[KeypointId]: KeypointDefinition,
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
|}
|
|
83
|
-
|
|
84
|
-
export type Keypoints = {|
|
|
85
|
-
...$Exact<BaseRegion>,
|
|
86
|
-
type: "keypoints",
|
|
87
|
-
keypointsDefinitionId: string,
|
|
88
|
-
points: {
|
|
89
|
-
[string]: { x: number, y: number },
|
|
90
|
-
},
|
|
91
|
-
|}
|
|
92
|
-
|
|
93
|
-
export type Region =
|
|
94
|
-
| Point
|
|
95
|
-
| PixelRegion
|
|
96
|
-
| Box
|
|
97
|
-
| Polygon
|
|
98
|
-
| ExpandingLine
|
|
99
|
-
| Keypoints
|
|
100
|
-
|
|
101
|
-
export const getEnclosingBox = (region: Region) => {
|
|
102
|
-
switch (region.type) {
|
|
103
|
-
case "polygon": {
|
|
104
|
-
const box = {
|
|
105
|
-
x: Math.min(...region.points.map(([x, y]) => x)),
|
|
106
|
-
y: Math.min(...region.points.map(([x, y]) => y)),
|
|
107
|
-
w: 0,
|
|
108
|
-
h: 0,
|
|
109
|
-
}
|
|
110
|
-
box.w = Math.max(...region.points.map(([x, y]) => x)) - box.x
|
|
111
|
-
box.h = Math.max(...region.points.map(([x, y]) => y)) - box.y
|
|
112
|
-
return box
|
|
113
|
-
}
|
|
114
|
-
case "keypoints": {
|
|
115
|
-
const minX = Math.min(
|
|
116
|
-
...Object.values(region.points).map(({ x, y }) => x)
|
|
117
|
-
)
|
|
118
|
-
const minY = Math.min(
|
|
119
|
-
...Object.values(region.points).map(({ x, y }) => y)
|
|
120
|
-
)
|
|
121
|
-
const maxX = Math.max(
|
|
122
|
-
...Object.values(region.points).map(({ x, y }) => x)
|
|
123
|
-
)
|
|
124
|
-
const maxY = Math.max(
|
|
125
|
-
...Object.values(region.points).map(({ x, y }) => y)
|
|
126
|
-
)
|
|
127
|
-
return {
|
|
128
|
-
x: minX,
|
|
129
|
-
y: minY,
|
|
130
|
-
w: maxX - minX,
|
|
131
|
-
h: maxY - minY,
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
case "expanding-line": {
|
|
135
|
-
const box = {
|
|
136
|
-
x: Math.min(...region.points.map(({ x, y }) => x)),
|
|
137
|
-
y: Math.min(...region.points.map(({ x, y }) => y)),
|
|
138
|
-
w: 0,
|
|
139
|
-
h: 0,
|
|
140
|
-
}
|
|
141
|
-
box.w = Math.max(...region.points.map(({ x, y }) => x)) - box.x
|
|
142
|
-
box.h = Math.max(...region.points.map(({ x, y }) => y)) - box.y
|
|
143
|
-
return box
|
|
144
|
-
}
|
|
145
|
-
case "line": {
|
|
146
|
-
return { x: region.x1, y: region.y1, w: 0, h: 0 }
|
|
147
|
-
}
|
|
148
|
-
case "box": {
|
|
149
|
-
return { x: region.x, y: region.y, w: region.w, h: region.h }
|
|
150
|
-
}
|
|
151
|
-
case "point": {
|
|
152
|
-
return { x: region.x, y: region.y, w: 0, h: 0 }
|
|
153
|
-
}
|
|
154
|
-
default: {
|
|
155
|
-
return { x: 0, y: 0, w: 0, h: 0 }
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
throw new Error("unknown region")
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export const moveRegion = (region: Region, x: number, y: number) => {
|
|
162
|
-
switch (region.type) {
|
|
163
|
-
case "point": {
|
|
164
|
-
return { ...region, x, y }
|
|
165
|
-
}
|
|
166
|
-
case "box": {
|
|
167
|
-
return { ...region, x: x - region.w / 2, y: y - region.h / 2 }
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return region
|
|
171
|
-
}
|
|
Binary file
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
// @flow weak
|
|
2
|
-
|
|
3
|
-
import { useRef } from "react"
|
|
4
|
-
import { Matrix } from "transformation-matrix-js"
|
|
5
|
-
|
|
6
|
-
const getDefaultMat = () => Matrix.from(1, 0, 0, 1, -10, -10)
|
|
7
|
-
|
|
8
|
-
export default ({
|
|
9
|
-
canvasEl,
|
|
10
|
-
changeMat,
|
|
11
|
-
changeDragging,
|
|
12
|
-
zoomStart,
|
|
13
|
-
zoomEnd,
|
|
14
|
-
changeZoomStart,
|
|
15
|
-
changeZoomEnd,
|
|
16
|
-
layoutParams,
|
|
17
|
-
zoomWithPrimary,
|
|
18
|
-
dragWithPrimary,
|
|
19
|
-
mat,
|
|
20
|
-
onMouseMove,
|
|
21
|
-
onMouseUp,
|
|
22
|
-
onMouseDown,
|
|
23
|
-
dragging,
|
|
24
|
-
}) => {
|
|
25
|
-
const mousePosition = useRef({ x: 0, y: 0 })
|
|
26
|
-
const prevMousePosition = useRef({ x: 0, y: 0 })
|
|
27
|
-
|
|
28
|
-
const zoomIn = (direction, point) => {
|
|
29
|
-
const [mx, my] = [point.x, point.y]
|
|
30
|
-
let scale =
|
|
31
|
-
typeof direction === "object" ? direction.to / mat.a : 1 + 0.2 * direction
|
|
32
|
-
|
|
33
|
-
// NOTE: We're mutating mat here
|
|
34
|
-
mat.translate(mx, my).scaleU(scale)
|
|
35
|
-
if (mat.a > 2) mat.scaleU(2 / mat.a)
|
|
36
|
-
if (mat.a < 0.05) mat.scaleU(0.05 / mat.a)
|
|
37
|
-
mat.translate(-mx, -my)
|
|
38
|
-
|
|
39
|
-
changeMat(mat.clone())
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const mouseEvents = {
|
|
43
|
-
onMouseMove: (e) => {
|
|
44
|
-
const { left, top } = canvasEl.current.getBoundingClientRect()
|
|
45
|
-
prevMousePosition.current.x = mousePosition.current.x
|
|
46
|
-
prevMousePosition.current.y = mousePosition.current.y
|
|
47
|
-
mousePosition.current.x = e.clientX - left
|
|
48
|
-
mousePosition.current.y = e.clientY - top
|
|
49
|
-
|
|
50
|
-
const projMouse = mat.applyToPoint(
|
|
51
|
-
mousePosition.current.x,
|
|
52
|
-
mousePosition.current.y
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
if (zoomWithPrimary && zoomStart) {
|
|
56
|
-
changeZoomEnd(projMouse)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const { iw, ih } = layoutParams.current
|
|
60
|
-
onMouseMove({ x: projMouse.x / iw, y: projMouse.y / ih })
|
|
61
|
-
|
|
62
|
-
if (dragging) {
|
|
63
|
-
mat.translate(
|
|
64
|
-
prevMousePosition.current.x - mousePosition.current.x,
|
|
65
|
-
prevMousePosition.current.y - mousePosition.current.y
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
changeMat(mat.clone())
|
|
69
|
-
}
|
|
70
|
-
e.preventDefault()
|
|
71
|
-
},
|
|
72
|
-
onMouseDown: (e, specialEvent = {}) => {
|
|
73
|
-
e.preventDefault()
|
|
74
|
-
|
|
75
|
-
if (
|
|
76
|
-
e.button === 1 ||
|
|
77
|
-
e.button === 2 ||
|
|
78
|
-
(e.button === 0 && dragWithPrimary)
|
|
79
|
-
)
|
|
80
|
-
return changeDragging(true)
|
|
81
|
-
|
|
82
|
-
const projMouse = mat.applyToPoint(
|
|
83
|
-
mousePosition.current.x,
|
|
84
|
-
mousePosition.current.y
|
|
85
|
-
)
|
|
86
|
-
if (zoomWithPrimary && e.button === 0) {
|
|
87
|
-
changeZoomStart(projMouse)
|
|
88
|
-
changeZoomEnd(projMouse)
|
|
89
|
-
return
|
|
90
|
-
}
|
|
91
|
-
if (e.button === 0) {
|
|
92
|
-
if (specialEvent.type === "resize-box") {
|
|
93
|
-
// onResizeBox()
|
|
94
|
-
}
|
|
95
|
-
if (specialEvent.type === "move-region") {
|
|
96
|
-
// onResizeBox()
|
|
97
|
-
}
|
|
98
|
-
const { iw, ih } = layoutParams.current
|
|
99
|
-
onMouseDown({ x: projMouse.x / iw, y: projMouse.y / ih })
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
onMouseUp: (e) => {
|
|
103
|
-
e.preventDefault()
|
|
104
|
-
const projMouse = mat.applyToPoint(
|
|
105
|
-
mousePosition.current.x,
|
|
106
|
-
mousePosition.current.y
|
|
107
|
-
)
|
|
108
|
-
if (zoomStart) {
|
|
109
|
-
const zoomEnd = projMouse
|
|
110
|
-
if (
|
|
111
|
-
Math.abs(zoomStart.x - zoomEnd.x) < 10 &&
|
|
112
|
-
Math.abs(zoomStart.y - zoomEnd.y) < 10
|
|
113
|
-
) {
|
|
114
|
-
if (mat.a < 1) {
|
|
115
|
-
zoomIn({ to: 1 }, mousePosition.current)
|
|
116
|
-
} else {
|
|
117
|
-
zoomIn({ to: 0.25 }, mousePosition.current)
|
|
118
|
-
}
|
|
119
|
-
} else {
|
|
120
|
-
const { iw, ih } = layoutParams.current
|
|
121
|
-
|
|
122
|
-
if (zoomStart.x > zoomEnd.x) {
|
|
123
|
-
;[zoomStart.x, zoomEnd.x] = [zoomEnd.x, zoomStart.x]
|
|
124
|
-
}
|
|
125
|
-
if (zoomStart.y > zoomEnd.y) {
|
|
126
|
-
;[zoomStart.y, zoomEnd.y] = [zoomEnd.y, zoomStart.y]
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// The region defined by zoomStart and zoomEnd should be the new transform
|
|
130
|
-
let scale = Math.min(
|
|
131
|
-
(zoomEnd.x - zoomStart.x) / iw,
|
|
132
|
-
(zoomEnd.y - zoomStart.y) / ih
|
|
133
|
-
)
|
|
134
|
-
if (scale < 0.05) scale = 0.05
|
|
135
|
-
if (scale > 10) scale = 10
|
|
136
|
-
|
|
137
|
-
const newMat = getDefaultMat()
|
|
138
|
-
.translate(zoomStart.x, zoomStart.y)
|
|
139
|
-
.scaleU(scale)
|
|
140
|
-
|
|
141
|
-
changeMat(newMat.clone())
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
changeZoomStart(null)
|
|
145
|
-
changeZoomEnd(null)
|
|
146
|
-
}
|
|
147
|
-
if (
|
|
148
|
-
e.button === 1 ||
|
|
149
|
-
e.button === 2 ||
|
|
150
|
-
(e.button === 0 && dragWithPrimary)
|
|
151
|
-
)
|
|
152
|
-
return changeDragging(false)
|
|
153
|
-
if (e.button === 0) {
|
|
154
|
-
const { iw, ih } = layoutParams.current
|
|
155
|
-
onMouseUp({ x: projMouse.x / iw, y: projMouse.y / ih })
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
onWheel: (e) => {
|
|
159
|
-
const direction = e.deltaY > 0 ? 1 : e.deltaY < 0 ? -1 : 0
|
|
160
|
-
zoomIn(direction, mousePosition.current)
|
|
161
|
-
// e.preventDefault()
|
|
162
|
-
},
|
|
163
|
-
onContextMenu: (e) => {
|
|
164
|
-
e.preventDefault()
|
|
165
|
-
},
|
|
166
|
-
}
|
|
167
|
-
return { mouseEvents, mousePosition }
|
|
168
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// @flow weak
|
|
2
|
-
import useEventCallback from "use-event-callback"
|
|
3
|
-
import { getEnclosingBox } from "./region-tools.js"
|
|
4
|
-
|
|
5
|
-
export default ({ layoutParams, mat }) => {
|
|
6
|
-
return useEventCallback((r) => {
|
|
7
|
-
const { iw, ih } = layoutParams.current
|
|
8
|
-
const bbox = getEnclosingBox(r)
|
|
9
|
-
const margin = r.type === "point" ? 15 : 2
|
|
10
|
-
const cbox = {
|
|
11
|
-
x: bbox.x * iw - margin,
|
|
12
|
-
y: bbox.y * ih - margin,
|
|
13
|
-
w: bbox.w * iw + margin * 2,
|
|
14
|
-
h: bbox.h * ih + margin * 2,
|
|
15
|
-
}
|
|
16
|
-
const pbox = {
|
|
17
|
-
...mat.clone().inverse().applyToPoint(cbox.x, cbox.y),
|
|
18
|
-
w: cbox.w / mat.a,
|
|
19
|
-
h: cbox.h / mat.d,
|
|
20
|
-
}
|
|
21
|
-
return pbox
|
|
22
|
-
})
|
|
23
|
-
}
|