Spaces:
Build error
Build error
dillonlaird
commited on
Commit
·
4aea6da
1
Parent(s):
8f3faa9
added click to select instance
Browse files
instance-labeler/app/canvas.tsx
CHANGED
@@ -149,6 +149,32 @@ export default function Canvas({ imageUrl, imageName }: { imageUrl: string, imag
|
|
149 |
const pos = e.target.getStage()?.getPointerPosition();
|
150 |
if (!pos) return;
|
151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
let labels = labelsRef.current;
|
153 |
if (e.evt.button === 2) {
|
154 |
labels = [...labels, 0];
|
|
|
149 |
const pos = e.target.getStage()?.getPointerPosition();
|
150 |
if (!pos) return;
|
151 |
|
152 |
+
const height = image?.height ? image.height : 1024;
|
153 |
+
const width = image?.width ? image.width : 1024;
|
154 |
+
|
155 |
+
console.log(groupRef.current.length);
|
156 |
+
for (let i = 0; i < groupRef.current.length && i < classList.length; i++) {
|
157 |
+
if (groupRef.current[i].children?.length === 0) continue;
|
158 |
+
|
159 |
+
const elt = groupRef.current[i].children![0];
|
160 |
+
const canvas = elt.toCanvas() as HTMLCanvasElement;
|
161 |
+
const imageData = canvas.getContext('2d')?.getImageData(0, 0, width, height);
|
162 |
+
if (!imageData) continue;
|
163 |
+
const r = imageData.data[(pos.x + pos.y * width) * 4];
|
164 |
+
const g = imageData.data[(pos.x + pos.y * width) * 4 + 1];
|
165 |
+
const b = imageData.data[(pos.x + pos.y * width) * 4 + 2];
|
166 |
+
if (r > 0 || g > 0 || b > 0) {
|
167 |
+
if (selectedInstanceRef.current !== i) {
|
168 |
+
selectedInstanceRef.current = i;
|
169 |
+
setSelectedInstanceStyle(true);
|
170 |
+
} else {
|
171 |
+
selectedInstanceRef.current = -1;
|
172 |
+
setSelectedInstanceStyle(false);
|
173 |
+
}
|
174 |
+
return;
|
175 |
+
}
|
176 |
+
}
|
177 |
+
|
178 |
let labels = labelsRef.current;
|
179 |
if (e.evt.button === 2) {
|
180 |
labels = [...labels, 0];
|