lib/rubysketch/processing.rb in rubysketch-0.3.7 vs lib/rubysketch/processing.rb in rubysketch-0.3.8

- old
+ new

@@ -735,17 +735,36 @@ # Returns a list of available camera device names # # @return [Array] device name list # def self.list () - ['default'] + Rays::Camera.device_names end # Initialize camera object. # - def initialize () - @camera = Rays::Camera.new + # @overload Capture.new() + # @overload Capture.new(cameraName) + # @overload Capture.new(requestWidth, requestHeight) + # @overload Capture.new(requestWidth, requestHeight, cameraName) + # + # @param requestWidth [Integer] captured image width + # @param requestHeight [Integer] captured image height + # @param cameraName [String] camera device name + # + 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 # Start capturing. # # @return [Capture] self @@ -774,9 +793,25 @@ # Reads next frame image # def read () @camera.image + end + + # Returns the width of captured image + # + # @return [Numeric] the width of captured image + # + def width () + @camera.image&.width || 0 + end + + # Returns the height of captured image + # + # @return [Numeric] the height of captured image + # + def height () + @camera.image&.height || 0 end # @private def getInternal__ () @camera.image || dummyImage__