import json,cv2,numpy as np,sys,glob,os d=json.load(open('eval/labels/image6.json'));im=cv2.imread('add/image6.jpg') S=sys.argv[1] H=300 def tile(img,txt,col=(0,0,0)): h,w=img.shape[:2];s=H/h;img=cv2.resize(img,(max(1,int(w*s)),H)) pad=np.full((H+30,img.shape[1]+6,3),255,np.uint8);pad[30:,3:3+img.shape[1]]=img cv2.putText(pad,txt,(2,20),cv2.FONT_HERSHEY_SIMPLEX,0.5,col,1);return pad groups={} for f in d['facings']: x1,y1,x2,y2=f['box'];c=im[y1:y2,x1:x2] groups.setdefault(f['label'],[]).append(tile(c,f"#{f['index']}")) for lab,ts in groups.items(): ref=glob.glob(f'stock-lopia-clean/{lab}.jpg') row=([tile(cv2.imread(ref[0]),'REF',(0,0,255))] if ref else [])+ts rows=[row[i:i+12] for i in range(0,len(row),12)] out=[] for r in rows: w=sum(t.shape[1] for t in r);canvas=np.full((H+30,max(w,10),3),255,np.uint8);x=0 for t in r: canvas[:,x:x+t.shape[1]]=t;x+=t.shape[1] out.append(canvas) W=max(o.shape[1] for o in out);out=[np.pad(o,((0,0),(0,W-o.shape[1]),(0,0)),constant_values=255) for o in out] cv2.imwrite(f'{S}/gt_{lab}.jpg',np.vstack(out)) vis=im.copy() for f in d['facings']: x1,y1,x2,y2=f['box'];c=(0,0,255) if f['label']=='unknown' else (0,200,0) cv2.rectangle(vis,(x1,y1),(x2,y2),c,2);cv2.putText(vis,f"{f['index']}:{f['label'].replace('sku_','')}",(x1+2,y1+15),cv2.FONT_HERSHEY_SIMPLEX,0.45,c,1) cv2.imwrite(f'{S}/shelf_labels.jpg',vis)