This commit is contained in:
alexgobbo
2024-10-16 10:43:18 +02:00
parent 2c69347d7f
commit 83d83e84e7
19 changed files with 135 additions and 36 deletions

View File

@@ -46,7 +46,7 @@
"simpleEditor" : false,
"hideEditorLineNumbers" : false,
"hideEditorContextMenu" : false,
"consoleLocation" : "Status",
"consoleLocation" : "Plot",
"dataPanelLocation" : null,
"openDataFilesInDocTab" : false,
"noVariableEvaluationPropagation" : false,

View File

@@ -1,4 +1,4 @@
#Fri Sep 20 10:59:23 CEST 2024
#Tue Oct 15 10:20:20 CEST 2024
barcode_reader_scan_pucks=false
beamline_status_enabled=false
cold_position_timeout=3600
@@ -7,7 +7,7 @@ dry_timestamp=1.69564645367E9
force_dry_mount_count=4
force_dry_timeout=27000
imaging_enabled=true
led_level=0.0
led_level=100.0
pin_cleaner_timer=60
pin_offset=-0.0
puck_types=true

View File

@@ -1,21 +1,24 @@
#Fri Sep 20 10:59:27 CEST 2024
center_x=917.0
center_y=1015.0
#Wed Oct 16 10:41:00 CEST 2024
center_x=1019.0
center_y=1052.0
continuous=false
correlation_threshold=0.0
diam_dewar=null
diam_disk=null
diam_target=null
diameter_target=95
diameter_dewar=1800
diameter_disk=670
diameter_target=100
diamter_dewar=1800
diamter_disk=670
mask_dewar=null
mask_disk=null
max_detect_offset=10
modulo=3
number_images=2
modulo=2
number_images=1
offset_threshold=null
open_strategy=both
rotation_degrees=0.0
scale_x=0.3
scale_y=0.3
size_mask_dewar=0.98

View File

@@ -1,4 +1,4 @@
#Fri Sep 20 09:24:26 CEST 2024
#Wed Oct 16 10:43:18 CEST 2024
colormap=Grayscale
colormapAutomatic=true
colormapLogarithmic=false
@@ -14,7 +14,7 @@ roiHeight=-1
roiWidth=-1
roiX=0
roiY=0
rotation=0.0
rotation=90.0
rotationCrop=false
scale=1.0
spatialCalOffsetX=NaN

View File

@@ -1,4 +1,5 @@
#Tue Jun 19 16:41:28 CEST 2018
#Mon Sep 23 10:42:00 CEST 2024
description=null
maxValue=180.0
minValue=-180.0
offset=0.0

View File

@@ -1,4 +1,5 @@
#Tue Jun 19 16:41:28 CEST 2018
#Mon Sep 23 10:42:00 CEST 2024
description=null
maxValue=127.5
minValue=-127.5
offset=0.0

View File

@@ -1,4 +1,5 @@
#Tue Jun 19 16:41:28 CEST 2018
#Mon Sep 23 10:42:00 CEST 2024
description=null
maxValue=152.5
minValue=-152.5
offset=0.0

View File

@@ -1,4 +1,5 @@
#Tue Jun 19 16:41:28 CEST 2018
#Mon Sep 23 10:42:00 CEST 2024
description=null
maxValue=270.0
minValue=-270.0
offset=0.0

View File

@@ -1,4 +1,5 @@
#Tue Jun 19 16:41:28 CEST 2018
#Mon Sep 23 10:42:00 CEST 2024
description=null
maxValue=132.5
minValue=-122.5
offset=0.0

View File

@@ -1,4 +1,5 @@
#Fri Aug 24 14:56:42 CEST 2018
#Mon Sep 23 10:42:00 CEST 2024
description=null
maxValue=400.0
minValue=-400.0
offset=0.0

View File

@@ -1,4 +1,5 @@
#Tue Jun 19 16:41:28 CEST 2018
#Mon Sep 23 10:42:00 CEST 2024
description=null
maxValue=180.0
minValue=-180.0
offset=0.0

View File

@@ -1,4 +1,5 @@
#Tue Jun 19 16:41:28 CEST 2018
#Mon Sep 23 10:42:00 CEST 2024
description=null
maxValue=180.0
minValue=-180.0
offset=0.0

View File

@@ -1,4 +1,5 @@
#Tue Jun 19 16:41:28 CEST 2018
#Mon Sep 23 10:42:00 CEST 2024
description=null
maxValue=360.0
minValue=-360.0
offset=0.0

View File

