Module: MatrixCreator::Vision

Defined in:
lib/matrix_creator/vision.rb

Overview

Module: Vision

Communicate with the vision driver

Constant Summary collapse

VISION_CONFIG =

Configuration values for the Vision driver

MatrixCreator.settings[:devices][:vision]
BASE_PORT =

Base port to send data to Vision driver

VISION_CONFIG[:port]
CAMERA_WIDTH =

Camera width value

1280
CAMERA_HEIGHT =

Camera height value

720

Class Method Summary collapse

Class Method Details

.detect_demographicsObject

Detect demographics of a face

Examples:

MatrixCreator::Vision.detect_demographics


130
131
132
# File 'lib/matrix_creator/vision.rb', line 130

def self.detect_demographics
  detect_once(MatrixMalos::EnumMalosEyeDetectionType::FACE_DEMOGRAPHICS)
end

.detect_faceObject

Detect one face message

Examples:

MatrixCreator::Vision.detect_face


120
121
122
# File 'lib/matrix_creator/vision.rb', line 120

def self.detect_face
  detect_once(MatrixMalos::EnumMalosEyeDetectionType::FACE)
end

.detect_fistObject

Detect a fist

Examples:

MatrixCreator::Vision.detect_fist


170
171
172
# File 'lib/matrix_creator/vision.rb', line 170

def self.detect_fist
  detect_once(MatrixMalos::EnumMalosEyeDetectionType::HAND_FIST)
end

.detect_objects(objects, options = {}, &block) ⇒ Array

Detect a list of objects that are on detected by the camera, specifying the amount of max responses or max seconds to detect elements on camera

Examples:

Detect thumbs up for ten ocurrances

thumbs_up = MatrixMalos::EnumMalosEyeDetectionType::HAND_THUMB_UP
MatrixMalos::Vision.detect_objects(thumbs_up, max_resp: 10)

Detect face and palms for 30 seconds

objects = [
  MatrixMalos::EnumMalosEyeDetectionType::HAND_PALM,
  MatrixMalos::EnumMalosEyeDetectionType::FACE
]
MatrixCreator::Vision.detect_objects(objects, max_secs: 30)

Detect face for 10 seconds and process data on each occurance when received

objects = [MatrixMalos::EnumMalosEyeDetectionType::FACE]
MatrixCreator::Vision.detect_objects(objects, max_secs: 10) { |data|
  // Do something with data
}

Parameters:

  • objects (Array)

    of MatrixMalos::EnumMalosEyeDetectionType

  • options (Hash) (defaults to: {})

    of keys and values that can contain max_resp and/or max_secs

Returns:

  • (Array)

    elements detected in JSON format



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/matrix_creator/vision.rb', line 50

def self.detect_objects(objects, options = {}, &block)
  @vision_comm = MatrixCreator::Comm.new(BASE_PORT)

  # Setup MalosEye configuration
  malos_eye_config = MatrixMalos::MalosEyeConfig.new(
    camera_config: MatrixMalos::CameraConfig.new(
      camera_id: 0,
      width: CAMERA_WIDTH,
      height: CAMERA_HEIGHT
    )
  )

  # Generate driver configuration
  config = MatrixMalos::DriverConfig.new(
    malos_eye_config: malos_eye_config,
    delay_between_updates: 0.1,
    timeout_after_last_ping: 4
  )
  @vision_comm.send_configuration(config)

  # Setup objects to detect
  malos_eye_config = MatrixMalos::MalosEyeConfig.new
  objects.each do |object|
    malos_eye_config.object_to_detect.push(object)
  end
  config = MatrixMalos::DriverConfig.new(
    malos_eye_config: malos_eye_config
  )
  @vision_comm.send_configuration(config)

  # Query Demographics
  result = @vision_comm.perform(AdmobilizeVision::VisionResult, options, block)

  # Stop capturing events
  malos_eye_config = MatrixMalos::MalosEyeConfig.new
  malos_eye_config.object_to_detect.push(MatrixMalos::EnumMalosEyeDetectionType::STOP)
  config = MatrixMalos::DriverConfig.new(malos_eye_config: malos_eye_config)
  @vision_comm.send_configuration(config)

  # Destroy context
  @vision_comm.destroy

  result
end

.detect_once(object) ⇒ Object

Detects an object once

Examples:

object = MatrixMalos::EnumMalosEyeDetectionType::HAND_FIST
MatrixCreator::Vision.detect_once(object)


102
103
104
105
106
107
108
109
110
111
112
# File 'lib/matrix_creator/vision.rb', line 102

def self.detect_once(object)
  result = nil

  # Loop until recDetection is returned
  loop do
    result = detect_objects([object], max_resp: 1).first
    break unless result[:rectDetection].empty?
  end

  result
end

.detect_palmObject

Detect a palm

Examples:

MatrixCreator::Vision.detect_palm


150
151
152
# File 'lib/matrix_creator/vision.rb', line 150

def self.detect_palm
  detect_once(MatrixMalos::EnumMalosEyeDetectionType::HAND_PALM)
end

.detect_pinchObject

Detect a pinch

Examples:

MatrixCreator::Vision.detect_pinch


160
161
162
# File 'lib/matrix_creator/vision.rb', line 160

def self.detect_pinch
  detect_once(MatrixMalos::EnumMalosEyeDetectionType::HAND_PINCH)
end

.detect_thumb_upObject

Detect a thumbs up

Examples:

MatrixCreator::Vision.detect_thumbs_up


140
141
142
# File 'lib/matrix_creator/vision.rb', line 140

def self.detect_thumb_up
  detect_once(MatrixMalos::EnumMalosEyeDetectionType::HAND_THUMB_UP)
end