Class: Player::BlobFinder

Inherits:
Device
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ruby-player/blob_finder.rb

Overview

The blobfinder interface provides access to devices that detect blobs in images

Instance Attribute Summary collapse

Attributes inherited from Device

#addr

Instance Method Summary collapse

Methods inherited from Device

#send_message

Constructor Details

#initialize(dev, client) ⇒ BlobFinder

Returns a new instance of BlobFinder.



34
35
36
37
38
39
40
# File 'lib/ruby-player/blob_finder.rb', line 34

def initialize(dev, client)
  super
  @blobs = []
  @state = { width: 0, height: 0, blobs: @blobs }
  @color = { channel: 0, rmin: 0, rmax: 0, gmin: 0, gmax: 0, bmin: 0, bmax: 0 }
  @imager_params = { brightness: 0, contrast: 0, colormode: 0, autogain: 0 }
end

Instance Attribute Details

#colorHash (readonly)

Tracking color

Returns:

  • (Hash)

    by default { channel: 0, rmin: 0, rmax: 0, gmin: 0, gmax: 0, bmin: 0, bmax: 0 }

See Also:



27
28
29
# File 'lib/ruby-player/blob_finder.rb', line 27

def color
  @color
end

#imager_paramsHash (readonly)

Imager params.

Returns:

  • (Hash)

    by default { brightness: 0, contrast: 0, colormode: 0, autogain: 0 }

See Also:



32
33
34
# File 'lib/ruby-player/blob_finder.rb', line 32

def imager_params
  @imager_params
end

#stateHash (readonly)

Blobfinder data

Returns:

  • (Hash)

    iby defult{ width: 0.0, height: 0.0, blobs: [] }



22
23
24
# File 'lib/ruby-player/blob_finder.rb', line 22

def state
  @state
end

Instance Method Details

#[](index) ⇒ Blob

Get blob

Parameters:

  • blob (Integer)

    index

Returns:



101
102
103
# File 'lib/ruby-player/blob_finder.rb', line 101

def [](index)
  @blobs[index] ||= Blob.new(index, self) 
end

#blobsArray

The list of blobs.

Returns:

  • (Array)


56
57
58
# File 'lib/ruby-player/blob_finder.rb', line 56

def blobs
  state[:blobs] 
end

#eachObject



105
106
107
# File 'lib/ruby-player/blob_finder.rb', line 105

def each
  @blobs.each { |b| yield b }
end

#fill(hdr, msg) ⇒ Object



109
110
111
112
113
114
115
116
# File 'lib/ruby-player/blob_finder.rb', line 109

def fill(hdr, msg)
  case hdr.subtype
  when PLAYER_BLOBFINDER_DATA_BLOBS
    read_data(msg)
  else
    unexpected_message hdr
  end
end

#handle_response(hdr, msg) ⇒ Object



118
119
120
121
122
123
124
125
126
127
# File 'lib/ruby-player/blob_finder.rb', line 118

def handle_response(hdr, msg)
  case hdr.subtype
  when PLAYER_BLOBFINDER_REQ_GET_COLOR
    read_color(msg)
  when 1,2
    nil
  else
    unexpected_message hdr
  end
end

#heightInteger

The image height.

Returns:

  • (Integer)


50
51
52
# File 'lib/ruby-player/blob_finder.rb', line 50

def height
  state[:height] 
end

#query_colorBlobFinder

Query color settings

Returns:



62
63
64
65
# File 'lib/ruby-player/blob_finder.rb', line 62

def query_color
  send_message(PLAYER_MSGTYPE_REQ, PLAYER_BLOBFINDER_REQ_GET_COLOR)
  self
end

#set_color(color = {}) ⇒ BlobFinder

Set tracking color.

Parameters:

  • color (Hash) (defaults to: {})
  • [Integer] (Hash)

    a customizable set of options

Returns:



77
78
79
80
81
82
# File 'lib/ruby-player/blob_finder.rb', line 77

def set_color(color={})
  data = to_a_by_default(color, @color)

  send_message(PLAYER_MSGTYPE_REQ, PLAYER_BLOBFINDER_REQ_SET_COLOR, data.pack("N*"))
  self
end

#set_imager_params(params = {}) ⇒ BlobFinder

Set imager params Imaging sensors that do blob tracking generally have some sorts of image quality parameters that you can tweak.

Parameters:

  • params (Hash) (defaults to: {})
  • [Integer] (Hash)

    a customizable set of options

Returns:



92
93
94
95
96
# File 'lib/ruby-player/blob_finder.rb', line 92

def set_imager_params(params={})
  data = to_a_by_default(params, @imager_params)
  send_message(PLAYER_MSGTYPE_REQ, PLAYER_BLOBFINDER_REQ_SET_IMAGER_PARAMS, data.pack("N*"))
  self
end

#widthInteger

The image width.

Returns:

  • (Integer)


44
45
46
# File 'lib/ruby-player/blob_finder.rb', line 44

def width
  state[:width] 
end