This commit is contained in:
@@ -2,6 +2,9 @@ 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 *
|
||||
import ch.psi.utils.swing.SwingUtils as SwingUtils
|
||||
import javax.swing.SwingUtilities as SwingUtilities
|
||||
from swingutils.threads.swing import callSwing
|
||||
#SIMULATION = ch.psi.pshell.imaging.FileSource
|
||||
"""
|
||||
img.camera.setColorMode(Camera.ColorMode.Mono)
|
||||
@@ -15,9 +18,10 @@ img.config.rotationCrop=True
|
||||
"""
|
||||
|
||||
MOVE_HEXIPOSI = True
|
||||
ROTATION_OFFSET = 180.0
|
||||
|
||||
if MOVE_HEXIPOSI:
|
||||
enable_motion()
|
||||
release_safety() #enable_motion()
|
||||
|
||||
sensor_width,sensor_height = img.camera.getSensorSize()
|
||||
img.camera.setROI(0, 0,sensor_width, sensor_height)
|
||||
@@ -29,11 +33,17 @@ img.camera.start()
|
||||
|
||||
|
||||
p = show_panel(img)
|
||||
dlg = SwingUtilities.getWindowAncestor(p)
|
||||
dlg.setSize(800,800)
|
||||
frm=SwingUtils.getFrame(p)
|
||||
dlg.setLocationRelativeTo(frm)
|
||||
|
||||
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...")
|
||||
@@ -130,10 +140,12 @@ try:
|
||||
|
||||
print a, sx, sy, roi_w, roi_h
|
||||
|
||||
img.config.rotation=-a
|
||||
img.config.rotation=-a + ROTATION_OFFSET
|
||||
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()
|
||||
|
||||
set_return ("Success calibrating the camera")
|
||||
|
||||
finally:
|
||||
set_led_state(False)
|
||||
|
||||
@@ -6,11 +6,15 @@
|
||||
FRAMES_INTEGRATION = 3
|
||||
STEP_SIZE = 2
|
||||
POSITION_NAMES = [ 'A','B','C','D', 'E', 'F']
|
||||
POSITION_ANGLES = [330, 30, 90, 150, 210, 270]
|
||||
|
||||
#POSITION_ANGLES = [ 330, 30, 90, 150, 210, 270 ]
|
||||
POSITION_ANGLES = [ 0, 60, 120, 180, 240, 300 ]
|
||||
POSITION_TOLERANCE = 3
|
||||
MINIMUM_CONFIDENCE = 10
|
||||
MINIMUM_CONFIDENCE = 3
|
||||
DEBUG = cover_detection_debug
|
||||
REFERENCE_IMG = "ref2"
|
||||
#REFERENCE_IMG = "ref2"
|
||||
REFERENCE_IMG = "ref1"
|
||||
BORDER = 7
|
||||
|
||||
#Load reference image
|
||||
ref = load_image(str("{images}/cover/" + REFERENCE_IMG + ".png") , title="Line")
|
||||
@@ -23,9 +27,16 @@ smooth(ip)
|
||||
#bandpass_filter(ip, 30, 1000)
|
||||
edges(ip)
|
||||
auto_threshold(ip, method = "MaxEntropy")
|
||||
#binary_erode(ip, False)
|
||||
#binary_dilate(ip, True)
|
||||
ip.getProcessor().erode(1, 255)
|
||||
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)
|
||||
|
||||
if BORDER>0:
|
||||
sip = sub_image(ip, BORDER,BORDER, ref.width-2*BORDER, ref.height-2*BORDER)
|
||||
ip = pad_image(sip, BORDER, BORDER, BORDER, BORDER, fill_color=Color.WHITE)
|
||||
|
||||
#Show ROI of pre-processed image
|
||||
if DEBUG:
|
||||
image_panel = show_panel(ip.bufferedImage)
|
||||
@@ -49,6 +60,14 @@ for i in xdata:
|
||||
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)
|
||||
if len(peaks_x) > 1:
|
||||
#remoce close peaks between 350 deg and 10 deg
|
||||
if ((peaks_x[0]<10) and (peaks_x[1]>350)) or ((peaks_x[1]<10) and (peaks_x[0]>350)):
|
||||
peaks.pop(1)
|
||||
peaks_x.pop(1)
|
||||
peaks_y.pop(1)
|
||||
|
||||
|
||||
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])
|
||||
|
||||
|
||||
40
script/imgproc/CoverDetectionCalibration.py
Normal file
40
script/imgproc/CoverDetectionCalibration.py
Normal file
@@ -0,0 +1,40 @@
|
||||
#Parameters
|
||||
FRAMES_INTEGRATION = 3
|
||||
MINIMUM_CONFIDENCE = 10
|
||||
DEBUG = cover_detection_debug
|
||||
REFERENCE_IMG = "ref1"
|
||||
ERODE_ITERATIONS = 2
|
||||
|
||||
#Load reference image
|
||||
SIZE = [128,128]
|
||||
BORDER = 7
|
||||
|
||||
hexiposi.move("A")
|
||||
#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")
|
||||
#binary_dilate(ip, True, 2)
|
||||
for i in range(ERODE_ITERATIONS):
|
||||
ip.getProcessor().erode(1, 255)
|
||||
|
||||
cx,cy = int(ip.width/2), int(ip.height/2)
|
||||
ip = sub_image(ip, cx-SIZE[0]/2, cy-SIZE[1]/2, SIZE[0], SIZE[1])
|
||||
|
||||
invert(ip)
|
||||
ip = grayscale(ip, True)
|
||||
#smooth(ip)
|
||||
|
||||
if BORDER > 0:
|
||||
sip = sub_image(ip, BORDER,BORDER, SIZE[0]-2*BORDER, SIZE[1]-2*BORDER)
|
||||
ip = pad_image(sip, BORDER, BORDER, BORDER, BORDER)
|
||||
if DEBUG:
|
||||
image_panel = show_panel(ip.bufferedImage)
|
||||
|
||||
save_image(ip, str("{images}/cover/" + REFERENCE_IMG + ".png") ,"png")
|
||||
|
||||
Reference in New Issue
Block a user