Noursine commited on
Commit
faaf172
·
verified ·
1 Parent(s): 44bc78d

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +50 -0
index.html CHANGED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>SAM2 Interactive</title>
5
+ <style>
6
+ body { font-family: sans-serif; }
7
+ #canvas { border: 1px solid #ccc; cursor: crosshair; }
8
+ </style>
9
+ </head>
10
+ <body>
11
+ <h1>Interactive SAM2 Segmentation</h1>
12
+ <input type="file" id="upload" accept="image/*">
13
+ <canvas id="canvas"></canvas>
14
+ <script>
15
+ const canvas = document.getElementById("canvas");
16
+ const ctx = canvas.getContext("2d");
17
+ let img = new Image();
18
+
19
+ document.getElementById("upload").addEventListener("change", function(e) {
20
+ const file = e.target.files[0];
21
+ const reader = new FileReader();
22
+ reader.onload = function(evt) {
23
+ img.onload = function() {
24
+ canvas.width = img.width;
25
+ canvas.height = img.height;
26
+ ctx.drawImage(img, 0, 0);
27
+ }
28
+ img.src = evt.target.result;
29
+ }
30
+ reader.readAsDataURL(file);
31
+ });
32
+
33
+ canvas.addEventListener("contextmenu", e => e.preventDefault()); // disable default right-click menu
34
+
35
+ canvas.addEventListener("mousedown", function(e) {
36
+ const rect = canvas.getBoundingClientRect();
37
+ const x = Math.round(e.clientX - rect.left);
38
+ const y = Math.round(e.clientY - rect.top);
39
+
40
+ if (e.button === 0) {
41
+ console.log("Negative point:", x, y);
42
+ // send to backend with label=0
43
+ } else if (e.button === 2) {
44
+ console.log("Positive point:", x, y);
45
+ // send to backend with label=1
46
+ }
47
+ });
48
+ </script>
49
+ </body>
50
+ </html>