-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunction.js
More file actions
79 lines (63 loc) · 2.39 KB
/
Copy pathfunction.js
File metadata and controls
79 lines (63 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function drawKeypoints(ctx, points, color, label) {
// Draw top point
ctx.beginPath();
ctx.arc(points.top.x, points.top.y, 3, 0, 2 * Math.PI);
ctx.fillStyle = color;
ctx.fill();
// Draw bottom point
ctx.beginPath();
ctx.arc(points.bottom.x, points.bottom.y, 3, 0, 2 * Math.PI);
ctx.fillStyle = color;
ctx.fill();
// Draw connecting line
ctx.beginPath();
ctx.moveTo(points.top.x, points.top.y);
ctx.lineTo(points.bottom.x, points.bottom.y);
ctx.strokeStyle = color;
ctx.lineWidth = 2;
ctx.stroke();
// Draw label
ctx.font = '12px Arial';
ctx.fillText(label, points.top.x, points.top.y - 10);
}
function processSegmentVariations(imageData, partName) {
return new Promise((resolve) => {
worker.postMessage({
imageData: imageData.data,
partName: partName,
width: imageData.width,
height: imageData.height
});
worker.onmessage = function(e) {
const { type, extremePoints, averages, partName } = e.data;
// console.log('averages :>> ', averages);
// console.log('extremePoints :>> ', extremePoints);
const variations = [{
data: new Uint8ClampedArray(imageData.data),
extremePoints: extremePoints,
points: {}
}];
// Store points for averaging
if (!collectedPoints.has(partName)) {
collectedPoints.set(partName, []);
}
if (extremePoints && extremePoints.top) collectedPoints.get(partName).push(extremePoints.top);
if (extremePoints && extremePoints.bottom) collectedPoints.get(partName).push(extremePoints.bottom);
// Initialize points object with missing properties
Object.keys(BODY_PARTS).forEach(part => {
variations[0].points[part] = {
top: null,
bottom: null
};
});
// Assign the extreme points to the correct properties
if (extremePoints) {
variations[0].points[partName] = {
top: extremePoints.top,
bottom: extremePoints.bottom
};
}
resolve(variations);
};
});
}