def afterSplashCallback(self): #-- Load Profile and Preferences profile.loadPreferences(os.path.join(self.basePath, 'preferences.ini')) profile.loadProfile(os.path.join(self.basePath, 'current-profile.ini')) #-- Load Language resources.setupLocalization(profile.getPreference('language')) #-- Create Main Window self.mainWindow = MainWindow() #-- Check for updates if profile.getPreferenceBool('check_for_updates') and version.checkForUpdates(): v = VersionWindow(self.mainWindow) if v.download: return #-- Show Main Window self.SetTopWindow(self.mainWindow) self.mainWindow.Show() if profile.getPreferenceBool('show_welcome'): #-- Create Welcome Window WelcomeWindow(self.mainWindow) setFullScreenCapable(self.mainWindow) if sys.isDarwin(): wx.CallAfter(self.StupidMacOSWorkaround)
def __init__(self, parent): """""" ExpandablePanel.__init__(self, parent, _("Image Acquisition")) self.driver = Driver.Instance() self.pcg = PointCloudGenerator.Instance() self.simpleScan = SimpleScan.Instance() self.textureScan = TextureScan.Instance() self.main = self.GetParent().GetParent().GetParent().GetParent() self.last_resolution = profile.getProfileSetting('resolution_scanning') self.clearSections() section = self.createSection('camera_scanning') section.addItem(Slider, 'brightness_scanning', tooltip=_('Image luminosity. Low values are better for environments with high ambient light conditions. High values are recommended for poorly lit places')) section.addItem(Slider, 'contrast_scanning', tooltip=_('Relative difference in intensity between an image point and its surroundings. Low values are recommended for black or very dark colored objects. High values are better for very light colored objects')) section.addItem(Slider, 'saturation_scanning', tooltip=_('Purity of color. Low values will cause colors to disappear from the image. High values will show an image with very intense colors')) section.addItem(Slider, 'laser_exposure_scanning', tooltip=_('Amount of light per unit area. It is controlled by the time the camera sensor is exposed during a frame capture. High values are recommended for poorly lit places')) section.addItem(Slider, 'color_exposure_scanning', tooltip=_('Amount of light per unit area. It is controlled by the time the camera sensor is exposed during a frame capture. High values are recommended for poorly lit places')) section.addItem(ComboBox, 'framerate_scanning', tooltip=_('Number of frames captured by the camera every second. Maximum frame rate is recommended')) section.addItem(ComboBox, 'resolution_scanning', tooltip=_('Size of the video. Maximum resolution is recommended')) section.addItem(CheckBox, 'use_distortion_scanning', tooltip=_("This option applies lens distortion correction to the video. This process slows the video feed from the camera")) if sys.isDarwin(): section = self.sections['camera_scanning'].disable('framerate_scanning') section = self.sections['camera_scanning'].disable('resolution_scanning')
def __init__(self, parent): """""" ExpandablePanel.__init__(self, parent, _("Scan Parameters"), hasUndo=False, hasRestore=False) self.driver = Driver.Instance() self.simpleScan = SimpleScan.Instance() self.textureScan = TextureScan.Instance() self.pcg = PointCloudGenerator.Instance() self.main = self.GetParent().GetParent().GetParent().GetParent() self.parent = parent self.lastScan = profile.getProfileSetting('scan_type') self.clearSections() section = self.createSection('scan_parameters') section.addItem( ComboBox, 'scan_type', tooltip= _("Simple Scan algorithm captures only the geometry using one image. Texture Scan algorithm captures also the texture using two images" )) section.addItem(ComboBox, 'use_laser') if not sys.isWindows() and not sys.isDarwin(): section.addItem(CheckBox, 'fast_scan')
def afterSplashCallback(self): #-- Load Profile and Preferences profile.loadPreferences(os.path.join(self.basePath, 'preferences.ini')) profile.loadProfile(os.path.join(self.basePath, 'current-profile.ini')) profile.loadMachineSettings( os.path.join(self.basePath, profile.getMachineSettingFileName())) #-- Load Language resources.setupLocalization(profile.getPreference('language')) #-- Create Main Window self.mainWindow = MainWindow() #-- Check for updates if profile.getPreferenceBool( 'check_for_updates') and version.checkForUpdates(): v = VersionWindow(self.mainWindow) if v.download: return #-- Show Main Window self.SetTopWindow(self.mainWindow) self.mainWindow.Show() if profile.getPreferenceBool('show_welcome'): #-- Create Welcome Window WelcomeWindow(self.mainWindow) setFullScreenCapable(self.mainWindow) if sys.isDarwin(): wx.CallAfter(self.StupidMacOSWorkaround)
def getPathForTools(name): if system.isWindows(): path = getPathForResource(resourceBasePath, "tools/windows", name) elif system.isDarwin(): path = getPathForResource(resourceBasePath, "tools/darwin", name) else: path = getPathForResource(resourceBasePath, "tools/linux", name) return path
def setBrightness(self, value): if self.isConnected: if sys.isDarwin(): ctl = self.controls['UVCC_REQ_BRIGHTNESS_ABS'] ctl.set_val(self.line(value,0,self.maxBrightness,ctl.min,ctl.max)) else: value = int(value)/self.maxBrightness self.capture.set(cv2.cv.CV_CAP_PROP_BRIGHTNESS, value)
def setSaturation(self, value): if self.isConnected: if sys.isDarwin(): ctl = self.controls['UVCC_REQ_SATURATION_ABS'] ctl.set_val(self.line(value,0,self.maxSaturation,ctl.min,ctl.max)) else: value = int(value)/self.maxSaturation self.capture.set(cv2.cv.CV_CAP_PROP_SATURATION, value)
def setContrast(self, value): if self.isConnected: if sys.isDarwin(): ctl = self.controls['UVCC_REQ_CONTRAST_ABS'] ctl.set_val(self.line(value,0,self.maxContrast,ctl.min,ctl.max)) else: value = int(value)/self.maxContrast self.capture.set(cv2.cv.CV_CAP_PROP_CONTRAST, value)
def getPathForTools(name): if system.isWindows(): path = getPathForResource(resourceBasePath, 'tools/windows', name) elif system.isDarwin(): path = getPathForResource(resourceBasePath, 'tools/darwin', name) else: path = getPathForResource(resourceBasePath, 'tools/linux', name) return path
def setSaturation(self, value): if self.isConnected: if sys.isDarwin(): ctl = self.controls['UVCC_REQ_SATURATION_ABS'] ctl.set_val( self.line(value, 0, self.maxSaturation, ctl.min, ctl.max)) else: value = int(value) / self.maxSaturation self.capture.set(cv2.cv.CV_CAP_PROP_SATURATION, value)
def getBrightness(self): if self.isConnected: if sys.isDarwin(): ctl = self.controls['UVCC_REQ_BRIGHTNESS_ABS'] value = ctl.get_val() else: value = self.capture.get(cv2.cv.CV_CAP_PROP_BRIGHTNESS) value *= self.maxBrightness return value
def __init__(self): super(HorusApp, self).__init__(redirect=False) self.basePath = profile.getBasePath() if sys.isDarwin(): self.afterSplashCallback() else: SplashScreen(self.afterSplashCallback)
def setBrightness(self, value): if self.isConnected: if sys.isDarwin(): ctl = self.controls['UVCC_REQ_BRIGHTNESS_ABS'] ctl.set_val( self.line(value, 0, self.maxBrightness, ctl.min, ctl.max)) else: value = int(value) / self.maxBrightness self.capture.set(cv2.cv.CV_CAP_PROP_BRIGHTNESS, value)
def setContrast(self, value): if self.isConnected: if sys.isDarwin(): ctl = self.controls['UVCC_REQ_CONTRAST_ABS'] ctl.set_val( self.line(value, 0, self.maxContrast, ctl.min, ctl.max)) else: value = int(value) / self.maxContrast self.capture.set(cv2.cv.CV_CAP_PROP_CONTRAST, value)
def __init__(self, parent): """""" ExpandablePanel.__init__(self, parent, _("Camera Settings")) self.driver = Driver.Instance() self.main = self.GetParent().GetParent().GetParent().GetParent() self.last_resolution = profile.getProfileSetting( 'resolution_calibration') self.clearSections() section = self.createSection('camera_calibration') section.addItem( Slider, 'brightness_calibration', tooltip= _('Image luminosity. Low values are better for environments with high ambient light conditions. High values are recommended for poorly lit places' )) section.addItem( Slider, 'contrast_calibration', tooltip= _('Relative difference in intensity between an image point and its surroundings. Low values are recommended for black or very dark colored objects. High values are better for very light colored objects' )) section.addItem( Slider, 'saturation_calibration', tooltip= _('Purity of color. Low values will cause colors to disappear from the image. High values will show an image with very intense colors' )) section.addItem( Slider, 'exposure_calibration', tooltip= _('Amount of light per unit area. It is controlled by the time the camera sensor is exposed during a frame capture. High values are recommended for poorly lit places' )) section.addItem( ComboBox, 'framerate_calibration', tooltip= _('Number of frames captured by the camera every second. Maximum frame rate is recommended' )) section.addItem( ComboBox, 'resolution_calibration', tooltip=_('Size of the video. Maximum resolution is recommended')) section.addItem( CheckBox, 'use_distortion_calibration', tooltip= _("This option applies lens distortion correction to the video. This process slows the video feed from the camera" )) if sys.isDarwin(): section = self.sections['camera_calibration'].disable( 'framerate_calibration') section = self.sections['camera_calibration'].disable( 'resolution_calibration')
def setExposure(self, value): if self.isConnected: if sys.isDarwin(): ctl = self.controls['UVCC_REQ_EXPOSURE_ABS'] value = int(value * self.relExposure) ctl.set_val(value) elif sys.isWindows(): value = int(round(-math.log(value)/math.log(2))) self.capture.set(cv2.cv.CV_CAP_PROP_EXPOSURE, value) else: value = int(value) / self.maxExposure self.capture.set(cv2.cv.CV_CAP_PROP_EXPOSURE, value)
def setExposure(self, value): if self.isConnected: if sys.isDarwin(): ctl = self.controls['UVCC_REQ_EXPOSURE_ABS'] value = int(value * self.relExposure) ctl.set_val(value) elif sys.isWindows(): value = int(round(-math.log(value) / math.log(2))) self.capture.set(cv2.cv.CV_CAP_PROP_EXPOSURE, value) else: value = int(value) / self.maxExposure self.capture.set(cv2.cv.CV_CAP_PROP_EXPOSURE, value)
def getExposure(self): if self.isConnected: if sys.isDarwin(): ctl = self.controls['UVCC_REQ_EXPOSURE_ABS'] value = ctl.get_val() value /= self.relExposure elif sys.isWindows(): value = self.capture.get(cv2.cv.CV_CAP_PROP_EXPOSURE) value = 2**-value else: value = self.capture.get(cv2.cv.CV_CAP_PROP_EXPOSURE) value *= self.maxExposure return value
def videoList(self): baselist = [] if sys.isWindows(): count = self.countCameras() for i in xrange(count): baselist.append(str(i)) elif sys.isDarwin(): for device in Camera_List(): baselist.append(str(device.src_id)) else: for device in ['/dev/video*']: baselist = baselist + glob.glob(device) return baselist
def videoList(self): baselist=[] if sys.isWindows(): count = self.countCameras() for i in xrange(count): baselist.append(str(i)) elif sys.isDarwin(): for device in Camera_List(): baselist.append(str(device.src_id)) else: for device in ['/dev/video*']: baselist = baselist + glob.glob(device) return baselist ##-- END TODO
def onScanFinished(self): self.buttonShowVideoViews.Hide() self.comboVideoViews.Hide() self.enableLabelTool(self.disconnectTool, True) self.enableLabelTool(self.playTool, True) self.enableLabelTool(self.stopTool, False) self.enableLabelTool(self.pauseTool, False) self.sceneView.setShowDeleteMenu(True) self.combo.Enable() self.GetParent().menuFile.Enable( self.GetParent().menuLaunchWizard.GetId(), True) self.GetParent().menuFile.Enable( self.GetParent().menuLoadModel.GetId(), True) self.GetParent().menuFile.Enable( self.GetParent().menuSaveModel.GetId(), True) self.GetParent().menuFile.Enable( self.GetParent().menuClearModel.GetId(), True) self.GetParent().menuFile.Enable( self.GetParent().menuOpenProfile.GetId(), True) self.GetParent().menuFile.Enable( self.GetParent().menuSaveProfile.GetId(), True) self.GetParent().menuFile.Enable( self.GetParent().menuResetProfile.GetId(), True) self.GetParent().menuFile.Enable(self.GetParent().menuExit.GetId(), True) self.GetParent().menuEdit.Enable( self.GetParent().menuPreferences.GetId(), True) self.GetParent().menuHelp.Enable(self.GetParent().menuWelcome.GetId(), True) panel = self.controls.panels['scan_parameters'] section = panel.sections['scan_parameters'] section.enable('scan_type') section.enable('use_laser') panel = self.controls.panels['rotative_platform'] section = panel.sections['motor_scanning'] section.enable('feed_rate_scanning') section.enable('acceleration_scanning') panel = self.controls.panels['image_acquisition'] section = panel.sections['camera_scanning'] if not sys.isDarwin(): section.enable('framerate_scanning') section.enable('resolution_scanning') self.enableRestore(True) self.pointCloudTimer.Stop() self.videoView.setMilliseconds(10) self.gauge.Hide() self.scenePanel.Layout() self.Layout()
def getPatternPosition(self, step, board, camera): t = None if sys.isWindows(): flush = 2 elif sys.isDarwin(): flush = 2 else: flush = 1 image = camera.captureImage(flush=True, flushValue=flush) if image is not None: self.image = image ret = self.solvePnp(image, self.objpoints, self.cameraMatrix, self.distortionVector, self.patternColumns, self.patternRows) if ret is not None: if ret[0]: t = ret[2] board.setRelativePosition(step) board.moveMotor() return t
def __init__(self, parent): """""" ExpandablePanel.__init__(self, parent, _("Scan Parameters"), hasUndo=False, hasRestore=False) self.driver = Driver.Instance() self.simpleScan = SimpleScan.Instance() self.textureScan = TextureScan.Instance() self.pcg = PointCloudGenerator.Instance() self.main = self.GetParent().GetParent().GetParent().GetParent() self.parent = parent self.lastScan = profile.getProfileSetting('scan_type') self.clearSections() section = self.createSection('scan_parameters') section.addItem(ComboBox, 'scan_type', tooltip=_("Simple Scan algorithm captures only the geometry using one image. Texture Scan algorithm captures also the texture using two images")) section.addItem(ComboBox, 'use_laser') if not sys.isWindows() and not sys.isDarwin(): section.addItem(CheckBox, 'fast_scan')
def getPatternPosition(self, step, board, camera): t = None if sys.isWindows(): flush = 2 elif sys.isDarwin(): flush = 2 else: flush = 1 image = camera.captureImage(flush=True, flushValue=flush) if image is not None: self.image = image ret = self.solvePnp(image, self.objpoints, self.cameraMatrix, self.distortionVector, self.patternColumns, self.patternRows) if ret is not None: self.patron += 1 if ret[0]: t = ret[2] board.setRelativePosition(step) board.moveMotor() print 'Patron leido ',self.patron,' veces' return t
def checkCamera(self): """ Checks correct camera """ cExp = False cBri = False # Check exposure if sys.isDarwin(): self.controls['UVCC_REQ_EXPOSURE_AUTOMODE'].set_val(1) self.setExposure(2) exposure = self.getExposure() if exposure is not None: cExp = exposure >= 1 # Check brightness self.setBrightness(2) brightness = self.getBrightness() if brightness is not None: cBri = brightness >= 1 if not cExp or not cBri: raise WrongCamera()
def connect(self): print ">>> Connecting camera {0}".format(self.cameraId) self.isConnected = False if sys.isDarwin(): for device in uvc.mac.Camera_List(): if device.src_id == self.cameraId: self.controls = uvc.mac.Controls(device.uId) if self.capture is not None: self.capture.release() self.capture = cv2.VideoCapture(self.cameraId) time.sleep(0.2) if not self.capture.isOpened(): time.sleep(1) self.capture.open(self.cameraId) if self.capture.isOpened(): print ">>> Done" self.isConnected = True self.checkVideo() self.checkCamera() else: raise CameraNotConnected()
def checkCamera(self): """ Checks correct camera """ cExp = False cBri = False # Check exposure if sys.isDarwin(): self.controls['UVCC_REQ_EXPOSURE_AUTOMODE'].set_val(1); self.setExposure(2) exposure = self.getExposure() if exposure is not None: cExp = exposure >= 1 # Check brightness self.setBrightness(2) brightness = self.getBrightness() if brightness is not None: cBri = brightness >= 1 if not cExp or not cBri: raise WrongCamera()
def _getExecutableUrl(version): url = None import platform if sys.isLinux(): url = "https://launchpad.net/~bqopensource/+archive/ubuntu/horus/+files/" url += "horus_" url += version+"-bq1~" url += platform.linux_distribution()[2]+"1_" if platform.architecture()[0] == '64bit': url += "amd64.deb" elif platform.architecture()[0] == '32bit': url += "i386.deb" elif sys.isWindows(): url = "storage.googleapis.com/bq-horus/releases/" url += "Horus_" url += version+".exe" elif sys.isDarwin(): url = "https://storage.googleapis.com/bq-horus/releases/" url += "Horus_" url += version+".dmg" del platform return url
def __init__(self, parent=None, cameraId=0): self.parent = parent self.cameraId = cameraId self.capture = None self.isConnected = False self.reading = False self.framerate = 30 self.width = 800 self.height = 600 self.useDistortion = False self.cameraMatrix = None self.distortionVector = None self.distCameraMatrix = None if sys.isWindows(): self.numberFramesFail = 3 self.maxBrightness = 1. self.maxContrast = 1. self.maxSaturation = 1. elif sys.isDarwin(): self.numberFramesFail = 1 self.maxBrightness = 255. self.maxContrast = 255. self.maxSaturation = 255. self.relExposure = 10. else: self.numberFramesFail = 3 self.maxBrightness = 255. self.maxContrast = 255. self.maxSaturation = 255. self.maxExposure = 1000. self.unplugCallback = None self._n = 0 # Check if command fails
def onScanFinished(self): self.buttonShowVideoViews.Hide() self.comboVideoViews.Hide() self.enableLabelTool(self.disconnectTool, True) self.enableLabelTool(self.playTool, True) self.enableLabelTool(self.stopTool, False) self.enableLabelTool(self.pauseTool , False) self.sceneView.setShowDeleteMenu(True) self.combo.Enable() self.GetParent().menuFile.Enable(self.GetParent().menuLaunchWizard.GetId(), True) self.GetParent().menuFile.Enable(self.GetParent().menuLoadModel.GetId(), True) self.GetParent().menuFile.Enable(self.GetParent().menuSaveModel.GetId(), True) self.GetParent().menuFile.Enable(self.GetParent().menuClearModel.GetId(), True) self.GetParent().menuFile.Enable(self.GetParent().menuOpenProfile.GetId(), True) self.GetParent().menuFile.Enable(self.GetParent().menuSaveProfile.GetId(), True) self.GetParent().menuFile.Enable(self.GetParent().menuResetProfile.GetId(), True) self.GetParent().menuFile.Enable(self.GetParent().menuExit.GetId(), True) self.GetParent().menuEdit.Enable(self.GetParent().menuPreferences.GetId(), True) self.GetParent().menuHelp.Enable(self.GetParent().menuWelcome.GetId(), True) panel = self.controls.panels['scan_parameters'] section = panel.sections['scan_parameters'] section.enable('scan_type') section.enable('use_laser') panel = self.controls.panels['rotative_platform'] section = panel.sections['motor_scanning'] section.enable('feed_rate_scanning') section.enable('acceleration_scanning') panel = self.controls.panels['image_acquisition'] section = panel.sections['camera_scanning'] if not sys.isDarwin(): section.enable('framerate_scanning') section.enable('resolution_scanning') self.enableRestore(True) self.pointCloudTimer.Stop() self.videoView.setMilliseconds(10) self.gauge.Hide() self.scenePanel.Layout() self.Layout()
def updateCallbacks(self): section = self.sections['scan_parameters'] section.updateCallback('scan_type', self.setCurrentScan) section.updateCallback('use_laser', self.setUseLaser) if not sys.isWindows() and not sys.isDarwin(): section.updateCallback('fast_scan', self.setFastScan)
# # # You should have received a copy of the GNU General Public License # # along with this program. If not, see <http://www.gnu.org/licenses/>. # # # #-----------------------------------------------------------------------# __author__ = "Jesús Arroyo Torrens <*****@*****.**>" __license__ = "GNU General Public License v2 http://www.gnu.org/licenses/gpl.html" import cv2 import math import time from horus.util import system as sys if sys.isDarwin(): from horus.engine import uvc class Error(Exception): def __init__(self, msg): self.msg = msg def __str__(self): return repr(self.msg) class CameraNotConnected(Error): def __init__(self, msg="CameraNotConnected"): super(CameraNotConnected, self).__init__(msg) class WrongCamera(Error): def __init__(self, msg="WrongCamera"):
def MacReopenApp(self): self.GetTopWindow().Raise() def StupidMacOSWorkaround(self): """ On MacOS for some magical reason opening new frames does not work until you opened a new modal dialog and closed it. If we do this from software, then, as if by magic, the bug which prevents opening extra frames is gone. """ dlg = wx.Dialog(None, size=(1, 1)) wx.PostEvent(dlg, wx.CommandEvent(wx.EVT_CLOSE.typeId)) dlg.ShowModal() dlg.Destroy() if sys.isDarwin( ): #Mac magic. Dragons live here. This sets full screen options. try: import ctypes, objc _objc = ctypes.PyDLL(objc._objc.__file__) # PyObject *PyObjCObject_New(id objc_object, int flags, int retain) _objc.PyObjCObject_New.restype = ctypes.py_object _objc.PyObjCObject_New.argtypes = [ ctypes.c_void_p, ctypes.c_int, ctypes.c_int ] def setFullScreenCapable(frame): frameobj = _objc.PyObjCObject_New(frame.GetHandle(), 0, 1) NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7 window = frameobj.window()
__author__ = "Jesús Arroyo Torrens <*****@*****.**>" __license__ = "GNU General Public License v2 http://www.gnu.org/licenses/gpl.html" import gc import os import cv2 import glob import time import struct import wx._core import webbrowser from horus.util import profile, resources, meshLoader, version, system as sys if sys.isDarwin(): from horus.engine.uvc.mac import Camera_List from horus.gui.workbench.control.main import ControlWorkbench from horus.gui.workbench.scanning.main import ScanningWorkbench from horus.gui.workbench.calibration.main import CalibrationWorkbench from horus.gui.preferences import PreferencesDialog from horus.gui.machineSettings import MachineSettingsDialog from horus.gui.welcome import WelcomeWindow from horus.gui.wizard.main import * from horus.gui.util.versionWindow import VersionWindow from horus.engine.driver import Driver from horus.engine import scan, calibration class MainWindow(wx.Frame):
def _captureThread(self): """""" linea = 0 if sys.isWindows() or sys.isDarwin(): flush_both = 3 flush_single = 1 else: flush_both = 1 flush_single = 0 #-- Switch off the lasers self.driver.board.setLeftLaserOff() self.driver.board.setRightLaserOff() if self.pcg.useLeftLaser and not self.pcg.useRightLaser: self.driver.board.setLeftLaserOn() if not self.pcg.useLeftLaser and self.pcg.useRightLaser: self.driver.board.setRightLaserOn() while self.runCapture: if not self.inactive: if abs(self.theta * 180.0 / np.pi) <= 360.0: begin = time.time() #-- Left laser if self.pcg.useLeftLaser and not self.pcg.useRightLaser: imageLaserLeft = self.driver.camera.captureImage( flush=True, flushValue=flush_single) linea += 1 #-- Right laser if not self.pcg.useLeftLaser and self.pcg.useRightLaser: imageLaserRight = self.driver.camera.captureImage( flush=True, flushValue=flush_single) linea += 1 ##-- Both laser if self.pcg.useLeftLaser and self.pcg.useRightLaser: self.driver.board.setLeftLaserOn() self.driver.board.setRightLaserOff() imgLaserLeft = self.driver.camera.captureImage( flush=True, flushValue=flush_both) linea += 1 self.driver.board.setRightLaserOn() self.driver.board.setLeftLaserOff() imgLaserRight = self.driver.camera.captureImage( flush=True, flushValue=flush_both) linea += 1 print "> {0} deg < > {1} lin <".format( self.theta * 180.0 / np.pi, linea) self.theta -= self.pcg.degrees * self.pcg.rad #-- Move motor if self.moveMotor: self.driver.board.setRelativePosition(self.pcg.degrees) self.driver.board.moveMotor() else: time.sleep(0.05) end = time.time() print "Capture: {0} ms".format(int((end - begin) * 1000)) if self.pcg.useLeftLaser and not self.pcg.useRightLaser: self.imagesQueue.put(('left', imageLaserLeft)) del imageLaserLeft if not self.pcg.useLeftLaser and self.pcg.useRightLaser: self.imagesQueue.put(('right', imageLaserRight)) del imageLaserRight if self.pcg.useLeftLaser and self.pcg.useRightLaser: self.imagesQueue.put(('both_left', imgLaserLeft)) self.imagesQueue.put(('both_right', imgLaserRight)) del imgLaserLeft del imgLaserRight else: if self.generatePointCloud: self._stopCapture() break else: time.sleep(0.1) #-- Disable board self.driver.board.setLeftLaserOff() self.driver.board.setRightLaserOff() self.driver.board.disableMotor()
def OnKeyDown(self, keyCode): if keyCode == wx.WXK_DELETE or keyCode == wx.WXK_NUMPAD_DELETE or (keyCode == wx.WXK_BACK and sys.isDarwin()): if self._showDeleteMenu: if self._object is not None: self.onDeleteObject(None) self.QueueRefresh() if keyCode == wx.WXK_DOWN: if wx.GetKeyState(wx.WXK_SHIFT): self._zoom *= 1.2 if self._zoom > numpy.max(self._machineSize) * 3: self._zoom = numpy.max(self._machineSize) * 3 elif wx.GetKeyState(wx.WXK_CONTROL): self._zOffset += 5 else: self._pitch -= 15 self.QueueRefresh() elif keyCode == wx.WXK_UP: if wx.GetKeyState(wx.WXK_SHIFT): self._zoom /= 1.2 if self._zoom < 1: self._zoom = 1 elif wx.GetKeyState(wx.WXK_CONTROL): self._zOffset -= 5 else: self._pitch += 15 self.QueueRefresh() elif keyCode == wx.WXK_LEFT: self._yaw -= 15 self.QueueRefresh() elif keyCode == wx.WXK_RIGHT: self._yaw += 15 self.QueueRefresh() elif keyCode == wx.WXK_NUMPAD_ADD or keyCode == wx.WXK_ADD or keyCode == ord('+') or keyCode == ord('='): self._zoom /= 1.2 if self._zoom < 1: self._zoom = 1 self.QueueRefresh() elif keyCode == wx.WXK_NUMPAD_SUBTRACT or keyCode == wx.WXK_SUBTRACT or keyCode == ord('-'): self._zoom *= 1.2 if self._zoom > numpy.max(self._machineSize) * 3: self._zoom = numpy.max(self._machineSize) * 3 self.QueueRefresh() elif keyCode == wx.WXK_HOME: self._yaw = 30 self._pitch = 60 self.QueueRefresh() elif keyCode == wx.WXK_PAGEUP: self._yaw = 0 self._pitch = 0 self.QueueRefresh() elif keyCode == wx.WXK_PAGEDOWN: self._yaw = 0 self._pitch = 90 self.QueueRefresh() elif keyCode == wx.WXK_END: self._yaw = 90 self._pitch = 90 self.QueueRefresh() if keyCode == wx.WXK_F3 and wx.GetKeyState(wx.WXK_SHIFT): shaderEditor(self, self.ShaderUpdate, self._objectLoadShader.getVertexShader(), self._objectLoadShader.getFragmentShader()) if keyCode == wx.WXK_F4 and wx.GetKeyState(wx.WXK_SHIFT): from collections import defaultdict from gc import get_objects self._beforeLeakTest = defaultdict(int) for i in get_objects(): self._beforeLeakTest[type(i)] += 1 if keyCode == wx.WXK_F5 and wx.GetKeyState(wx.WXK_SHIFT): from collections import defaultdict from gc import get_objects self._afterLeakTest = defaultdict(int) for i in get_objects(): self._afterLeakTest[type(i)] += 1 for k in self._afterLeakTest: if self._afterLeakTest[k]-self._beforeLeakTest[k]: print k, self._afterLeakTest[k], self._beforeLeakTest[k], self._afterLeakTest[k] - self._beforeLeakTest[k] if keyCode == wx.WXK_CONTROL: self._moveVertical = True
def _captureThread(self): """""" imgRaw = None imgLaserLeft = None imgLaserRight = None #-- Switch off the lasers self.driver.board.setLeftLaserOff() self.driver.board.setRightLaserOff() if sys.isWindows() or sys.isDarwin(): flush = 3 else: flush = 1 while self.runCapture: if not self.inactive: if abs(self.theta * 180.0 / np.pi) <= 360.0: begin = time.time() if self.fastScan: #-- FAST METHOD (only for linux) if self.driver.camera.isConnected: self.driver.camerareading = True #-- Left laser if self.pcg.useLeftLaser and not self.pcg.useRightLaser: self.driver.board.setLeftLaserOff() imgLaserLeft = self.driver.camera.capture.read()[1] imgRaw = self.driver.camera.capture.read()[1] self.driver.board.setLeftLaserOn() self.driver.camerareading = False if imgRaw is None or imgLaserLeft is None: self.driver.camera._fail() else: imgRaw = cv2.transpose(imgRaw) imgRaw = cv2.flip(imgRaw, 1) imgRaw = cv2.cvtColor(imgRaw, cv2.COLOR_BGR2RGB) imgLaserRight = None imgLaserLeft = cv2.transpose(imgLaserLeft) imgLaserLeft = cv2.flip(imgLaserLeft, 1) imgLaserLeft = cv2.cvtColor(imgLaserLeft, cv2.COLOR_BGR2RGB) #-- Right laser if not self.pcg.useLeftLaser and self.pcg.useRightLaser: self.driver.board.setRightLaserOff() imgLaserRight = self.driver.camera.capture.read()[1] imgRaw = self.driver.camera.capture.read()[1] self.driver.board.setRightLaserOn() self.driver.camerareading = False if imgRaw is None or imgLaserRight is None: self.driver.camera._fail() else: imgRaw = cv2.transpose(imgRaw) imgRaw = cv2.flip(imgRaw, 1) imgRaw = cv2.cvtColor(imgRaw, cv2.COLOR_BGR2RGB) imgLaserLeft = None imgLaserRight = cv2.transpose(imgLaserRight) imgLaserRight = cv2.flip(imgLaserRight, 1) imgLaserRight = cv2.cvtColor(imgLaserRight, cv2.COLOR_BGR2RGB) ##-- Both laser if self.pcg.useLeftLaser and self.pcg.useRightLaser: imgRaw = self.driver.camera.capture.read()[1] self.driver.board.setLeftLaserOn() imgLaserLeft = self.driver.camera.capture.read()[1] self.driver.board.setLeftLaserOff() self.driver.board.setRightLaserOn() imgLaserRight = self.driver.camera.capture.read()[1] self.driver.board.setRightLaserOff() imgRaw = self.driver.camera.capture.read()[1] self.driver.camerareading = False if imgRaw is None or imgLaserLeft is None or imgLaserRight is None: self.driver.camera._fail() else: #Begin modification rightlasername= './rightlaser-%f.tif' %(self._theta) leftlasername= './leftlaser-%f.tif' %(self._theta) texturename= './texture-%f.tif' %(self.theta) cv2.imwrite(rightlasername,imgLaserRight) cv2.imwrite(leftlasername,imgLaserLeft) cv2.imwrite(texturename,imgRaw) #End modification imgRaw = cv2.transpose(imgRaw) imgRaw = cv2.flip(imgRaw, 1) imgRaw = cv2.cvtColor(imgRaw, cv2.COLOR_BGR2RGB) imgLaserLeft = cv2.transpose(imgLaserLeft) imgLaserLeft = cv2.flip(imgLaserLeft, 1) imgLaserLeft = cv2.cvtColor(imgLaserLeft, cv2.COLOR_BGR2RGB) imgLaserRight = cv2.transpose(imgLaserRight) imgLaserRight = cv2.flip(imgLaserRight, 1) imgLaserRight = cv2.cvtColor(imgLaserRight, cv2.COLOR_BGR2RGB) else: #-- SLOW METHOD #-- Switch off laser if self.pcg.useLeftLaser: self.driver.board.setLeftLaserOff() if self.pcg.useRightLaser: self.driver.board.setRightLaserOff() #-- Capture images imgRaw = self.driver.camera.captureImage(flush=True, flushValue=flush) if self.pcg.useLeftLaser: self.driver.board.setLeftLaserOn() self.driver.board.setRightLaserOff() imgLaserLeft = self.driver.camera.captureImage(flush=True, flushValue=flush) else: imgLaserLeft = None if self.pcg.useRightLaser: self.driver.board.setRightLaserOn() self.driver.board.setLeftLaserOff() imgLaserRight = self.driver.camera.captureImage(flush=True, flushValue=flush) else: imgLaserRight = None #Begin modification rightlasername= './rightlaser-%f.tif' %(self._theta) leftlasername= './leftlaser-%f.tif' %(self._theta) texturename= './texture-%f.tif' %(self.theta) cv2.imwrite(rightlasername,imgLaserRight) cv2.imwrite(leftlasername,imgLaserLeft) cv2.imwrite(texturename,imgRaw) #End modification print "> {0} deg <".format(self.theta * 180.0 / np.pi) self.theta -= self.pcg.degrees * self.pcg.rad #-- Move motor if self.moveMotor: self.driver.board.setRelativePosition(self.pcg.degrees) self.driver.board.moveMotor() else: time.sleep(0.05) end = time.time() print "Capture: {0} ms".format(int((end-begin)*1000)) if self.pcg.useLeftLaser and not self.pcg.useRightLaser: if imgRaw is not None and imgLaserLeft is not None: self.imagesQueue.put(('left',imgRaw,imgLaserLeft)) del imgLaserLeft elif self.pcg.useRightLaser and not self.pcg.useLeftLaser: if imgRaw is not None and imgLaserRight is not None: self.imagesQueue.put(('right',imgRaw,imgLaserRight)) del imgLaserRight elif self.pcg.useRightLaser and self.pcg.useLeftLaser: if imgRaw is not None and imgLaserLeft is not None and imgLaserRight is not None: self.imagesQueue.put(('both_left',imgRaw,imgLaserLeft)) self.imagesQueue.put(('both_right',imgRaw,imgLaserRight)) del imgLaserLeft del imgLaserRight del imgRaw else: if self.generatePointCloud: self._stopCapture() break else: time.sleep(0.1) #-- Disable board self.driver.board.setLeftLaserOff() self.driver.board.setRightLaserOff() self.driver.board.disableMotor()
def _captureThread(self): """""" if sys.isWindows() or sys.isDarwin(): flush_both = 3 flush_single = 1 else: flush_both = 1 flush_single = 0 #-- Switch off the lasers self.driver.board.setLeftLaserOff() self.driver.board.setRightLaserOff() if self.pcg.useLeftLaser and not self.pcg.useRightLaser: self.driver.board.setLeftLaserOn() if not self.pcg.useLeftLaser and self.pcg.useRightLaser: self.driver.board.setRightLaserOn() while self.runCapture: if not self.inactive: if abs(self.theta * 180.0 / np.pi) <= 360.0: begin = time.time() #-- Left laser if self.pcg.useLeftLaser and not self.pcg.useRightLaser: imageLaserLeft = self.driver.camera.captureImage(flush=True, flushValue=flush_single) #-- Right laser if not self.pcg.useLeftLaser and self.pcg.useRightLaser: imageLaserRight = self.driver.camera.captureImage(flush=True, flushValue=flush_single) ##-- Both laser if self.pcg.useLeftLaser and self.pcg.useRightLaser: self.driver.board.setLeftLaserOn() self.driver.board.setRightLaserOff() imgLaserLeft = self.driver.camera.captureImage(flush=True, flushValue=flush_both) self.driver.board.setRightLaserOn() self.driver.board.setLeftLaserOff() imgLaserRight = self.driver.camera.captureImage(flush=True, flushValue=flush_both) print "> {0} deg <".format(self.theta * 180.0 / np.pi) self.theta -= self.pcg.degrees * self.pcg.rad #-- Move motor if self.moveMotor: self.driver.board.setRelativePosition(self.pcg.degrees) self.driver.board.moveMotor() else: time.sleep(0.05) end = time.time() print "Capture: {0} ms".format(int((end-begin)*1000)) if self.pcg.useLeftLaser and not self.pcg.useRightLaser: self.imagesQueue.put(('left',imageLaserLeft)) del imageLaserLeft if not self.pcg.useLeftLaser and self.pcg.useRightLaser: self.imagesQueue.put(('right',imageLaserRight)) del imageLaserRight if self.pcg.useLeftLaser and self.pcg.useRightLaser: self.imagesQueue.put(('both_left',imgLaserLeft)) self.imagesQueue.put(('both_right',imgLaserRight)) del imgLaserLeft del imgLaserRight else: if self.generatePointCloud: self._stopCapture() break else: time.sleep(0.1) #-- Disable board self.driver.board.setLeftLaserOff() self.driver.board.setRightLaserOff() self.driver.board.disableMotor()
profile.saveProfile(os.path.join(self.basePath, 'current-profile.ini')) def MacReopenApp(self): self.GetTopWindow().Raise() def StupidMacOSWorkaround(self): """ On MacOS for some magical reason opening new frames does not work until you opened a new modal dialog and closed it. If we do this from software, then, as if by magic, the bug which prevents opening extra frames is gone. """ dlg = wx.Dialog(None, size=(1,1)) wx.PostEvent(dlg, wx.CommandEvent(wx.EVT_CLOSE.typeId)) dlg.ShowModal() dlg.Destroy() if sys.isDarwin(): #Mac magic. Dragons live here. This sets full screen options. try: import ctypes, objc _objc = ctypes.PyDLL(objc._objc.__file__) # PyObject *PyObjCObject_New(id objc_object, int flags, int retain) _objc.PyObjCObject_New.restype = ctypes.py_object _objc.PyObjCObject_New.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int] def setFullScreenCapable(frame): frameobj = _objc.PyObjCObject_New(frame.GetHandle(), 0, 1) NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7 window = frameobj.window() newBehavior = window.collectionBehavior() | NSWindowCollectionBehaviorFullScreenPrimary window.setCollectionBehavior_(newBehavior)
def _start(self, progressCallback, afterCallback): XL = None XR = None if sys.isWindows(): flush = 2 elif sys.isDarwin(): flush = 2 else: flush = 1 if self.driver.isConnected: board = self.driver.board camera = self.driver.camera ##-- Switch off lasers board.setLeftLaserOff() board.setRightLaserOff() ##-- Setup motor step = 5 angle = 0 board.setSpeedMotor(1) board.enableMotor() board.setSpeedMotor(150) board.setAccelerationMotor(150) time.sleep(0.1) if progressCallback is not None: progressCallback(0) while self.isCalibrating and abs(angle) < 180: if progressCallback is not None: progressCallback(1.11*abs(angle/2.)) angle += step camera.setExposure(profile.getProfileSettingNumpy('exposure_calibration')) #-- Image acquisition imageRaw = camera.captureImage(flush=True, flushValue=flush) #-- Pattern detection ret = self.getPatternPlane(imageRaw) if ret is not None: step = 4 #2 d, n, corners = ret camera.setExposure(profile.getProfileSettingNumpy('exposure_calibration')/2.) #-- Image laser acquisition imageRawLeft = camera.captureImage(flush=True, flushValue=flush) board.setLeftLaserOn() imageLeft = camera.captureImage(flush=True, flushValue=flush) board.setLeftLaserOff() self.image = imageLeft if imageLeft is None: break imageRawRight = camera.captureImage(flush=True, flushValue=flush) board.setRightLaserOn() imageRight = camera.captureImage(flush=True, flushValue=flush) board.setRightLaserOff() self.image = imageRight if imageRight is None: break #-- Pattern ROI mask imageRaw = self.cornersMask(imageRaw, corners) imageLeft = self.cornersMask(imageLeft, corners) imageRawLeft = self.cornersMask(imageRawLeft, corners) imageRight = self.cornersMask(imageRight, corners) imageRawRight = self.cornersMask(imageRawRight, corners) #-- Line segmentation uL, vL = self.getLaserLine(imageLeft, imageRawLeft) uR, vR = self.getLaserLine(imageRight, imageRawRight) #-- Point Cloud generation xL = self.getPointCloudLaser(uL, vL, d, n) if xL is not None: if XL is None: XL = xL else: XL = np.concatenate((XL,xL)) xR = self.getPointCloudLaser(uR, vR, d, n) if xR is not None: if XR is None: XR = xR else: XR = np.concatenate((XR,xR)) else: step = 5 self.image = imageRaw board.setRelativePosition(step) board.moveMotor() time.sleep(0.1) # self.saveScene('XL.ply', XL) # self.saveScene('XR.ply', XR) #-- Compute planes dL, nL, stdL = self.computePlane(XL, 'l') dR, nR, stdR = self.computePlane(XR, 'r') ##-- Switch off lasers board.setLeftLaserOff() board.setRightLaserOff() #-- Disable motor board.disableMotor() #-- Restore camera exposure camera.setExposure(profile.getProfileSettingNumpy('exposure_calibration')) if self.isCalibrating and nL is not None and nR is not None: response = (True, ((dL, nL, stdL), (dR, nR, stdR))) if progressCallback is not None: progressCallback(100) else: if self.isCalibrating: response = (False, Error.CalibrationError) else: response = (False, Error.CalibrationCanceled) self.image = None if afterCallback is not None: afterCallback(response)
def _captureThread(self): """""" linea = 0 imgRaw = None imgLaserLeft = None imgLaserRight = None #-- Switch off the lasers self.driver.board.setLeftLaserOff() self.driver.board.setRightLaserOff() if sys.isWindows() or sys.isDarwin(): flush = 3 else: flush = 1 while self.runCapture: if not self.inactive: if abs(self.theta * 180.0 / np.pi) <= 360.0: begin = time.time() if self.fastScan: #-- FAST METHOD (only for linux) if self.driver.camera.isConnected: self.driver.camerareading = True #-- Left laser if self.pcg.useLeftLaser and not self.pcg.useRightLaser: self.driver.board.setLeftLaserOff() imgLaserLeft = self.driver.camera.capture.read( )[1] imgRaw = self.driver.camera.capture.read()[1] self.driver.board.setLeftLaserOn() self.driver.camerareading = False linea += 1 if imgRaw is None or imgLaserLeft is None: self.driver.camera._fail() else: imgRaw = cv2.transpose(imgRaw) imgRaw = cv2.flip(imgRaw, 1) imgRaw = cv2.cvtColor( imgRaw, cv2.COLOR_BGR2RGB) imgLaserRight = None imgLaserLeft = cv2.transpose(imgLaserLeft) imgLaserLeft = cv2.flip(imgLaserLeft, 1) imgLaserLeft = cv2.cvtColor( imgLaserLeft, cv2.COLOR_BGR2RGB) #-- Right laser if not self.pcg.useLeftLaser and self.pcg.useRightLaser: self.driver.board.setRightLaserOff() imgLaserRight = self.driver.camera.capture.read( )[1] imgRaw = self.driver.camera.capture.read()[1] self.driver.board.setRightLaserOn() self.driver.camerareading = False linea += 1 if imgRaw is None or imgLaserRight is None: self.driver.camera._fail() else: imgRaw = cv2.transpose(imgRaw) imgRaw = cv2.flip(imgRaw, 1) imgRaw = cv2.cvtColor( imgRaw, cv2.COLOR_BGR2RGB) imgLaserLeft = None imgLaserRight = cv2.transpose( imgLaserRight) imgLaserRight = cv2.flip(imgLaserRight, 1) imgLaserRight = cv2.cvtColor( imgLaserRight, cv2.COLOR_BGR2RGB) ##-- Both laser if self.pcg.useLeftLaser and self.pcg.useRightLaser: imgRaw = self.driver.camera.capture.read()[1] self.driver.board.setLeftLaserOn() imgLaserLeft = self.driver.camera.capture.read( )[1] self.driver.board.setLeftLaserOff() self.driver.board.setRightLaserOn() imgLaserRight = self.driver.camera.capture.read( )[1] self.driver.board.setRightLaserOff() imgRaw = self.driver.camera.capture.read()[1] self.driver.camerareading = False linea += 2 if imgRaw is None or imgLaserLeft is None or imgLaserRight is None: self.driver.camera._fail() else: imgRaw = cv2.transpose(imgRaw) imgRaw = cv2.flip(imgRaw, 1) imgRaw = cv2.cvtColor( imgRaw, cv2.COLOR_BGR2RGB) imgLaserLeft = cv2.transpose(imgLaserLeft) imgLaserLeft = cv2.flip(imgLaserLeft, 1) imgLaserLeft = cv2.cvtColor( imgLaserLeft, cv2.COLOR_BGR2RGB) imgLaserRight = cv2.transpose( imgLaserRight) imgLaserRight = cv2.flip(imgLaserRight, 1) imgLaserRight = cv2.cvtColor( imgLaserRight, cv2.COLOR_BGR2RGB) else: #-- SLOW METHOD #-- Switch off laser if self.pcg.useLeftLaser: self.driver.board.setLeftLaserOff() if self.pcg.useRightLaser: self.driver.board.setRightLaserOff() #-- Capture images imgRaw = self.driver.camera.captureImage( flush=True, flushValue=flush) if self.pcg.useLeftLaser: self.driver.board.setLeftLaserOn() self.driver.board.setRightLaserOff() imgLaserLeft = self.driver.camera.captureImage( flush=True, flushValue=flush) linea += 1 else: imgLaserLeft = None if self.pcg.useRightLaser: self.driver.board.setRightLaserOn() self.driver.board.setLeftLaserOff() imgLaserRight = self.driver.camera.captureImage( flush=True, flushValue=flush) linea += 1 else: imgLaserRight = None print "> {0} deg < > {1} lin <".format( self.theta * 180.0 / np.pi, linea) self.theta -= self.pcg.degrees * self.pcg.rad #-- Move motor if self.moveMotor: self.driver.board.setRelativePosition(self.pcg.degrees) self.driver.board.moveMotor() else: time.sleep(0.05) end = time.time() print "Capture: {0} ms".format(int((end - begin) * 1000)) if self.pcg.useLeftLaser and not self.pcg.useRightLaser: if imgRaw is not None and imgLaserLeft is not None: self.imagesQueue.put( ('left', imgRaw, imgLaserLeft)) del imgLaserLeft elif self.pcg.useRightLaser and not self.pcg.useLeftLaser: if imgRaw is not None and imgLaserRight is not None: self.imagesQueue.put( ('right', imgRaw, imgLaserRight)) del imgLaserRight elif self.pcg.useRightLaser and self.pcg.useLeftLaser: if imgRaw is not None and imgLaserLeft is not None and imgLaserRight is not None: self.imagesQueue.put( ('both_left', imgRaw, imgLaserLeft)) self.imagesQueue.put( ('both_right', imgRaw, imgLaserRight)) del imgLaserLeft del imgLaserRight del imgRaw else: if self.generatePointCloud: self._stopCapture() break else: time.sleep(0.1) #-- Disable board self.driver.board.setLeftLaserOff() self.driver.board.setRightLaserOff() self.driver.board.disableMotor()
def _start(self, progressCallback, afterCallback): XL = None XR = None planol = 0 planor = 0 if sys.isWindows(): flush = 2 elif sys.isDarwin(): flush = 2 else: flush = 1 if self.driver.isConnected: board = self.driver.board camera = self.driver.camera ##-- Switch off lasers board.setLeftLaserOff() board.setRightLaserOff() ##-- Setup motor step = 2 angle = 0 board.setSpeedMotor(1) board.enableMotor() board.setSpeedMotor(150) board.setAccelerationMotor(150) time.sleep(0.2) board.setRelativePosition(-90) board.moveMotor() time.sleep(0.2) if progressCallback is not None: progressCallback(0) while self.isCalibrating and abs(angle) < 180: if progressCallback is not None: progressCallback(1.11*abs(angle/2.)) angle += step print '> ',angle,' deg <' camera.setExposure(profile.getProfileSettingNumpy('exposure_calibration')) #-- Image acquisition imageRaw = camera.captureImage(flush=True, flushValue=flush) #-- Pattern detection ret = self.getPatternPlane(imageRaw) if ret is not None: step = 1 #2 d, n, corners = ret camera.setExposure(profile.getProfileSettingNumpy('exposure_calibration')/2.) #-- Image laser acquisition imageRawLeft = camera.captureImage(flush=True, flushValue=flush) board.setLeftLaserOn() #time.sleep(0.2) imageLeft = camera.captureImage(flush=True, flushValue=flush) #time.sleep(0.2) board.setLeftLaserOff() self.image = imageLeft if imageLeft is None: break imageRawRight = camera.captureImage(flush=True, flushValue=flush) board.setRightLaserOn() #time.sleep(0.2) imageRight = camera.captureImage(flush=True, flushValue=flush) #time.sleep(0.2) board.setRightLaserOff() self.image = imageRight if imageRight is None: break #-- Pattern ROI mask imageRaw = self.cornersMask(imageRaw, corners) imageLeft = self.cornersMask(imageLeft, corners) imageRawLeft = self.cornersMask(imageRawLeft, corners) imageRight = self.cornersMask(imageRight, corners) imageRawRight = self.cornersMask(imageRawRight, corners) #-- Line segmentation uL, vL = self.getLaserLine(imageLeft, imageRawLeft) uR, vR = self.getLaserLine(imageRight, imageRawRight) #-- Point Cloud generation xL = self.getPointCloudLaser(uL, vL, d, n) if xL is not None: if XL is None: XL = xL else: XL = np.concatenate((XL,xL)) planol += 1 print 'Plano Izquierdo registrado ',planol,' veces' xR = self.getPointCloudLaser(uR, vR, d, n) if xR is not None: if XR is None: XR = xR else: XR = np.concatenate((XR,xR)) planor += 1 print 'Plano Derecho registrado ',planol,' veces' else: step = 2 self.image = imageRaw print 'No se ha detectado el patron' board.setRelativePosition(step) board.moveMotor() time.sleep(0.2) # self.saveScene('XL.ply', XL) # self.saveScene('XR.ply', XR) #-- Compute planes print '>>> Computando plano Izquierdo <<<' dL, nL, stdL = self.computePlane(XL, 'l') print '>>> Computando plano Derecho <<<' dR, nR, stdR = self.computePlane(XR, 'r') ##-- Switch off lasers board.setLeftLaserOff() board.setRightLaserOff() #-- Disable motor board.setRelativePosition(-90) board.moveMotor() time.sleep(0.2) board.disableMotor() #-- Restore camera exposure camera.setExposure(profile.getProfileSettingNumpy('exposure_calibration')) if self.isCalibrating and nL is not None and nR is not None: response = (True, ((dL, nL, stdL), (dR, nR, stdR))) if progressCallback is not None: progressCallback(100) else: if self.isCalibrating: response = (False, Error.CalibrationError) else: response = (False, Error.CalibrationCanceled) self.image = None if afterCallback is not None: afterCallback(response)