Module AxisNetcam::Camera::PTZ
In: lib/axis-netcam/camera.rb

Functionality related to the camera‘s point, zoom, and tilt. Not all camera models support this.


Public Instance methods

Tries to ‘calibrate’ the camera by rotating to all extremes.

This may be useful when the camera is shifted by some external force and looses its place. Running the calibration should reset things so that the camera‘s absolute point and tilt co-ordinates are consistent relative to the camera‘s base.


# File lib/axis-netcam/camera.rb, line 197
      def calibrate"Starting camera calibration...")
        pos = get_position
        limits = get_ptz_limits(:auto)
        (1..2).each do # do it twice, just to be safe...
          ptz(:pan => limits['MinPan'], :tilt => limits['MinTilt'])
          ptz(:pan => limits['MinPan'], :tilt => limits['MaxTilt'])
          ptz(:pan => limits['MaxPan'], :tilt => limits['MaxTilt'])
          ptz(:pan => limits['MaxPan'], :tilt => limits['MinTilt'])
       "Finished camera calibration.")

Zooms the camera (in/out) to the given zoom factor.


# File lib/axis-netcam/camera.rb, line 122
      def center_on(x,y)
        axis_action("com/ptz.cgi", {'center'  => "#{x},#{y}"})

Returns the camera‘s current absolute position as a hash with :pan, :tilt, and :zoom elements.

:tilt and :pan are specified in degrees from center (for example, -170 to 170 for :pan, depending on your camera‘s physical capabilities), and zoom is an integer factor, with 0 being no zoom (widest possible viewing angle) and 10000 approaching a camera‘s maximum zoom. Again, this depends on your camera‘s capabilities.


# File lib/axis-netcam/camera.rb, line 78
      def get_position
        raw = axis_action("com/ptz.cgi", {'query' => 'position'})
        str = raw.split
        pan = str[0].split("=").last.to_f
        tilt = str[1].split("=").last.to_f
        zoom = str[2].split("=").last.to_i
        {:pan => pan, :tilt => tilt, :zoom => zoom}

Returns and array with the names of the preset positions saved in the camera.


# File lib/axis-netcam/camera.rb, line 127
      def get_preset_positions
        str = axis_action("com/ptz.cgi", {'query' => 'presetposall'})
        positions = []
        str.each do |line|
          line =~ /presetposno\d+=(.*)/
          positions << $~[1].strip if $~ && $~[1]

Returns a hash with info about the camera‘s point-tilt-zoom limits.

The returned hash will look something like:

  {'MinPan' => "-169",
   'MaxPan' => "169",
   'MinTilt' => "-90",
   'MaxTilt' => "10",
   'MinZoom' => "1",
   'MaxZoom' => "19999"}

The pan and tilt limit values assume that your camera‘s image is not rotated. If you want to use these values in ptz calls and your image is configured to be rotated, then you should also specify :imagerotation => 0 as one of your parameters to ptz. For example:

  limits = c.get_ptz_limits
  c.ptz(:tilt => limits['MaxTilt'], :imagerotation => 0)

Alternatively, you can specify a rotation argument. This will automatically adjust the returned pan and tilt values to match the given rotation. You can also specify :auto instead of providing a numeric value, in which case the system will try to fetch the rotation value for you (but be careful, because this can slow things down, since the camera must be queried first).


# File lib/axis-netcam/camera.rb, line 163
      def get_ptz_limits(rotation = nil)
        l = get_parameters("PTZ.Limit.L1")
        return l unless rotation
        rotation = get_current_image_rotation if rotation == :auto
        # TODO: this only works for the 0, 90, 180, 270 rotations but not arbitrary values
        case rotation
        when 90
          l['MinPan'], l['MaxPan'], l['MinTilt'], l['MaxTilt'] =
          l['MinTilt'], l['MaxTilt'], l['MinPan'], l['MaxPan']
        when 180
          l['MinPan'], l['MaxPan'], l['MinTilt'], l['MaxTilt'] =
          l['MinPan'], l['MaxPan'], l['MaxTilt']*-1, l['MinTilt']*-1
        when 270
          # FIXME: This transformation appears to be busted :(
          l['MinPan'], l['MaxPan'], l['MinTilt'], l['MaxTilt'] =
          l['MinTilt'], l['MaxTilt'], l['MinPan']*-1, l['MaxPan']*-1

Move the camera one ‘tick’ in the given direction. Possible values are ‘up’, ‘down’, ‘left’, ‘right‘


# File lib/axis-netcam/camera.rb, line 112
      def move(direction)
        axis_action("com/ptz.cgi", {'move' => direction})

Pans the camera (left/right) to the given absolute position in degrees.


# File lib/axis-netcam/camera.rb, line 106
      def pan(d)
        axis_action("com/ptz.cgi", {'pan'  => d})

Points the camera at the given preset.


# File lib/axis-netcam/camera.rb, line 187
      def point_at_preset_name(preset_name)
        axis_action("com/ptz.cgi", {'gotoserverpresetname' => preset_name})

Simultanously pans, tilts, and zooms the camera. The argument is a hash that can have any of ‘pan’, ‘tilt’, and ‘zoom’ elements, each specifying the desired value for the movement.


  camera.ptz(:pan => 60, :zoom => 8000)


# File lib/axis-netcam/camera.rb, line 96
      def ptz(ptz = {})
        axis_action('com/ptz.cgi', ptz)

Tilts the camera (up/down) to the given absolute position in degrees.


# File lib/axis-netcam/camera.rb, line 101
      def tilt(d)
        axis_action("com/ptz.cgi", {'tilt'  => d})

Zooms the camera (in/out) to the given zoom factor.


# File lib/axis-netcam/camera.rb, line 117
      def zoom(n)
        axis_action("com/ptz.cgi", {'zoom'  => n})