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 """ img.config.rotation=0 img.config.roiX,img.config.roiY, img.config.roiWidth,img.config.roiHeight =0,0,-1,-1 img.config.setCalibration(None) 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) 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 p.addOverlay(ov_text) 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: p.removeOverlay(ov_text) img.refresh()