Class: RubySketch::Processing::Capture

Inherits:
Object
  • Object
show all
Defined in:
lib/rubysketch/processing.rb

Overview

Camera object.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#Capture.new ⇒ Capture #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



754
755
756
757
758
759
760
761
762
763
764
765
766
# File 'lib/rubysketch/processing.rb', line 754

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

.list ⇒ Array

Returns a list of available camera device names

Returns:

  • (Array) —

    device name list



739
740
741
# File 'lib/rubysketch/processing.rb', line 739

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

Instance Method Details

#available ⇒ Boolean

Returns is the next captured image available?

Returns:

  • (Boolean) —

    true means object has next frame



790
791
792
# File 'lib/rubysketch/processing.rb', line 790

def available()
  @camera.active?
end

#height ⇒ Numeric

Returns the height of captured image

Returns:

  • (Numeric) —

    the height of captured image



812
813
814
# File 'lib/rubysketch/processing.rb', line 812

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

#read ⇒ Object

Reads next frame image



796
797
798
# File 'lib/rubysketch/processing.rb', line 796

def read()
  @camera.image
end

#start ⇒ nil

Start capturing.

Returns:

  • (nil) —

    nil



772
773
774
775
# File 'lib/rubysketch/processing.rb', line 772

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

#stop ⇒ nil

Stop capturing.

Returns:

  • (nil) —

    nil



781
782
783
784
# File 'lib/rubysketch/processing.rb', line 781

def stop()
  @camera.stop
  nil
end

#width ⇒ Numeric

Returns the width of captured image

Returns:

  • (Numeric) —

    the width of captured image



804
805
806
# File 'lib/rubysketch/processing.rb', line 804

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