Skip to content

Commit 80e8e83

Browse files
committed
fix adding landmark annotation to video
1 parent 2df65df commit 80e8e83

File tree

3 files changed

+103
-57
lines changed

3 files changed

+103
-57
lines changed

src/Annotator/poses.story.js

Lines changed: 100 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -7,70 +7,114 @@ import { action as actionAddon } from "@storybook/addon-actions"
77
import dancingManImage from "../ImageCanvas/dancing-man.story.jpg"
88
import Annotator from "./"
99

10+
const dancingManVideo =
11+
"https://s3.us-east-1.amazonaws.com/asset.workaround.online/developer-samples/how-to-dab.mp4"
12+
1013
const middlewares = [
1114
(store) => (next) => (action) => {
1215
actionAddon(action.type)(action)
1316
return next(action)
1417
},
1518
]
1619

17-
storiesOf("Annotator (Poses)", module).add("Basic", () => (
18-
<Annotator
19-
onExit={actionAddon("onExit")}
20-
middlewares={middlewares}
21-
labelImages
22-
enabledTools={["create-keypoints"]}
23-
keypointDefinitions={{
24-
human: {
25-
connections: [
26-
["head", "sternum"],
27-
["sternum", "leftElbow"],
28-
["sternum", "rightElbow"],
29-
],
30-
landmarks: {
31-
head: {
32-
label: "Head",
33-
color: "#f00",
34-
defaultPosition: [0, -0.05],
35-
},
36-
sternum: {
37-
label: "Torso",
38-
color: "#0f0",
39-
defaultPosition: [0, 0],
40-
},
41-
leftElbow: {
42-
label: "Left Elbow",
43-
color: "#00f",
44-
defaultPosition: [-0.05, 0],
45-
},
46-
rightElbow: {
47-
label: "Right Elbow",
48-
color: "#00f",
49-
defaultPosition: [0.05, 0],
20+
storiesOf("Annotator (Poses)", module)
21+
.add("Image", () => (
22+
<Annotator
23+
onExit={actionAddon("onExit")}
24+
middlewares={middlewares}
25+
labelImages
26+
enabledTools={["create-keypoints"]}
27+
keypointDefinitions={{
28+
human: {
29+
connections: [
30+
["head", "sternum"],
31+
["sternum", "leftElbow"],
32+
["sternum", "rightElbow"],
33+
],
34+
landmarks: {
35+
head: {
36+
label: "Head",
37+
color: "#f00",
38+
defaultPosition: [0, -0.05],
39+
},
40+
sternum: {
41+
label: "Torso",
42+
color: "#0f0",
43+
defaultPosition: [0, 0],
44+
},
45+
leftElbow: {
46+
label: "Left Elbow",
47+
color: "#00f",
48+
defaultPosition: [-0.05, 0],
49+
},
50+
rightElbow: {
51+
label: "Right Elbow",
52+
color: "#00f",
53+
defaultPosition: [0.05, 0],
54+
},
5055
},
5156
},
52-
},
53-
}}
54-
images={[
55-
{
56-
src: dancingManImage,
57-
name: "Dancing Man",
58-
regions: [
59-
{
60-
type: "keypoints",
61-
id: "keypoints1",
62-
keypointsDefinitionId: "human",
63-
highlighted: true,
64-
points: {
65-
head: { x: 0.54, y: 0.2 },
66-
sternum: { x: 0.57, y: 0.3 },
67-
leftElbow: { x: 0.4, y: 0.39 },
68-
rightElbow: { x: 0.7, y: 0.32 },
57+
}}
58+
images={[
59+
{
60+
src: dancingManImage,
61+
name: "Dancing Man",
62+
regions: [
63+
{
64+
type: "keypoints",
65+
id: "keypoints1",
66+
keypointsDefinitionId: "human",
67+
highlighted: true,
68+
points: {
69+
head: { x: 0.54, y: 0.2 },
70+
sternum: { x: 0.57, y: 0.3 },
71+
leftElbow: { x: 0.4, y: 0.39 },
72+
rightElbow: { x: 0.7, y: 0.32 },
73+
},
74+
visible: true,
75+
},
76+
],
77+
},
78+
]}
79+
/>
80+
))
81+
.add("Video", () => (
82+
<Annotator
83+
onExit={actionAddon("onExit")}
84+
middlewares={middlewares}
85+
labelImages
86+
enabledTools={["create-box", "create-keypoints"]}
87+
videoSrc={dancingManVideo}
88+
keypointDefinitions={{
89+
human: {
90+
connections: [
91+
["head", "sternum"],
92+
["sternum", "leftElbow"],
93+
["sternum", "rightElbow"],
94+
],
95+
landmarks: {
96+
head: {
97+
label: "Head",
98+
color: "#f00",
99+
defaultPosition: [0, -0.05],
100+
},
101+
sternum: {
102+
label: "Torso",
103+
color: "#0f0",
104+
defaultPosition: [0, 0],
105+
},
106+
leftElbow: {
107+
label: "Left Elbow",
108+
color: "#00f",
109+
defaultPosition: [-0.05, 0],
110+
},
111+
rightElbow: {
112+
label: "Right Elbow",
113+
color: "#00f",
114+
defaultPosition: [0.05, 0],
69115
},
70-
visible: true,
71116
},
72-
],
73-
},
74-
]}
75-
/>
76-
))
117+
},
118+
}}
119+
/>
120+
))

src/Annotator/reducers/video-reducer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export default (state: MainLayoutVideoAnnotationState, action: Action) => {
5656
switch (action.type) {
5757
case "BEGIN_BOX_TRANSFORM":
5858
case "BEGIN_MOVE_POINT":
59+
case "BEGIN_MOVE_KEYPOINT":
5960
case "BEGIN_MOVE_POLYGON_POINT":
6061
case "ADD_POLYGON_POINT":
6162
case "SELECT_REGION":
@@ -68,6 +69,7 @@ export default (state: MainLayoutVideoAnnotationState, action: Action) => {
6869
case "create-point":
6970
case "create-polygon":
7071
case "create-box":
72+
case "create-keypoints":
7173
return copyImpliedRegions()
7274
default:
7375
break

src/RegionShapes/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const RegionComponents = {
7474
const midPoint = { x: (kp1.x + kp2.x) / 2, y: (kp1.y + kp2.y) / 2 }
7575

7676
return (
77-
<g key={`${kp1}.${kp2}`}>
77+
<g key={`${kp1.x},${kp1.y}.${kp2.x},${kp2.y}`}>
7878
<line
7979
x1={kp1.x * iw}
8080
y1={kp1.y * ih}

0 commit comments

Comments
 (0)