Exemplo n.º 1
0
class Camera(object):
    """ Camera model.
    """
    def __init__(self):
        """ Init the Camera object.

        Load values from preferences.
        """
        self.lens = Lens()

    def __getSensorCoef(self):
        """
        """
        return ConfigManager().getFloat('Configuration/CAMERA_SENSOR_COEF')

    def __setSensorCoef(self, sensorCoef):
        """
        """
        ConfigManager().setFloat('Configuration/CAMERA_SENSOR_COEF', sensorCoef, 1)

    sensorCoef = property(__getSensorCoef, __setSensorCoef)

    def __getSensorRatio(self):
        """
        """
        return ConfigManager().get('Configuration/CAMERA_SENSOR_RATIO')

    def __setSensorRatio(self, sensorRatio):
        """
        """
        ConfigManager().set('Configuration/CAMERA_SENSOR_RATIO', sensorRatio)

    sensorRatio = property(__getSensorRatio, __setSensorRatio)

    def __getSensorResolution(self):
        """
        """
        return ConfigManager().getFloat('Configuration/CAMERA_SENSOR_RESOLUTION')

    def __setSensorResolution(self, resolution):
        """
        """
        ConfigManager().setFloat('Configuration/CAMERA_SENSOR_RESOLUTION', resolution, 1)

    sensorResolution = property(__getSensorResolution, __setSensorResolution)

    def getYawFov(self, cameraOrientation):
        """ Compute the yaw FoV.

        @return: yaw FoV of the image
        @rtype: float
        """
        if cameraOrientation == 'landscape':
            sensorSize = 36.
        elif cameraOrientation == 'portrait':
            sensorSize = 36. / config.SENSOR_RATIOS[self.sensorRatio]
        else:
            raise ValueError("cameraOrientation must be in ('portrait', 'landscape')")
        return self.lens.computeFov(sensorSize / self.sensorCoef)

    def getPitchFov(self, cameraOrientation):
        """ Compute the pitch FoV.

        @return: pitch FoV of the image
        @rtype: float
        """
        if cameraOrientation == 'landscape':
            sensorSize = 36. / config.SENSOR_RATIOS[self.sensorRatio]
        elif cameraOrientation == 'portrait':
            sensorSize = 36.
        else:
            raise ValueError("cameraOrientation must be in ('portrait', 'landscape')")

        return self.lens.computeFov(sensorSize / self.sensorCoef)

    def getYawSensorResolution(self, cameraOrientation):
        """ Compute the yaw sensor resolution

        @return: yaw sensor resolution (px)
        @rtype: int
        """
        if cameraOrientation == 'landscape':
            sensorResolution = round(math.sqrt(self.sensorResolution * 1e6 * config.SENSOR_RATIOS[self.sensorRatio]))
        elif cameraOrientation == 'portrait':
            sensorResolution = round(math.sqrt(self.sensorResolution * 1e6 / config.SENSOR_RATIOS[self.sensorRatio]))
        else:
            raise ValueError("cameraOrientation must be in ('portrait', 'landscape')")

        return sensorResolution

    def getPitchSensorResolution(self, cameraOrientation):
        """ Compute the pitch sensor resolution

        @return: pitch sensor resolution (px)
        @rtype: int
        """
        if cameraOrientation == 'landscape':
            sensorResolution = round(math.sqrt(self.sensorResolution * 1e6 / config.SENSOR_RATIOS[self.sensorRatio]))
        elif cameraOrientation == 'portrait':
            sensorResolution = round(math.sqrt(self.sensorResolution * 1e6 * config.SENSOR_RATIOS[self.sensorRatio]))
        else:
            raise ValueError("cameraOrientation must be in ('portrait', 'landscape')")

        return sensorResolution

    def shutdown(self):
        """ Cleanly terminate the camera.

        Save values to preferences.
        """
        Logger().trace("Camera.shutdown()")
        self.lens.shutdown()