@@ -1,4 +1,5 @@
#Tue Jun 19 16:41:28 CEST 2018
#Mon Sep 23 10:42:00 CEST 2024
description=null
maxValue=1000.0
minValue=-1000.0
offset=0.0

View File

@@ -1,4 +1,5 @@
#Tue Jun 19 16:41:28 CEST 2018
#Mon Sep 23 10:42:00 CEST 2024
description=null
maxValue=1000.0
minValue=-1000.0
offset=0.0

View File

@@ -1,4 +1,5 @@
#Tue Jun 19 16:41:28 CEST 2018
#Mon Sep 23 10:42:00 CEST 2024
description=null
maxValue=1000.0
minValue=-1000.0
offset=0.0

View File

@@ -11,10 +11,11 @@ class CoverDetectionConfig(RegisterConfig):
self.center_y = 570.0
self.scale_x = 1.0
self.scale_y = 1.0
self.rotation_degrees = 0.0
self.correlation_threshold = 0.60
self.diameter_target=95
self.diamter_disk=670
self.diamter_dewar=1800
self.diameter_disk=670
self.diameter_dewar=1800
self.size_mask_disk=0.8
self.size_mask_dewar=0.98
self.max_detect_offset=10
@@ -106,7 +107,7 @@ class CoverDetection(ReadonlyAsyncRegisterBase, ReadonlyRegisterArray):
self.error = None
center = (self.config.center_x, self.config.center_y)
x,y = detect(ip, center, \
diam_target=self.config.diameter_target, diam_disk= self.config.diamter_disk, diam_dewar=self.config.diamter_dewar, \
diam_target=self.config.diameter_target, diam_disk= self.config.diameter_disk, diam_dewar=self.config.diameter_dewar, \
mask_disk=self.config.size_mask_disk, mask_dewar=self.config.size_mask_dewar, \
offset_threshold=self.config.max_detect_offset ,open_strategy= self.config.open_strategy)
@@ -131,6 +132,28 @@ class CoverDetection(ReadonlyAsyncRegisterBase, ReadonlyRegisterArray):
if not self.config.continuous:
self.images=[]
def calculate_factors(self, x1, y1, x2, y2, mx1, my1, mx2, my2):
dx = x2-x1
dy = y2-y1
dmx = mx2-mx1
dmy = my2-my1
sx = dmx/dx
sy = dmy / dy
tp=math.atan(dy/dx)
tm=math.atan(dmy/dmx)
t = tm - tp
return sx, sy, math.degrees(t)
def pixel_to_millis(self, x, y):
try:
t = math.radians(self.config.rotation_degrees)
offx, offy = x-self.config.center_x, y-self.config.center_y
rx, ry = (offx * math.cos(t) + offy * math.sin(t)), (-offx * math.sin(t) + offy * math.cos(t))
mx, my = self.config.scale_x*rx, self.config.scale_y*ry
return round(mx,3), round(my,3)
except:
return float('nan'), float('nan')
def set(self, x, y, tm, error):
if self.enabled:
@@ -138,9 +161,9 @@ class CoverDetection(ReadonlyAsyncRegisterBase, ReadonlyRegisterArray):
self.offset_px = self.offset_um = None
value = None
else:
offx, offy = x-cover_detection.config.center_x, -(y-cover_detection.config.center_y)
offx, offy = x-self.config.center_x, y-self.config.center_y
self.offset_px = opx, opy = round(offx), round(offy)
self.offset_um = omx, omy = self.config.scale_x * offx * 1000.0, self.config.scale_y * offy *1000.0
self.offset_um = omx, omy = self.pixel_to_millis(x,y)
value = to_array([x, y, opx, opy, omx, omy, tm], 'i')
self.onReadout(value)
if self.renderer is not None:

View File

