Subh775 commited on
Commit
f5a1a7f
·
verified ·
1 Parent(s): b79a53d

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +16 -17
index.html CHANGED
@@ -281,7 +281,6 @@
281
  const ratio = Math.min(hRatio, vRatio);
282
  canvas.width = img.width * ratio;
283
  canvas.height = img.height * ratio;
284
- ctx.clearRect(0, 0, canvas.width, canvas.height);
285
  ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
286
  }
287
 
@@ -369,14 +368,16 @@
369
  this.currentView = view;
370
  document.querySelectorAll('.output-tabs .tool-btn').forEach(b => b.classList.remove('active'));
371
  document.getElementById(`view-${view}`).classList.add('active');
372
- this.transparencyControl.style.display = (view === 'filled' || view === 'outline') ? 'block' : 'none';
373
  this.renderOutput();
374
  }
375
 
376
  renderOutput() {
377
- if (!this.predictedMask) return;
 
 
 
378
 
379
- // Always draw the original image on the output canvas first
380
  this.outputCtx.clearRect(0,0, this.outputCanvas.width, this.outputCanvas.height);
381
  this.drawImageScaled(this.outputCanvas, this.outputCtx, this.uploadedImage);
382
 
@@ -385,7 +386,6 @@
385
  return;
386
  }
387
 
388
- // Create a temporary canvas to work with the mask for filled/outline views
389
  const tempCanvas = document.createElement('canvas');
390
  const tempCtx = tempCanvas.getContext('2d');
391
  tempCanvas.width = this.outputCanvas.width;
@@ -403,24 +403,23 @@
403
 
404
  } else if (this.currentView === 'outline') {
405
  const src = cv.imread(tempCanvas);
 
 
 
 
406
  const contours = new cv.MatVector();
407
  const hierarchy = new cv.Mat();
408
- cv.cvtColor(src, src, cv.COLOR_RGBA2GRAY, 0);
409
  cv.findContours(src, contours, hierarchy, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE);
410
 
411
- this.outputCtx.strokeStyle = 'white';
412
- this.outputCtx.lineWidth = 2;
413
  for (let i = 0; i < contours.size(); ++i) {
414
- const contour = contours.get(i).data32S;
415
- this.outputCtx.beginPath();
416
- this.outputCtx.moveTo(contour[0], contour[1]);
417
- for (let j = 2; j < contour.length; j += 2) {
418
- this.outputCtx.lineTo(contour[j], contour[j+1]);
419
- }
420
- this.outputCtx.closePath();
421
- this.outputCtx.stroke();
422
  }
423
- src.delete(); contours.delete(); hierarchy.delete();
 
 
 
 
424
  }
425
  }
426
 
 
281
  const ratio = Math.min(hRatio, vRatio);
282
  canvas.width = img.width * ratio;
283
  canvas.height = img.height * ratio;
 
284
  ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
285
  }
286
 
 
368
  this.currentView = view;
369
  document.querySelectorAll('.output-tabs .tool-btn').forEach(b => b.classList.remove('active'));
370
  document.getElementById(`view-${view}`).classList.add('active');
371
+ this.transparencyControl.style.display = (view === 'filled') ? 'block' : 'none';
372
  this.renderOutput();
373
  }
374
 
375
  renderOutput() {
376
+ if (!this.predictedMask) {
377
+ this.outputCtx.clearRect(0, 0, this.outputCanvas.width, this.outputCanvas.height);
378
+ return;
379
+ }
380
 
 
381
  this.outputCtx.clearRect(0,0, this.outputCanvas.width, this.outputCanvas.height);
382
  this.drawImageScaled(this.outputCanvas, this.outputCtx, this.uploadedImage);
383
 
 
386
  return;
387
  }
388
 
 
389
  const tempCanvas = document.createElement('canvas');
390
  const tempCtx = tempCanvas.getContext('2d');
391
  tempCanvas.width = this.outputCanvas.width;
 
403
 
404
  } else if (this.currentView === 'outline') {
405
  const src = cv.imread(tempCanvas);
406
+ cv.cvtColor(src, src, cv.COLOR_RGBA2GRAY, 0);
407
+
408
+ // Create a transparent mat to draw contours on
409
+ let contourImg = cv.Mat.zeros(src.rows, src.cols, cv.CV_8UC4);
410
  const contours = new cv.MatVector();
411
  const hierarchy = new cv.Mat();
 
412
  cv.findContours(src, contours, hierarchy, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE);
413
 
414
+ const color = new cv.Scalar(255, 255, 255, 255); // White color
 
415
  for (let i = 0; i < contours.size(); ++i) {
416
+ cv.drawContours(contourImg, contours, i, color, 2, cv.LINE_8, hierarchy, 0);
 
 
 
 
 
 
 
417
  }
418
+
419
+ // Draw the contours over the original image
420
+ this.outputCtx.drawImage(contourImg, 0, 0, this.outputCanvas.width, this.outputCanvas.height);
421
+
422
+ src.delete(); contours.delete(); hierarchy.delete(); contourImg.delete();
423
  }
424
  }
425