Module: AxisNetcam::Camera::PTZ

Included in:
AxisNetcam::Camera
Defined in:
lib/axis-netcam/camera.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#center_on(x, y) ⇒ Object

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



96
97
98
# File 'lib/axis-netcam/camera.rb', line 96

def center_on(x,y)
  axis_action("com/ptz.cgi", {'center'  => "#{x},#{y}"})
end

#get_positionObject

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.



59
60
61
62
63
64
65
66
# File 'lib/axis-netcam/camera.rb', line 59

def get_position
  str = axis_action("com/ptz.cgi", {'query' => 'position'}).split
  pan = str[0].split("=").last
  tilt = str[1].split("=").last
  zoom = str[2].split("=").last
  
  {:pan => pan, :tilt => tilt, :zoom => zoom}
end

#get_preset_positionsObject

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



101
102
103
104
105
106
107
108
109
# File 'lib/axis-netcam/camera.rb', line 101

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]
  end
  positions
end

#pan(d) ⇒ Object

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



86
87
88
# File 'lib/axis-netcam/camera.rb', line 86

def pan(d)
  axis_action("com/ptz.cgi", {'pan'  => d})
end

#point_at_preset_name(preset_name) ⇒ Object



111
112
113
# File 'lib/axis-netcam/camera.rb', line 111

def point_at_preset_name(preset_name)
  axis_action("com/ptz.cgi", {'gotoserverpresetname' => preset_name})
end

#ptz(ptz = {}) ⇒ Object

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.

Example:

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


76
77
78
# File 'lib/axis-netcam/camera.rb', line 76

def ptz(ptz = {})
  axis_action('com/ptz.cgi', ptz)
end

#tilt(d) ⇒ Object

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



81
82
83
# File 'lib/axis-netcam/camera.rb', line 81

def tilt(d)
  axis_action("com/ptz.cgi", {'tilt'  => d})
end

#zoom(n) ⇒ Object

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



91
92
93
# File 'lib/axis-netcam/camera.rb', line 91

def zoom(n)
  axis_action("com/ptz.cgi", {'zoom'  => n})
end