From 1681426f9e465e726c7813d03be6ae612b80e095 Mon Sep 17 00:00:00 2001 From: Sanjay Rohith Date: Mon, 5 Feb 2024 22:15:38 +0530 Subject: [PATCH] ISS --- dat/0a.json | 19 +---------- script/fetchphotos.js | 76 +++++++++++++++++++++++++++++++++++++++++++ test.html | 5 +++ 3 files changed, 82 insertions(+), 18 deletions(-) diff --git a/dat/0a.json b/dat/0a.json index 31e0a57..e5d906a 100644 --- a/dat/0a.json +++ b/dat/0a.json @@ -1,20 +1,3 @@ { - "max": 3, - "S7227U7777777": [ - "true", - "01", - "Sanjay Rohith", - "IMG001" - ], - "S7156U8363664": [ - "false", - "02", - "Bhrath", - "IMG005" - ], - "S3702": [ - "true", - "03", - "STUDENT NAME 3" - ] + "max":0 } \ No newline at end of file diff --git a/script/fetchphotos.js b/script/fetchphotos.js index 7297cb2..75009d3 100644 --- a/script/fetchphotos.js +++ b/script/fetchphotos.js @@ -4,6 +4,82 @@ imgel.id="imgel" imgel.src=direc var imgcon = document.getElementById('imgcont'); imgcon.appendChild(imgel); + +var image = document.getElementById('image'); +var canvas = document.getElementById('canvas'); +var ctx = canvas.getContext("2d"); +canvas.width = image.width; +canvas.height = image.height; +ctx.drawImage(image, + 0, 0, image.width, image.height, + 0, 0, canvas.width, canvas.height); + +const scale = canvas.width / image.width; + +function detect() { + if (window.BarcodeDetector == undefined) { + var footer = document.getElementsByTagName('footer')[0]; + footer.innerHTML = "Barcode Detection not supported"; + console.error('Barcode Detection not supported'); + return; + } + + var barcodeDetector = new BarcodeDetector(); + barcodeDetector.detect(image) + .then(barcodes => { + // Draw the boxes on the . + var ctx = document.getElementById('canvas').getContext("2d"); + ctx.beginPath(); + ctx.lineWidth = 2; + ctx.strokeStyle = "red"; + for(var i = 0; i < barcodes.length; i++) { + ctx.rect(Math.floor(barcodes[i].boundingBox.x * scale), + Math.floor(barcodes[i].boundingBox.y * scale), + Math.floor(barcodes[i].boundingBox.width * scale), + Math.floor(barcodes[i].boundingBox.height * scale)); + ctx.stroke(); + } + ctx.closePath(); + + ctx.beginPath(); + ctx.strokeStyle = "yellow"; + for(var i = 0; i < barcodes.length; i++) { + ctx.moveTo(Math.floor(barcodes[i].cornerPoints[0].x * scale), + Math.floor(barcodes[i].cornerPoints[0].y * scale)); + ctx.lineTo(Math.floor(barcodes[i].cornerPoints[1].x * scale), + Math.floor(barcodes[i].cornerPoints[1].y * scale)); + ctx.lineTo(Math.floor(barcodes[i].cornerPoints[2].x * scale), + Math.floor(barcodes[i].cornerPoints[2].y * scale)); + ctx.lineTo(Math.floor(barcodes[i].cornerPoints[3].x * scale), + Math.floor(barcodes[i].cornerPoints[3].y * scale)); + ctx.lineTo(Math.floor(barcodes[i].cornerPoints[0].x * scale), + Math.floor(barcodes[i].cornerPoints[0].y * scale)); + ctx.stroke(); + } + ctx.closePath(); + + // Add the barcodes as strings to the