Add uniform Yangmi framing candidate for code37
This commit is contained in:
@@ -12,9 +12,9 @@ def bilinear(image,x,y):
|
||||
fx=(x-ix)[...,None];fy=(y-iy)[...,None]
|
||||
return (image[iy,ix]*(1-fx)+image[iy,jx]*fx)*(1-fy)+(image[jy,ix]*(1-fx)+image[jy,jx]*fx)*fy
|
||||
|
||||
def golden(body,patch,x,y,opacity,w,h,crop):
|
||||
def golden(body,patch,x,y,opacity,w,h,crop,zoom=1,center_y=.5):
|
||||
bh,bw=body.shape[:2]
|
||||
scale=min(w/bw,h/bh);left=(w-bw*scale)/2;top=(h-bh*scale)/2
|
||||
scale=min(w/bw,h/bh)*zoom;left=(w-bw*scale)/2;top=h/2-bh*scale*center_y
|
||||
yy,xx=np.mgrid[:h,:w];px=(xx+.5-left)/scale;py=(yy+.5-top)/scale
|
||||
inside=(px>=0)&(px<bw)&(py>=0)&(py<bh)
|
||||
bx=px*(.98 if crop else 1)+(bw*.01 if crop else 0)-.5
|
||||
@@ -29,7 +29,9 @@ def golden(body,patch,x,y,opacity,w,h,crop):
|
||||
|
||||
def main():
|
||||
parser=argparse.ArgumentParser(description=__doc__);parser.add_argument('--runtime',type=Path);parser.add_argument('--synthetic-shape',choices=['480x848','720x1280'],default='720x1280');parser.add_argument('--output',type=Path,required=True)
|
||||
parser.add_argument('--zoom',type=float,default=1);parser.add_argument('--center-y',type=float,default=.5)
|
||||
args=parser.parse_args();args.output.mkdir(parents=True,exist_ok=True)
|
||||
assert 1<=args.zoom<=2 and .4<=args.center_y<=.6
|
||||
m=json.loads((args.runtime/'manifest.json').read_text()) if args.runtime else None
|
||||
bw,bh=(m['body']['width'],m['body']['height']) if m else map(int,args.synthetic_shape.split('x'))
|
||||
source=(ROOT/'app/src/main/java/com/gorios/lanvoice/avatar/ContinuousBodyRenderer.kt').read_text()
|
||||
@@ -43,14 +45,14 @@ def main():
|
||||
env=dict(os.environ,EGL_PLATFORM='surfaceless',LIBGL_ALWAYS_SOFTWARE='1')
|
||||
def check(body,patch,x,y,opacity,w,h,label,crop=0):
|
||||
(tmp/'body.rgba').write_bytes(body.tobytes());(tmp/'patch.rgba').write_bytes(patch.tobytes())
|
||||
p=subprocess.run([str(tmp/'golden'),str(tmp/'vertex'),str(tmp/'fragment'),str(tmp/'body.rgba'),str(tmp/'patch.rgba'),str(tmp/'out.rgba'),str(patch.shape[1]),str(patch.shape[0]),str(x),str(y),str(opacity),str(w),str(h),str(crop),str(body.shape[1]),str(body.shape[0])],env=env,capture_output=True,text=True)
|
||||
p=subprocess.run([str(tmp/'golden'),str(tmp/'vertex'),str(tmp/'fragment'),str(tmp/'body.rgba'),str(tmp/'patch.rgba'),str(tmp/'out.rgba'),str(patch.shape[1]),str(patch.shape[0]),str(x),str(y),str(opacity),str(w),str(h),str(crop),str(body.shape[1]),str(body.shape[0]),str(args.zoom),str(args.center_y)],env=env,capture_output=True,text=True)
|
||||
assert p.returncode==0,p.stderr
|
||||
actual=np.frombuffer((tmp/'out.rgba').read_bytes(),np.uint8).reshape(h,w,4)[::-1,:,:3]
|
||||
expected=golden(body,patch,x,y,opacity,w,h,crop);diff=np.abs(actual.astype(int)-expected.astype(int))
|
||||
row={'case':label,'maxAbsRGB':int(diff.max()),'meanAbsRGB':float(diff.mean()),'viewport':[w,h],'bodyShape':[body.shape[1],body.shape[0]],'bodyTransformCrop':crop,'gl':p.stdout.strip()}
|
||||
expected=golden(body,patch,x,y,opacity,w,h,crop,args.zoom,args.center_y);diff=np.abs(actual.astype(int)-expected.astype(int))
|
||||
row={'case':label,'maxAbsRGB':int(diff.max()),'meanAbsRGB':float(diff.mean()),'viewport':[w,h],'bodyShape':[body.shape[1],body.shape[0]],'bodyTransformCrop':crop,'zoom':args.zoom,'centerY':args.center_y,'gl':p.stdout.strip()}
|
||||
results.append(row)
|
||||
assert diff.max()<=2,row
|
||||
if opacity==0 and w==body.shape[1] and h==body.shape[0] and not crop:assert np.array_equal(actual,body[:,:,:3]),'Level0 must be exact decoded body'
|
||||
if opacity==0 and w==body.shape[1] and h==body.shape[0] and not crop and args.zoom==1 and args.center_y==.5:assert np.array_equal(actual,body[:,:,:3]),'Level0 must be exact decoded body'
|
||||
if label=='frame43-level2':Image.fromarray(actual[94:150,193:263]).resize((560,448)).save(args.output/'gles-frame43-level2-mouth.png')
|
||||
yy,xx=np.mgrid[:bh,:bw];body=np.empty((bh,bw,4),np.uint8)
|
||||
body[:,:,0]=xx%256;body[:,:,1]=yy%256;body[:,:,2]=((xx//16+yy//16)%2)*255;body[:,:,3]=255
|
||||
|
||||
Reference in New Issue
Block a user