Class: Processing::Capture

Inherits:
Object
  • Object
show all
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



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

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



12
13
14
# File 'lib/processing/capture.rb', line 12

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



63
64
65
# File 'lib/processing/capture.rb', line 63

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



99
100
101
# File 'lib/processing/capture.rb', line 99

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

#heightNumeric

Returns the height of captured image

Returns:

  • (Numeric)

    the height of captured image



85
86
87
# File 'lib/processing/capture.rb', line 85

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

#readObject

Reads next frame image



69
70
71
# File 'lib/processing/capture.rb', line 69

def read()
  @camera.image
end

#startnil

Start capturing.

Returns:

  • (nil)

    nil



45
46
47
48
# File 'lib/processing/capture.rb', line 45

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

#stopnil

Stop capturing.

Returns:

  • (nil)

    nil



54
55
56
57
# File 'lib/processing/capture.rb', line 54

def stop()
  @camera.stop
  nil
end

#widthNumeric

Returns the width of captured image

Returns:

  • (Numeric)

    the width of captured image



77
78
79
# File 'lib/processing/capture.rb', line 77

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