From 8413a64914b90af9c5897d99c08cd0f6eb27fc53 Mon Sep 17 00:00:00 2001 From: sfop Date: Thu, 18 Aug 2016 17:45:11 +0200 Subject: [PATCH] Closedown --- config/devices.properties | 2 +- script/ImageStats.py | 52 ++++++++++++++++++++++++++++++--------- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/config/devices.properties b/config/devices.properties index cbfd229..46fd5e4 100755 --- a/config/devices.properties +++ b/config/devices.properties @@ -14,4 +14,4 @@ gun_phase=ch.psi.pshell.epics.Positioner|SINEG01-RSYS:SET-BEAM-PHASE SINEG01-RSY #rf_phase_rb=ch.psi.pshell.epics.ChannelDouble|MINSB03-RSYS:GET-VSUM-PHASE|Read||true #rf_ampl_rb=ch.psi.pshell.epics.ChannelDouble|MINSB03-RSYS:GET-VSUM-AMPLT|Read||true image=ch.psi.pshell.imaging.FileSource|/afs/psi.ch/intranet/SF/Applications/config/pshell_op/context/beam.jpg||| -cam=ch.psi.pshell.epics.AreaDetector|SINEG01-DSCR190||| +#cam=ch.psi.pshell.epics.AreaDetector|SINEG01-DSCR190||| diff --git a/script/ImageStats.py b/script/ImageStats.py index 195924c..894e1a8 100644 --- a/script/ImageStats.py +++ b/script/ImageStats.py @@ -1,16 +1,16 @@ from ijutils import * from ch.psi.pshell.imaging.Overlays import * import ch.psi.pshell.imaging.Pen as Pen +import random -def wait_next(): - camera.waitNext(250) def get_centroid(source): - bi = source.getImage() + bi = source.getImage() if bi is None: return None op = show_panel(bi, "Original") - ip = load_image(bi) + ip = load_image(bi) + plot(get_histogram(ip)) grayscale(ip) invert(ip) gaussian_blur(ip) @@ -30,6 +30,33 @@ def get_centroid(source): + +import ch.psi.pshell.imaging.Filter as Filter + +class SimulatedSource(Filter): + def process(self, img, data): + self.img=img + if img is None: + return None + ip = load_image(img) + pad_h = int((random.random()-0.5) * 20) + pad_v = int((random.random()-0.5) * 20) + ip = pad_image(ip, -pad_h, pad_h, pad_v, -pad_v, fill_color = Color.BLACK) + return ip.getBufferedImage() + #return img + + def waitNext(self, timeout): + #self.pushImage(self.process(self.img,None)) + self.process(self.img, None) + print "---> " , self.getImage() + + +simulated_source = SimulatedSource() +simulated_source.img=None +simulated_source.initialize() +image.addListener(simulated_source) + + class ImageStats(DeviceBase): def __init__(self, name, source): DeviceBase.__init__(self, name) @@ -60,11 +87,13 @@ class ImageStats(DeviceBase): self.initialize() - def doUpdate(self): + def doUpdate(self): self.com_x_samples, self.com_y_samples = [], [] for i in range(self.num_images): - self.source.waitNext(2000) - centroid = get_centroid(self.source) + if type(self.source) is not ch.psi.pshell.imaging.FileSource: + self.source.waitNext(3000) + centroid = get_centroid(self.source) + print "cent ", centroid if centroid is not None: self.com_x_samples.append(centroid[0]) self.com_y_samples.append(centroid[1]) @@ -82,12 +111,13 @@ class ImageStats(DeviceBase): pass if __name__ == "__builtin__": - print get_centroid(image) + print get_centroid(simulated_source) + show_panel(simulated_source) - add_device(ImageStats("image_stats", image), True) + add_device(ImageStats("image_stats", simulated_source), True) image_stats.enableBackground(False) - for i in range (100): + for i in range (1): image_stats.update() - print camera_tool.take(), camera_tool.com_x_mean.read(), camera_tool.com_y_mean.read() + print image_stats.take(), image_stats.com_x_mean.read(), image_stats.com_y_mean.read()