Class: Processing::Capture

Inherits:
Object
  • Object
show all
Includes:
Xot::Inspectable
Defined in:
lib/processing/capture.rb

Overview

Camera object.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#Capture.newCapture #Capture.new(cameraName) ⇒ Capture #Capture.new(requestWidth, requestHeight) ⇒ Capture #Capture.new(requestWidth, requestHeight, cameraName) ⇒ Capture

Initialize camera object.

Parameters:

  • requestWidth (Integer)

    captured image width

  • requestHeight (Integer)

    captured image height

  • cameraName (String)

    camera device name



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/processing/capture.rb', line 29

def initialize(*args)
  width, height, name =
    if args.empty?
      [-1, -1, nil]
    elsif args[0].kind_of?(String)
      [-1, -1, args[0]]
    elsif args[0].kind_of?(Numeric) && args[1].kind_of?(Numeric)
      [args[0], args[1], args[2]]
    else
      raise ArgumentError
    end
  @camera = Rays::Camera.new width, height, device_name: name
end

Class Method Details

.listArray

Returns a list of available camera device names

Returns:

  • (Array)

    device name list



14
15
16
# File 'lib/processing/capture.rb', line 14

def self.list()
  Rays::Camera.device_names
end

Instance Method Details

#availableBoolean

Returns is the next captured image available?

Returns:

  • (Boolean)

    true means object has next frame



65
66
67
# File 'lib/processing/capture.rb', line 65

def available()
  @camera.active?
end

#filter(*args) ⇒ Object

Applies an image filter.

overload filter(shader) overload filter(type) overload filter(type, param)

Parameters:

  • shader (Shader)

    a fragment shader to apply

  • type (THRESHOLD, GRAY, INVERT, BLUR)

    filter type

  • param (Numeric)

    a parameter for each filter



101
102
103
# File 'lib/processing/capture.rb', line 101

def filter(*args)
  @filter = Shader.createFilter__(*args)
end

#heightNumeric

Returns the height of captured image

Returns:

  • (Numeric)

    the height of captured image



87
88
89
# File 'lib/processing/capture.rb', line 87

def height()
  @camera.image&.height || 0
end

#readObject

Reads next frame image



71
72
73
# File 'lib/processing/capture.rb', line 71

def read()
  @camera.image
end

#startnil

Start capturing.

Returns:

  • (nil)

    nil



47
48
49
50
# File 'lib/processing/capture.rb', line 47

def start()
  raise "Failed to start capture" unless @camera.start
  nil
end

#stopnil

Stop capturing.

Returns:

  • (nil)

    nil



56
57
58
59
# File 'lib/processing/capture.rb', line 56

def stop()
  @camera.stop
  nil
end

#widthNumeric

Returns the width of captured image

Returns:

  • (Numeric)

    the width of captured image



79
80
81
# File 'lib/processing/capture.rb', line 79

def width()
  @camera.image&.width || 0
end