various fixes

This commit is contained in:
2022-09-16 12:25:36 +02:00
parent 6a7b5ab91e
commit ba4f5feecb
7 changed files with 141 additions and 87 deletions

View File

@@ -256,13 +256,13 @@ class geometry:
_log.debug('least square data:\nK:{}\nAA:{}'.format(K, AA))
@staticmethod
def autofocus(cam,mot,rng=(-1,1),n=30,saveImg=False):
def autofocus(cam,mot,rng=(-1,1),n=30,progressDlg=None,saveImg=False):
# cam camera object
# mot motor object
# mot motor object (e.g. SimMotorTweak)
# rng region (min max relative to current position) to seek
# n number of images to take in region
# roi region of interrest to calculate sharpness
# mode mode to calculate sharpness (sum/max-min/hist? of edge detection in roi)
# progressDlg a pg.ProgressDialog to allow to abort the function call
if mot is not None:
p0=mot.get_rbv()
else:
@@ -295,13 +295,19 @@ class geometry:
img=np.asarray(img)
else:
mot.move_abs(p, wait=True)
img=cam._pic # get_image()
img=cam.get_image() # get latest image
img16=np.array(img, np.int16)
msk=np.array(((1, 0, -1), (2, 0, -2), (1, 0, -1)), np.int16)
sb1=signal.convolve2d(img16, msk, mode='same', boundary='fill', fillvalue=0)
sb2=signal.convolve2d(img16, msk.T, mode='same', boundary='fill', fillvalue=0)
sb=np.abs(sb1)+np.abs(sb2)
mtr[i]=sb.sum()
try:
progressDlg+=1
if progressDlg.wasCanceled():
return
except TypeError as e:
pass
_log.debug(f'{i}/{p:.4g} -> {mtr[i]:.4g}')
mx=mtr.argmax()
@@ -333,8 +339,7 @@ class geometry:
img=PIL.Image.open(cam)
img=np.asarray(img)
else:
img=cam._pic # get_image()
img16=np.array(img, np.int16)
img=cam.get_image() # get latest image
fid=np.ones((sz[1]+2*brd[1],sz[0]+2*brd[0]),dtype=np.uint8)*255
fid[brd[1]:sz[1]+brd[1],brd[0]:sz[0]+brd[0]]=0