Dynamsoft / barcode-reader-javascript

Dynamsoft Barcode Reader JavaScript SDK for package managers. PDF417, QR Code, DataMatrix, MaxiCode and more are supported.
https://www.dynamsoft.com/barcode-reader/sdk-javascript/
Other
169 stars 111 forks source link

getting barcode image marked with detection results #73

Closed bmabir17 closed 3 years ago

bmabir17 commented 3 years ago

I am trying to get results from image files using the Dynamsoft.DBR.BarcodeReader as follows

reader = reader || await Dynamsoft.DBR.BarcodeReader.createInstance();
let results = await reader.decode(this.files[0]);
let res_img = await reader.getIntermediateResults();

I am getting the results of the bar code as text. But i also want the image that is marked with the bar code location. would i be able to get that using getIntermediateResults(); method ?

Keillion commented 3 years ago

@bmabir17 oriCanvas saves the source image in a canvas. While you need to draw the barcode location yourself using localizationresult.

some sample code copied from BarcodeScanner:

ctx.fillStyle = this.barcodeFillStyle;
ctx.strokeStyle = this.barcodeStrokeStyle;
ctx.lineWidth = this.barcodeLineWidth;
results = results || [];
for(let result of results){
let loc = result.localizationResult;
  ctx.beginPath();
  ctx.moveTo(loc.x1, loc.y1);
  ctx.lineTo(loc.x2, loc.y2);
  ctx.lineTo(loc.x3, loc.y3);
  ctx.lineTo(loc.x4, loc.y4);
  ctx.fill();
  ctx.beginPath();
  ctx.moveTo(loc.x1, loc.y1);
  ctx.lineTo(loc.x2, loc.y2);
  ctx.lineTo(loc.x3, loc.y3);
  ctx.lineTo(loc.x4, loc.y4);
  ctx.closePath();
  ctx.stroke();
}