Exemplo n.º 2
0
class Camera(object):
    """ Camera model.
    """
    def __init__(self):
        """ Init the Camera object.

        Load values from preferences.
        """
        self.lens = Lens()

    def __getSensorCoef(self):
        """
        """
        return ConfigManager().getFloat('Configuration/CAMERA_SENSOR_COEF')

    def __setSensorCoef(self, sensorCoef):
        """
        """
        ConfigManager().setFloat('Configuration/CAMERA_SENSOR_COEF',
                                 sensorCoef, 1)

    sensorCoef = property(__getSensorCoef, __setSensorCoef)

    def __getSensorRatio(self):
        """
        """
        return ConfigManager().get('Configuration/CAMERA_SENSOR_RATIO')

    def __setSensorRatio(self, sensorRatio):
        """
        """
        ConfigManager().set('Configuration/CAMERA_SENSOR_RATIO', sensorRatio)

    sensorRatio = property(__getSensorRatio, __setSensorRatio)

    def __getSensorResolution(self):
        """
        """
        return ConfigManager().getFloat(
            'Configuration/CAMERA_SENSOR_RESOLUTION')

    def __setSensorResolution(self, resolution):
        """
        """
        ConfigManager().setFloat('Configuration/CAMERA_SENSOR_RESOLUTION',
                                 resolution, 1)

    sensorResolution = property(__getSensorResolution, __setSensorResolution)

    def getYawFov(self, cameraOrientation):
        """ Compute the yaw FoV.

        @return: yaw FoV of the image
        @rtype: float
        """
        if cameraOrientation == 'landscape':
            sensorSize = 36.
        elif cameraOrientation == 'portrait':
            sensorSize = 36. / config.SENSOR_RATIOS[self.sensorRatio]
        else:
            raise ValueError(
                "cameraOrientation must be in ('portrait', 'landscape')")
        return self.lens.computeFov(sensorSize / self.sensorCoef)

    def getPitchFov(self, cameraOrientation):
        """ Compute the pitch FoV.

        @return: pitch FoV of the image
        @rtype: float
        """
        if cameraOrientation == 'landscape':
            sensorSize = 36. / config.SENSOR_RATIOS[self.sensorRatio]
        elif cameraOrientation == 'portrait':
            sensorSize = 36.
        else:
            raise ValueError(
                "cameraOrientation must be in ('portrait', 'landscape')")

        return self.lens.computeFov(sensorSize / self.sensorCoef)

    def getYawSensorResolution(self, cameraOrientation):
        """ Compute the yaw sensor resolution

        @return: yaw sensor resolution (px)
        @rtype: int
        """
        if cameraOrientation == 'landscape':
            sensorResolution = round(
                math.sqrt(self.sensorResolution * 1e6 *
                          config.SENSOR_RATIOS[self.sensorRatio]))
        elif cameraOrientation == 'portrait':
            sensorResolution = round(
                math.sqrt(self.sensorResolution * 1e6 /
                          config.SENSOR_RATIOS[self.sensorRatio]))
        else:
            raise ValueError(
                "cameraOrientation must be in ('portrait', 'landscape')")

        return sensorResolution

    def getPitchSensorResolution(self, cameraOrientation):
        """ Compute the pitch sensor resolution

        @return: pitch sensor resolution (px)
        @rtype: int
        """
        if cameraOrientation == 'landscape':
            sensorResolution = round(
                math.sqrt(self.sensorResolution * 1e6 /
                          config.SENSOR_RATIOS[self.sensorRatio]))
        elif cameraOrientation == 'portrait':
            sensorResolution = round(
                math.sqrt(self.sensorResolution * 1e6 *
                          config.SENSOR_RATIOS[self.sensorRatio]))
        else:
            raise ValueError(
                "cameraOrientation must be in ('portrait', 'landscape')")

        return sensorResolution

    def shutdown(self):
        """ Cleanly terminate the camera.

        Save values to preferences.
        """
        Logger().trace("Camera.shutdown()")
        self.lens.shutdown()