This commit is contained in:
gac-S_Changer
2018-06-14 17:33:20 +02:00
parent 086e8f347e
commit 70a11a6e39
25 changed files with 612 additions and 363 deletions

View File

@@ -34,14 +34,14 @@ class RobotSC(RobotTCP):
def get_dewar(self, segment, puck, sample):
segment = self.toSegmentNumber(segment)
self.start_task('getDewar',segment, puck, sample)
self.start_task('getDewar',segment, puck, sample, is_room_temp())
self.wait_task_finished(TASK_WAIT_ROBOT_POLLING)
self.assert_dewar()
def put_dewar(self, segment, puck, sample):
segment = self.toSegmentNumber(segment)
self.assert_dewar()
self.start_task('putDewar',segment, puck, sample)
self.start_task('putDewar',segment, puck, sample, is_room_temp())
self.wait_task_finished(TASK_WAIT_ROBOT_POLLING)
self.assert_dewar()

View File

@@ -1,4 +1,5 @@
LED_LEVEL_ROOM_TEMPERATURE = 0.4
LED_LEVEL_LN2 = 1.0
"""
@@ -67,7 +68,7 @@ def set_led_range(room_temp = True):
"""
Led range should be limitted in room temperature
"""
max_val = 0.40 if room_temp else 1.20
max_val = LED_LEVEL_ROOM_TEMPERATURE if room_temp else LED_LEVEL_LN2
led_ctrl_1.config.maxValue = max_val
led_ctrl_1.config.save()
led_ctrl_2.config.maxValue = max_val
@@ -87,7 +88,7 @@ def set_led_range(room_temp = True):
def is_led_room_temp():
return led_ctrl_1.config.maxValue <= 0.50
return led_ctrl_1.config.maxValue <= LED_LEVEL_ROOM_TEMPERATURE

View File

@@ -1,7 +1,8 @@
import ch.psi.pshell.device.Camera as Camera
import ch.psi.pshell.imaging.RendererMode as RendererMode
import ch.psi.pshell.imaging.Calibration as Calibration
from ch.psi.pshell.imaging.Overlays import *
#SIMULATION = ch.psi.pshell.imaging.FileSource
"""
img.camera.setColorMode(Camera.ColorMode.Mono)
img.camera.setDataType(Camera.DataType.UInt8)
@@ -11,61 +12,132 @@ img.camera.setExposure(50.00)
img.camera.setAcquirePeriod(200.00)
img.camera.setGain(0.0)
img.config.rotationCrop=True
"""
#img.camera.setROI(200, 0,1200,1200)
img.camera.setROI(0, 0,1600,1200)
MOVE_HEXIPOSI = True
if MOVE_HEXIPOSI:
enable_motion()
sensor_width,sensor_height = img.camera.getSensorSize()
img.camera.setROI(0, 0,sensor_width, sensor_height)
img.config.rotation=0
img.config.roiX,img.config.roiY, img.config.roiWidth,img.config.roiHeight =0,0,-1,-1
img.config.setCalibration(None)
img.camera.stop()
img.camera.start()
#img.camera.setROI(300, 200,1000,1000)
#img.config.rotation=17
#img.config.roiX,img.config.roiY, img.config.roiWidth,img.config.roiHeight = 50,50,900,900
p = show_panel(img)
p.setMode(RendererMode.Fit)
ov_text = Text(Pen(java.awt.Color.GREEN.darker()), "", java.awt.Font("Verdana", java.awt.Font.PLAIN, 24), java.awt.Point(20,20))
ov_text.setFixed(True)
p.addOverlay(ov_text)
try:
ov_text.update("Click on upper reference...")
p1 = p.waitClick(60000)
print p1
ov_text.update("Click on left reference...")
p2 = p.waitClick(60000)
print p2
ov_text.update("Click on right reference...")
p3 = p.waitClick(60000)
print p3
x, y, z = p1.x+p1.y*1j, p2.x+p2.y*1j, p3.x+p3.y*1j
w = z-x
w /= y-x
c = (x-y)*(w-abs(w)**2)/2j/w.imag-x
cx, cy, r = -c.real, -c.imag, abs(c+x)
a = math.degrees(math.atan((cx-p1.x)/(p1.y-cy)))
print cx, cy, r, a
#img.camera.setROI(int((1600-cx)/2),int((1200-cy)/2),1000,1000)
img.camera.setROI(int(cx-r),int(cy-r),int(2*r),int(2*r))
img.config.rotation=-a
#remove rotation border
d=int(r/11)
img.config.roiX,img.config.roiY, img.config.roiWidth,img.config.roiHeight =d,d, int(2*r-2*d), int(2*r-2*d)
#img.config.setCalibration(None)
#Find image center and Prosilica ROI
ov_text.update("Click on the center of the Dewar...")
p.refresh()
dc = p.waitClick(60000)
print dc
width, height = min(dc.x, sensor_width-dc.x)*2, min(dc.y, sensor_height-dc.y)*2
width, height = width - width%16, height - height%16
width, height = min(width,1000), min(height,1000)
print width, height
roi_x = int(dc.x- width/2)
roi_y = int(dc.y- height/2)
roi_w = int(width)
roi_h = int(height)
set_setting("roi_x", roi_x)
set_setting("roi_y", roi_y)
set_setting("roi_w", roi_w)
set_setting("roi_h", roi_h)
img.camera.setROI(roi_x, roi_y, width, height)
except:
img.camera.setROI(int(get_setting("roi_x")), int(get_setting("roi_y")), int(get_setting("roi_w")), int(get_setting("roi_h")))
finally:
img.camera.stop()
img.camera.start()
img.camera.start()
#Configure source
CC4 = (-129.9, -150)
CD5 = (129.9, -150)
CA5 = (-129.9, 150)
CF4 = (129.9, 150)
DX = 259.8
DY = 300.0
ROI_X = 470.0
ROI_Y = 470.0
def rotate(x,y, degrees):
rotation = math.radians(degrees)
rw, rh = img.getImage().getWidth(), img.getImage().getHeight()
ox, oy = x - (rw / 2), y - (rh / 2)
x = ox * math.cos(rotation) - oy * math.sin(rotation) + rw / 2;
y = oy * math.cos(rotation) + ox * math.sin(rotation) + rh / 2;
return x,y
set_led_state(True)
try:
if MOVE_HEXIPOSI: set_hexiposi("C")
ov_text.update("Click on the center of C4 (19) position...")
p.refresh()
pc4 = p.waitClick(60000)
print pc4
if MOVE_HEXIPOSI: set_hexiposi("D")
ov_text.update("Click on the center of D5 (13) position...")
p.refresh()
pd5 = p.waitClick(60000)
print pd5
if MOVE_HEXIPOSI: set_hexiposi("F")
ov_text.update("Click on the center of F4 (04) position...")
p.refresh()
pf4 = p.waitClick(60000)
print pf4
if MOVE_HEXIPOSI: set_hexiposi("A")
ov_text.update("Click on the center of A5 (28) position...")
p.refresh()
pa5 = p.waitClick(60000)
print pa5
vc1x, vc1y, vc2x, vc2y = (pc4.x + pd5.x )/2.0, (pc4.y + pd5.y )/2.0, (pa5.x + pf4.x )/2.0, (pa5.y + pf4.y )/2.0
hc1x, hc1y, hc2x, hc2y = (pc4.x + pa5.x )/2.0, (pc4.y + pa5.y )/2.0, (pd5.x + pf4.x )/2.0, (pd5.y + pf4.y )/2.0
cx, cy = (vc1x + vc2x)/2, (hc1y + hc2y)/2
a1 = math.degrees(math.atan((cx-vc1x)/(vc1y-cy)))
a2 = math.degrees(math.atan((cx-vc2x)/(vc2y-cy)))
a = (a1+a2)/2
dy = math.hypot(vc2y - vc1y, vc2x - vc1x)
dx = math.hypot(hc2x - hc1x, hc2y - hc1y)
print dy, dx, cx, cy
sx, sy = DX/dx, DY/dy
#Rotating center of puck
rcx, rcy = rotate(cx, cy, -a)
roi_w, roi_h = int(ROI_X / sx), int(ROI_Y / sy)
roi_x, roi_y = int(rcx-roi_w/2), int(rcy-roi_h/2)
print a, sx, sy, roi_w, roi_h
img.config.rotation=-a
img.config.roiX,img.config.roiY, img.config.roiWidth,img.config.roiHeight = roi_x, roi_y, roi_w, roi_h
img.config.setCalibration(Calibration(sx, sy, -roi_w/2, -roi_h/2))
img.config.save()
finally:
set_led_state(False)
p.removeOverlay(ov_text)
img.refresh()

View File

@@ -1,136 +0,0 @@
import ch.psi.pshell.device.Camera as Camera
import ch.psi.pshell.imaging.RendererMode as RendererMode
import ch.psi.pshell.imaging.Calibration as Calibration
from ch.psi.pshell.imaging.Overlays import *
SIMULATION = ch.psi.pshell.imaging.FileSource
"""
img.camera.setColorMode(Camera.ColorMode.Mono)
img.camera.setDataType(Camera.DataType.UInt8)
img.camera.setGrabMode(Camera.GrabMode.Continuous)
img.camera.setTriggerMode(Camera.TriggerMode.Fixed_Rate)
img.camera.setExposure(50.00)
img.camera.setAcquirePeriod(200.00)
img.camera.setGain(0.0)
img.config.rotationCrop=True
"""
sensor_width,sensor_height = img.camera.getSensorSize()
img.camera.setROI(0, 0,sensor_width, sensor_height)
img.config.rotation=0
img.config.roiX,img.config.roiY, img.config.roiWidth,img.config.roiHeight =0,0,-1,-1
img.config.setCalibration(None)
img.camera.stop()
img.camera.start()
p = show_panel(img)
p.setMode(RendererMode.Fit)
ov_text = Text(Pen(java.awt.Color.GREEN.darker()), "", java.awt.Font("Verdana", java.awt.Font.PLAIN, 24), java.awt.Point(20,20))
ov_text.setFixed(True)
p.addOverlay(ov_text)
try:
#Find image center and Prosilica ROI
ov_text.update("Click on the center of the Dewar...")
p.refresh()
dc = p.waitClick(60000)
print dc
width, height = min(dc.x, sensor_width-dc.x)*2, min(dc.y, sensor_height-dc.y)*2
width, height = width - width%16, height - height%16
width, height = min(width,1000), min(height,1000)
print width, height
roi_x = int(dc.x- width/2)
roi_y = int(dc.y- height/2)
roi_w = int(width)
roi_h = int(height)
set_setting("roi_x", roi_x)
set_setting("roi_y", roi_y)
set_setting("roi_w", roi_w)
set_setting("roi_h", roi_h)
img.camera.setROI(roi_x, roi_y, width, height)
except:
img.camera.setROI(int(get_setting("roi_x")), int(get_setting("roi_y")), int(get_setting("roi_w")), int(get_setting("roi_h")))
finally:
img.camera.stop()
img.camera.start()
#Configure source
CC4 = (-129.9, -150)
CD5 = (129.9, -150)
CA5 = (-129.9, 150)
CF4 = (129.9, 150)
DX = 259.8
DY = 300.0
ROI_X = 470.0
ROI_Y = 470.0
def rotate(x,y, degrees):
rotation = math.radians(degrees)
rw, rh = img.getImage().getWidth(), img.getImage().getHeight()
ox, oy = x - (rw / 2), y - (rh / 2)
x = ox * math.cos(rotation) - oy * math.sin(rotation) + rw / 2;
y = oy * math.cos(rotation) + ox * math.sin(rotation) + rh / 2;
return x,y
set_led_state(True)
try:
ov_text.update("Click on the center of C4 (19) position...")
p.refresh()
pc4 = p.waitClick(60000)
print pc4
ov_text.update("Click on the center of D5 (13) position...")
p.refresh()
pd5 = p.waitClick(60000)
print pd5
ov_text.update("Click on the center of A5 (28) position...")
p.refresh()
pa5 = p.waitClick(60000)
print pa5
ov_text.update("Click on the center of F4 (04) position...")
p.refresh()
pf4 = p.waitClick(60000)
print pf4
vc1x, vc1y, vc2x, vc2y = (pc4.x + pd5.x )/2.0, (pc4.y + pd5.y )/2.0, (pa5.x + pf4.x )/2.0, (pa5.y + pf4.y )/2.0
hc1x, hc1y, hc2x, hc2y = (pc4.x + pa5.x )/2.0, (pc4.y + pa5.y )/2.0, (pd5.x + pf4.x )/2.0, (pd5.y + pf4.y )/2.0
cx, cy = (vc1x + vc2x)/2, (hc1y + hc2y)/2
a1 = math.degrees(math.atan((cx-vc1x)/(vc1y-cy)))
a2 = math.degrees(math.atan((cx-vc2x)/(vc2y-cy)))
a = (a1+a2)/2
dy = math.hypot(vc2y - vc1y, vc2x - vc1x)
dx = math.hypot(hc2x - hc1x, hc2y - hc1y)
print dy, dx, cx, cy
sx, sy = DX/dx, DY/dy
#Rotating center of puck
rcx, rcy = rotate(cx, cy, -a)
roi_w, roi_h = int(ROI_X / sx), int(ROI_Y / sy)
roi_x, roi_y = int(rcx-roi_w/2), int(rcy-roi_h/2)
print a, sx, sy, roi_w, roi_h
img.config.rotation=-a
img.config.roiX,img.config.roiY, img.config.roiWidth,img.config.roiHeight = roi_x, roi_y, roi_w, roi_h
img.config.setCalibration(Calibration(sx, sy, -roi_w/2, -roi_h/2))
img.config.save()
finally:
set_led_state(False)
p.removeOverlay(ov_text)
img.refresh()

View File

@@ -1,116 +1,77 @@
###################################################################################################
# Procedure to detect the cover orientation
###################################################################################################
import ch.psi.pshell.imaging.Utils.integrateVertically as integrateVertically
img.backgroundEnabled=False
REF = (0,96,125)
#Parameters
FRAMES_INTEGRATION = 3
STEP_SIZE = 2
POSITION_NAMES = [ 'A','B','C','D', 'E', 'F']
POSITION_ANGLES = [330, 30, 90, 150, 210, 270]
POSITION_TOLERANCE = 3
MINIMUM_CONFIDENCE = 10
DEBUG = cover_detection_debug
REFERENCE_IMG = "ref2"
line = load_image("{images}/line.png", title="Line")
#line = load_image("{images}/line360.png", title="Line")
#Load reference image
ref = load_image(str("{images}/cover/" + REFERENCE_IMG + ".png") , title="Line")
line.getProcessor().setBackgroundValue(0.0)
#ip = get_image()
ip = integrate_frames(10)
#Pre-process camera image
#ip = load_image("{images}/cover/Cover_000" + str(index) + ".png", title="Img")
ip = integrate_frames(FRAMES_INTEGRATION)
ip = grayscale(ip, True)
smooth(ip)
#bandpass_filter(ip, 30, 1000)
edges(ip)
#invert(ip)
#auto_threshold(ip, method = "Default")
#auto_threshold(ip, method = "Li")
auto_threshold(ip, method = "MaxEntropy")
cx,cy = int(ip.width/2), int(ip.height/2)
ip = sub_image(ip, cx-ref.width/2, cy-ref.height/2, ref.width, ref.height)
"""
for m in AutoThresholder.getMethods():
print m
aux = ip.duplicate()
auto_threshold(aux, method = m)
binary_fill_holes(aux, dark_background=False)
renderer = show_panel(aux.bufferedImage)
time.sleep(1.0)
"""
#binary_dilate(ip, dark_background=False)
#binary_fill_holes(ip, dark_background=False)
#binary_open(ip, dark_background=Tr)
renderer = show_panel(ip.bufferedImage)
#Show ROI of pre-processed image
if DEBUG:
image_panel = show_panel(ip.bufferedImage)
#line = sub_image(line, 325, 325, 512, 512)
#ip = sub_image(ip, 325, 325, 512, 512)
line = sub_image(line, 453, 453, 256, 256)
ip = sub_image(ip, 453, 453, 256, 256)
#op = op_fft(ip, line, "correlate")
renderer = show_panel(ip.bufferedImage)
#renderer = show_panel(op.bufferedImage)
#line.show()
#Calculate correlation between image and reference, rotating the reference from 0 to 360
import ch.psi.pshell.imaging.Utils.integrateVertically as integrateVertically
ydata = []
xdata = range (0,180,1)
xdata = range (0,360,STEP_SIZE)
for i in xdata:
l = line.duplicate()
l.getProcessor().setBackgroundValue(0.0)
l.getProcessor().rotate(float(i))
op = op_fft(ip, l, "correlate")
r = ref.duplicate()
r.getProcessor().setBackgroundValue(0.0)
r.getProcessor().rotate(float(i))
op = op_fft(r, ip, "correlate")
bi = op.getBufferedImage()
p = integrateVertically(bi)
ydata.append(sum(p))
#renderer = show_panel(op.bufferedImage)
#time.sleep(0.001)
def moving_average(arr, n) :
ret = []
for i in range(len(arr)):
ret.append(mean(arr[max(i-n,0):min(i+n,len(arr)-1)]))
return ret
av = moving_average(ydata, 1)
p = plot(ydata, xdata=xdata)[0]
p.addSeries(LinePlotSeries("Moving Average"))
p.getSeries(1).setData(xdata, av)
#Calculate angle of the highest correlation, and confidence level
peaks = estimate_peak_indexes(ydata, xdata, (min(ydata) + max(ydata))/2, 25.0)
left, right = min(peaks), max(peaks)
if xdata[left]<5 and xdata[right]>(xdata[-1]-5):
#del peaks[0 if ydata[right] > ydata[left] else -1]
peaks.remove(right if ydata[right] > ydata[left] else left)
peaks = sorted(peaks[:3])
peaks_x = map(lambda x:xdata[x], peaks)
peaks_y = map(lambda x:ydata[x], peaks)
confidence = None if len(peaks_x)<2 else int(((float(peaks_y[0])/peaks_y[1])-1) * 1000)
angle = (None if len(peaks_x)==0 else peaks_x[0])
#From angle and confidence level estimate hexiposi position
position = None
if angle is not None:
for i in range(len(POSITION_NAMES)):
if abs(POSITION_ANGLES[i] - angle) <= POSITION_TOLERANCE:
position = POSITION_NAMES[i]
print "Peaks", peaks
print "Peak indexes: " + str(peaks_x)
print "Peak values: " + str(peaks_y)
#Plot the correlations values agains angle
if DEBUG:
p = plot(ydata, xdata=xdata)[0]
#Output results
if DEBUG:
print "Peaks", peaks
print "Peak indexes: " + str(peaks_x)
print "Peak values: " + str(peaks_y)
print "Angle: " , angle
print "Position: " , position
print "Confidence: " , confidence
for i in range(len(peaks)):
peak = xdata[peaks[i]]
p.addMarker(peak, None, "N="+str(round(peak,2)), Color(80,0,80))
if ((peaks[i]>160) and (REF[i]<20)):
peaks[i] = peaks[i] - 180.0
#Set return value
set_return ([position, angle, confidence])
print "Peaks x: " + str(peaks_x)
d = mean(arrabs(arrsub(REF, peaks_x)))
print "Angle = ", d

View File

@@ -1,77 +0,0 @@
###################################################################################################
# Procedure to detect the cover orientation
###################################################################################################
#Parameters
FRAMES_INTEGRATION = 3
STEP_SIZE = 2
POSITION_NAMES = [ 'A','B','C','D', 'E', 'F']
POSITION_ANGLES = [330, 30, 90, 150, 210, 270]
POSITION_TOLERANCE = 3
MINIMUM_CONFIDENCE = 10
DEBUG = cover_detection_debug
REFERENCE_IMG = "ref2"
#Load reference image
ref = load_image(str("{images}/cover/" + REFERENCE_IMG + ".png") , title="Line")
#Pre-process camera image
#ip = load_image("{images}/cover/Cover_000" + str(index) + ".png", title="Img")
ip = integrate_frames(FRAMES_INTEGRATION)
ip = grayscale(ip, True)
smooth(ip)
#bandpass_filter(ip, 30, 1000)
edges(ip)
auto_threshold(ip, method = "MaxEntropy")
cx,cy = int(ip.width/2), int(ip.height/2)
ip = sub_image(ip, cx-ref.width/2, cy-ref.height/2, ref.width, ref.height)
#Show ROI of pre-processed image
if DEBUG:
image_panel = show_panel(ip.bufferedImage)
#Calculate correlation between image and reference, rotating the reference from 0 to 360
import ch.psi.pshell.imaging.Utils.integrateVertically as integrateVertically
ydata = []
xdata = range (0,360,STEP_SIZE)
for i in xdata:
r = ref.duplicate()
r.getProcessor().setBackgroundValue(0.0)
r.getProcessor().rotate(float(i))
op = op_fft(r, ip, "correlate")
bi = op.getBufferedImage()
p = integrateVertically(bi)
ydata.append(sum(p))
#Calculate angle of the highest correlation, and confidence level
peaks = estimate_peak_indexes(ydata, xdata, (min(ydata) + max(ydata))/2, 25.0)
peaks_x = map(lambda x:xdata[x], peaks)
peaks_y = map(lambda x:ydata[x], peaks)
confidence = None if len(peaks_x)<2 else int(((float(peaks_y[0])/peaks_y[1])-1) * 1000)
angle = (None if len(peaks_x)==0 else peaks_x[0])
#From angle and confidence level estimate hexiposi position
position = None
if angle is not None:
for i in range(len(POSITION_NAMES)):
if abs(POSITION_ANGLES[i] - angle) <= POSITION_TOLERANCE:
position = POSITION_NAMES[i]
#Plot the correlations values agains angle
if DEBUG:
p = plot(ydata, xdata=xdata)[0]
#Output results
if DEBUG:
print "Peaks", peaks
print "Peak indexes: " + str(peaks_x)
print "Peak values: " + str(peaks_y)
print "Angle: " , angle
print "Position: " , position
print "Confidence: " , confidence
#Set return value
set_return ([position, angle, confidence])

View File

@@ -3,7 +3,7 @@
###################################################################################################
COVER_PRESENT = True
ROOM_TEMP = False
ROOM_TEMP = is_room_temp()
if get_exec_pars().source == CommandSource.ui:
PLOT = None
@@ -41,11 +41,13 @@ time.sleep(led_latency)
img.waitNext(2000)
background = average_frames(number_backgrounds)
#background = integrate_frames(number_backgrounds)
set_led_state(True)
time.sleep(led_latency)
img.waitNext(2000)
image = average_frames(number_frames)
#image = integrate_frames(number_frames)
set_led_state(False)

View File

@@ -12,7 +12,7 @@ import java.awt.Rectangle as Rectangle
def get_img_cover_pos():
[position, angle, confidence] = run("imgproc/CoverDetection2")
[position, angle, confidence] = run("imgproc/CoverDetection")
return position
def assert_img_in_cover_pos(pos = None):

View File

@@ -69,6 +69,12 @@ def check_puck_detection():
def stop_puck_detection():
run("tools/StopPuckDetection")
DEWAR_LEVEL_RT = 5.0
def is_room_temp():
return dewar_level.read() <= DEWAR_LEVEL_RT
###################################################################################################
# Device initialization
###################################################################################################

View File

@@ -40,6 +40,13 @@ def set_hexiposi(pos, force = False):
else:
hexiposi.move(pos)
#Can be used if cover has following error (no checking readback)
def _set_hexiposi(pos):
hexiposi.moveAsync(pos)
time.sleep(1.0)
hexiposi.waitReady(-1)
def visual_check_hexiposi(segment):
#if robot.working_mode == "manual" ?
if hexiposi.moved:

View File

@@ -0,0 +1,71 @@
import ch.psi.pshell.device.Camera as Camera
import ch.psi.pshell.imaging.RendererMode as RendererMode
from ch.psi.pshell.imaging.Overlays import *
"""
img.camera.setColorMode(Camera.ColorMode.Mono)
img.camera.setDataType(Camera.DataType.UInt8)
img.camera.setGrabMode(Camera.GrabMode.Continuous)
img.camera.setTriggerMode(Camera.TriggerMode.Fixed_Rate)
img.camera.setExposure(50.00)
img.camera.setAcquirePeriod(200.00)
img.camera.setGain(0.0)
img.config.rotationCrop=True
"""
#img.camera.setROI(200, 0,1200,1200)
img.camera.setROI(0, 0,1600,1200)
img.config.rotation=0
img.config.roiX,img.config.roiY, img.config.roiWidth,img.config.roiHeight =0,0,-1,-1
img.config.setCalibration(None)
img.camera.stop()
img.camera.start()
#img.camera.setROI(300, 200,1000,1000)
#img.config.rotation=17
#img.config.roiX,img.config.roiY, img.config.roiWidth,img.config.roiHeight = 50,50,900,900
p = show_panel(img)
p.setMode(RendererMode.Fit)
ov_text = Text(Pen(java.awt.Color.GREEN.darker()), "", java.awt.Font("Verdana", java.awt.Font.PLAIN, 24), java.awt.Point(20,20))
ov_text.setFixed(True)
p.addOverlay(ov_text)
try:
ov_text.update("Click on upper reference...")
p1 = p.waitClick(60000)
print p1
ov_text.update("Click on left reference...")
p2 = p.waitClick(60000)
print p2
ov_text.update("Click on right reference...")
p3 = p.waitClick(60000)
print p3
x, y, z = p1.x+p1.y*1j, p2.x+p2.y*1j, p3.x+p3.y*1j
w = z-x
w /= y-x
c = (x-y)*(w-abs(w)**2)/2j/w.imag-x
cx, cy, r = -c.real, -c.imag, abs(c+x)
a = math.degrees(math.atan((cx-p1.x)/(p1.y-cy)))
print cx, cy, r, a
#img.camera.setROI(int((1600-cx)/2),int((1200-cy)/2),1000,1000)
img.camera.setROI(int(cx-r),int(cy-r),int(2*r),int(2*r))
img.config.rotation=-a
#remove rotation border
d=int(r/11)
img.config.roiX,img.config.roiY, img.config.roiWidth,img.config.roiHeight =d,d, int(2*r-2*d), int(2*r-2*d)
#img.config.setCalibration(None)
img.camera.stop()
img.camera.start()
finally:
p.removeOverlay(ov_text)

View File

@@ -0,0 +1,116 @@
###################################################################################################
# Procedure to detect the cover orientation
###################################################################################################
import ch.psi.pshell.imaging.Utils.integrateVertically as integrateVertically
img.backgroundEnabled=False
REF = (0,96,125)
line = load_image("{images}/line.png", title="Line")
#line = load_image("{images}/line360.png", title="Line")
line.getProcessor().setBackgroundValue(0.0)
#ip = get_image()
ip = integrate_frames(10)
ip = grayscale(ip, True)
smooth(ip)
#bandpass_filter(ip, 30, 1000)
edges(ip)
#invert(ip)
#auto_threshold(ip, method = "Default")
#auto_threshold(ip, method = "Li")
auto_threshold(ip, method = "MaxEntropy")
"""
for m in AutoThresholder.getMethods():
print m
aux = ip.duplicate()
auto_threshold(aux, method = m)
binary_fill_holes(aux, dark_background=False)
renderer = show_panel(aux.bufferedImage)
time.sleep(1.0)
"""
#binary_dilate(ip, dark_background=False)
#binary_fill_holes(ip, dark_background=False)
#binary_open(ip, dark_background=Tr)
renderer = show_panel(ip.bufferedImage)
#line = sub_image(line, 325, 325, 512, 512)
#ip = sub_image(ip, 325, 325, 512, 512)
line = sub_image(line, 453, 453, 256, 256)
ip = sub_image(ip, 453, 453, 256, 256)
#op = op_fft(ip, line, "correlate")
renderer = show_panel(ip.bufferedImage)
#renderer = show_panel(op.bufferedImage)
#line.show()
ydata = []
xdata = range (0,180,1)
for i in xdata:
l = line.duplicate()
l.getProcessor().setBackgroundValue(0.0)
l.getProcessor().rotate(float(i))
op = op_fft(ip, l, "correlate")
bi = op.getBufferedImage()
p = integrateVertically(bi)
ydata.append(sum(p))
#renderer = show_panel(op.bufferedImage)
#time.sleep(0.001)
def moving_average(arr, n) :
ret = []
for i in range(len(arr)):
ret.append(mean(arr[max(i-n,0):min(i+n,len(arr)-1)]))
return ret
av = moving_average(ydata, 1)
p = plot(ydata, xdata=xdata)[0]
p.addSeries(LinePlotSeries("Moving Average"))
p.getSeries(1).setData(xdata, av)
peaks = estimate_peak_indexes(ydata, xdata, (min(ydata) + max(ydata))/2, 25.0)
left, right = min(peaks), max(peaks)
if xdata[left]<5 and xdata[right]>(xdata[-1]-5):
#del peaks[0 if ydata[right] > ydata[left] else -1]
peaks.remove(right if ydata[right] > ydata[left] else left)
peaks = sorted(peaks[:3])
peaks_x = map(lambda x:xdata[x], peaks)
peaks_y = map(lambda x:ydata[x], peaks)
print "Peaks", peaks
print "Peak indexes: " + str(peaks_x)
print "Peak values: " + str(peaks_y)
for i in range(len(peaks)):
peak = xdata[peaks[i]]
p.addMarker(peak, None, "N="+str(round(peak,2)), Color(80,0,80))
if ((peaks[i]>160) and (REF[i]<20)):
peaks[i] = peaks[i] - 180.0
print "Peaks x: " + str(peaks_x)
d = mean(arrabs(arrsub(REF, peaks_x)))
print "Angle = ", d

View File

@@ -7,7 +7,7 @@ pa = []
#index = i+1
for i in ['A', 'B', 'C', 'D', 'E', 'F']:
hexiposi.move(i)
[position, angle, confidence] = run("imgproc/CoverDetection2")
[position, angle, confidence] = run("imgproc/CoverDetection")
print [position, angle, confidence]
pa.append(position)
aa.append(angle)