17 lines
2.2 KiB
JavaScript
17 lines
2.2 KiB
JavaScript
// Developer-only, explicit manual glyph labels from calibration images. Never imported by the application.
|
|
import {readFileSync as read,writeFileSync as write} from 'node:fs';
|
|
import {gunzipSync} from 'node:zlib';
|
|
import {readNumber} from '../colorBlock-level-editor/src/local-vision.js';
|
|
const root=new URL('../colorBlock-level-editor/',import.meta.url),frame=i=>{const base=`test/fixtures/local-vision/level17/shot${i}`;return {...JSON.parse(read(new URL(base+'.json',root))),data:new Uint8ClampedArray(gunzipSync(read(new URL(base+'.rgba.gz',root))))};};
|
|
const templates=[],provenance=[];
|
|
const regions=[
|
|
[0,'24',[480,440,130,80]], [0,'17',[225,599,110,65]], [0,'16',[495,599,100,65]], [0,'5',[180,940,65,75]], [0,'5',[380,938,65,74]], [0,'19',[665,790,100,80]], [0,'6',[695,1070,70,90]],
|
|
[2,'8',[495,345,70,75]], [3,'7',[470,325,70,70]],
|
|
[0,'0220',[325,215,190,70],true],[1,'0203',[280,115,190,65],true],[2,'0141',[315,123,190,65],true],[3,'0125',[290,103,185,60],true],[4,'0057',[285,90,185,65],true]
|
|
];
|
|
for(const [index,label,[x,y,w,h],bright=false]of regions){const f=frame(index),result=readNumber(f,{x,y,w,h},{minHeight:25,maxHeight:75,bright,allLines:true});if(result.digits.length!==label.length)throw Error(`manual label ${label}: got ${result.digits.length} boxes`);
|
|
for(let i=0;i<label.length;i++){const b=result.digits[i].box,rows=[];for(let y=0;y<32;y++){let row='';for(let x=0;x<24;x++){const px=Math.min(f.width-1,b.x+Math.floor((x+.5)*b.w/24)),py=Math.min(f.height-1,b.y+Math.floor((y+.5)*b.h/32)),p=(py*f.width+px)*4,[r,g,v]=f.data.slice(p,p+3);row+=(bright?r>215&&g>215&&v>210:r<85&&g<110&&v<165)?'1':'0';}rows.push(row);}templates.push({digit:label[i],family:bright?'capture-timer':'capture-ice',aspect:b.w/b.h,rows});provenance.push({frame:index,label:label[i],family:bright?'capture-timer':'capture-ice',box:b});}
|
|
}
|
|
write(new URL('src/vision/capture-digit-templates.js',root),'// Explicitly labeled calibration glyphs; no board geometry or level counters.\nexport const CAPTURE_DIGIT_TEMPLATES='+JSON.stringify(templates)+';\n');
|
|
write(new URL('test/fixtures/local-vision/level17/glyph-calibration.json',root),JSON.stringify(provenance,null,2)+'\n');console.log(`${templates.length} manually labeled glyphs`);
|