Class: Webcam
- Inherits:
-
Object
- Object
- Webcam
- Defined in:
- lib/rb_webcam.rb
Overview
Class to controll your webcam. Initialize camera, grab image, then close.
Defined Under Namespace
Classes: Image
Instance Attribute Summary collapse
-
#capture_handler ⇒ Object
readonly
Getter for debug use.
Class Method Summary collapse
-
.open(camera_id = 0) {|webcam| ... } ⇒ Object
Open camera with ‘method with block’ sentence.
Instance Method Summary collapse
-
#close ⇒ Object
Close camera.
-
#grab ⇒ Object
Grab a frame from camera and returns IplImage struct.
-
#initialize(camera_id = 0) ⇒ Webcam
constructor
Open camera with camera_id, and size.
-
#resolution_mode ⇒ Object
Get resolution mode of camera.
-
#resolution_mode=(resolution) ⇒ Object
Set resolution of camera output.
Constructor Details
Instance Attribute Details
#capture_handler ⇒ Object (readonly)
Getter for debug use. Internally used to call OpenCV C functions for specified camera.
125 126 127 |
# File 'lib/rb_webcam.rb', line 125 def capture_handler @capture_handler end |
Class Method Details
.open(camera_id = 0) {|webcam| ... } ⇒ Object
Open camera with ‘method with block’ sentence. This will open then close at start and end of block. ex. Webcam.open { |camera| @image = camera.grab }
82 83 84 85 86 |
# File 'lib/rb_webcam.rb', line 82 def self.open(camera_id=0) webcam = Webcam.new(camera_id) yield webcam webcam.close end |
Instance Method Details
#close ⇒ Object
Close camera. You need close opened camera for cleaner behavior.
103 104 105 106 |
# File 'lib/rb_webcam.rb', line 103 def close Highgui.release_capture(FFI::MemoryPointer.new(:pointer).write_pointer(@capture_handler)) @capture_handler = nil end |
#grab ⇒ Object
Grab a frame from camera and returns IplImage struct. This needs camera still opened.
96 97 98 99 100 |
# File 'lib/rb_webcam.rb', line 96 def grab raise "Camera has'nt be initialized" if @capture_handler.nil? image = Highgui.query(@capture_handler) return Image.new(image) end |
#resolution_mode ⇒ Object
Get resolution mode of camera. return format is written in resolution_mode=(resolution)
118 119 120 121 |
# File 'lib/rb_webcam.rb', line 118 def resolution_mode {width: Highgui.get_property(@capture_handler, :width), height: Highgui.get_property(@capture_handler, :height)} end |
#resolution_mode=(resolution) ⇒ Object
Set resolution of camera output.
- usage
-
@webcam.resolution_mode = 160, height: 120
Available resolution_mode is depends on your camera.
111 112 113 114 |
# File 'lib/rb_webcam.rb', line 111 def resolution_mode=(resolution) Highgui.set_property(@capture_handler, :width, resolution[:width]) Highgui.set_property(@capture_handler, :height, resolution[:height]) end |