71 lines
2.0 KiB
Python
71 lines
2.0 KiB
Python
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)
|
|
|
|
|