module MatrixCreator::Vision

Module: Vision

Communicate with the vision driver

Constants

BASE_PORT

Base port to send data to Vision driver

CAMERA_HEIGHT

Camera height value

CAMERA_WIDTH

Camera width value

VISION_CONFIG

Configuration values for the Vision driver

Public Class Methods

detect_demographics() click to toggle source

Detect demographics of a face

@example

MatrixCreator::Vision.detect_demographics
# File lib/matrix_creator/vision.rb, line 130
def self.detect_demographics
  detect_once(MatrixMalos::EnumMalosEyeDetectionType::FACE_DEMOGRAPHICS)
end
detect_face() click to toggle source

Detect one face message

@example

MatrixCreator::Vision.detect_face
# File lib/matrix_creator/vision.rb, line 120
def self.detect_face
  detect_once(MatrixMalos::EnumMalosEyeDetectionType::FACE)
end
detect_fist() click to toggle source

Detect a fist

@example

MatrixCreator::Vision.detect_fist
# File lib/matrix_creator/vision.rb, line 170
def self.detect_fist
  detect_once(MatrixMalos::EnumMalosEyeDetectionType::HAND_FIST)
end
detect_objects(objects, options = {}, &block) click to toggle source

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

@param objects [Array] of MatrixMalos::EnumMalosEyeDetectionType @param options [Hash] of keys and values that can contain max_resp and/or max_secs @return [Array] elements detected in JSON format

@example Detect thumbs up for ten ocurrances

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

@example Detect face and palms for 30 seconds

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

@example 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
}
# 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) click to toggle source

Detects an object once

@example

object = MatrixMalos::EnumMalosEyeDetectionType::HAND_FIST
MatrixCreator::Vision.detect_once(object)
# 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_palm() click to toggle source

Detect a palm

@example

MatrixCreator::Vision.detect_palm
# File lib/matrix_creator/vision.rb, line 150
def self.detect_palm
  detect_once(MatrixMalos::EnumMalosEyeDetectionType::HAND_PALM)
end
detect_pinch() click to toggle source

Detect a pinch

@example

MatrixCreator::Vision.detect_pinch
# File lib/matrix_creator/vision.rb, line 160
def self.detect_pinch
  detect_once(MatrixMalos::EnumMalosEyeDetectionType::HAND_PINCH)
end
detect_thumb_up() click to toggle source

Detect a thumbs up

@example

MatrixCreator::Vision.detect_thumbs_up
# File lib/matrix_creator/vision.rb, line 140
def self.detect_thumb_up
  detect_once(MatrixMalos::EnumMalosEyeDetectionType::HAND_THUMB_UP)
end