@@ -32,10 +32,28 @@ def rms_error(ip1, ip2):
def get_roi_img(img, img_size=1024, radius=800, offset_x=0, offset_y=0):
def clear_dc(img, width=2):
img = load_image(img.getBufferedImage())
ip=img.getProcessor()
w, h = ip.getWidth(), ip.getHeight()
mask = ip.createProcessor(w, h) # Creates a new blank ImageProcessor
mask.setColor(255) # Set the drawing color to white (255)
o=width/2
mask.fillRect(0, 0,(w/2)-o,(h/2)-o)
mask.fillRect(0, int(h/2)+o,(w/2)-o,(h/2)-o)
mask.fillRect(int(w/2)+o,0,(w/2)-o,(h/2)-o)
mask.fillRect(int(w/2)+o, int(h/2)+o,(w/2)-o,(h/2)-o)
mask.autoThreshold() # Ensures the mask is binary (if needed)
ip.copyBits(mask, 0, 0, Blitter.AND) # Apply the mask using a bitwise AND
return img
def _get_roi_img(img, img_size=1024, radius=800, offset_x=0, offset_y=0):
x,y,w,h = int(cover_detection.config.center_x-img_size/2 + offset_x), \
int(cover_detection.config.center_y-img_size/2 + offset_y), \
img_size, img_size
img_size, img_size
roi = ImagingUtils.copy(img, None, Rectangle(x,y,w,h))
ip = load_image(roi, title="Img")
p = ip.getProcessor()
@@ -49,6 +67,17 @@ def get_roi_img(img, img_size=1024, radius=800, offset_x=0, offset_y=0):
p.blurGaussian(1.0)
return ip.getBufferedImage()
def get_roi_img(img, offset_x=0, offset_y=0):
img = ImagingUtils.copy(img, None, None)
center = cover_detection.config.center_x, cover_detection.config.center_y
#radius = cover_detection.config.diameter_dewar*(cover_detection.config.size_mask_dewar/2.0)
radius = cover_detection.config.diameter_dewar*0.45
ip = load_image(img, title="Img")
p = ip.getProcessor()
set_circle_mask(p, center_x=center[0], center_y=center[1],radius=radius)
p.translate(offset_x, offset_y)
return ip.getBufferedImage()
def get_edge_img(ib):
ed = ImagingUtils.edgeDetect(ib)
ret = load_image(ed, title="Refe")
@@ -57,9 +86,18 @@ def get_edge_img(ib):
return ret
def save_ref_img(img):
path = os.path.abspath(expand_path("{images}/ip_ref_fe.png"))
global ip_ref_fe
path = os.path.abspath(expand_path("{images}/ip_ref.png"))
roi=get_roi_img(img, offset_x=0, offset_y=0)
ImageBuffer.saveImage(roi, path, "png")
path = os.path.abspath(expand_path("{images}/ip_ref_e.png"))
ip_ref_e =get_edge_img(roi)
ImageBuffer.saveImage(ip_ref_e.getBufferedImage(), path, "png")
path = os.path.abspath(expand_path("{images}/ip_ref_fe.png"))
ip_ref_fe = image_fft(ip_ref_e)
ImageBuffer.saveImage(ip_ref_fe.getBufferedImage(), path, "png")
#ip_ref = load_image(roi, title="ip_ref")
#save_image(ip_ref, path ,"png")
@@ -72,20 +110,21 @@ def save_ref_img(img):
def put_mark(ib):
for x in range(450, 470):
for y in range(450, 470):
for x in range(700,750):
for y in range(650, 700):
ib.setRGB(x,y, 0)
def get_correlation(img):
global ip_ref_fe
if "ip_ref_fe" not in globals() or ip_ref_fe is None:
path = os.path.abspath(expand_path("{images}/ip_ref_fe.png"))
path = os.path.abspath(expand_path("{images}/ip_ref.png"))
roi = ImagingUtils.newImage(path)
#ip_ref_fe=open_imagroie(path+"ip_ref_fe.png" ,"png")
#ip_ref = load_image(roi, title="ip_ref")
ip_ref_e =get_edge_img(roi)
ip_ref_fe = image_fft(ip_ref_e)
print "Opend reference image"
#ip_ref_fe = clear_dc(ip_ref_fe)
print "Opened reference image"
roi =get_roi_img(img, offset_x=-offset, offset_y=-offset)
if add_mark:
@@ -94,6 +133,7 @@ def get_correlation(img):
ip_cur_e =get_edge_img(roi)
#ip_cur_f = image_fft(ip_cur)
ip_cur_fe = image_fft(ip_cur_e)
return correlator.getCorrelation(ip_ref_fe, ip_cur_fe)[0]
#ip_cur_fe = clear_dc(ip_cur_fe)
return max(correlator.getCorrelation(ip_ref_fe, ip_cur_fe)[0], 0.0)

View File

@@ -0,0 +1,21 @@
x1, y1 = 1678, 365
x2, y2 = 416, 1641
mx1, my1 = 210.2, -210.2
mx2, my2 = -210.2, 210.2
print cover_detection.calculate_factors(x1, y1, x2, y2, mx1, my1, mx2, my2)
x1,y1 = cover_detection.config.center_x, cover_detection.config.center_y
x2, y2 = 1678, 365
mx1, my1 = 0.0, 0.0
mx2, my2 = 210.2, -210.2
print cover_detection.calculate_factors(x1, y1, x2, y2, mx1, my1, mx2, my2)