This commit is contained in:
71
script/test/CameraCalibration.py
Normal file
71
script/test/CameraCalibration.py
Normal 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)
|
||||
|
||||
|
||||
116
script/test/CoverDetection.py
Normal file
116
script/test/CoverDetection.py
Normal 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
|
||||
24
script/test/PuckDetection.py
Normal file
24
script/test/PuckDetection.py
Normal file
@@ -0,0 +1,24 @@
|
||||
###################################################################################################
|
||||
# Example of using ImageJ functionalities through ijutils.
|
||||
###################################################################################################
|
||||
|
||||
from ijutils import *
|
||||
import java.awt.Color as Color
|
||||
|
||||
|
||||
#Image Loading
|
||||
ip = load_image("{images}/test2.png", title="Image")
|
||||
|
||||
|
||||
#Puck Detection
|
||||
aux = grayscale(ip, in_place=False)
|
||||
aux.show()
|
||||
plot(get_histogram(aux))
|
||||
|
||||
subtract_background(aux)
|
||||
threshold(aux,0,50); aux.repaintWindow()
|
||||
binary_fill_holes(aux); aux.repaintWindow()
|
||||
(results,output_img)=analyse_particles(aux, 10000,50000,
|
||||
fill_holes = False, exclude_edges = True,print_table=True,
|
||||
output_image = "outlines", minCirc = 0.0, maxCirc = 1.0)
|
||||
output_img.show()
|
||||
23
script/test/SampleDetection.py
Normal file
23
script/test/SampleDetection.py
Normal file
@@ -0,0 +1,23 @@
|
||||
###################################################################################################
|
||||
# Example of using ImageJ functionalities through ijutils.
|
||||
###################################################################################################
|
||||
|
||||
from ijutils import *
|
||||
import java.awt.Color as Color
|
||||
|
||||
#Image Loading
|
||||
ip = load_image("{images}/test2.png", title="Image")
|
||||
|
||||
aux = grayscale(ip, in_place=False)
|
||||
aux.show()
|
||||
|
||||
invert(aux); aux.repaintWindow()
|
||||
#gaussian_blur(aux); aux.repaintWindow()
|
||||
subtract_background(aux); aux.repaintWindow()
|
||||
auto_threshold(aux); aux.repaintWindow()
|
||||
binary_open(aux); aux.repaintWindow()
|
||||
#binary_fill_holes(aux); aux.repaintWindow()
|
||||
(results,output_img)=analyse_particles(aux, 250,1000,
|
||||
fill_holes = False, exclude_edges = True,print_table=True,
|
||||
output_image = "outlines", minCirc = 0.7, maxCirc = 1.0)
|
||||
output_img.show()
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user