Class: QRTools::UI::Camera

Inherits:
Object
  • Object
show all
Defined in:
lib/qrtools/ui/camera.rb,
ext/qrtools/qrtools_ui_camera.c

Constant Summary collapse

@@locks =
Hash.new { |h,k| h[k] = Mutex.new }

Instance Method Summary collapse

Constructor Details

#initialize(camera_number) ⇒ Camera

Returns a new instance of Camera.



8
9
10
11
12
13
14
15
# File 'lib/qrtools/ui/camera.rb', line 8

def initialize camera_number
  @camera_number = camera_number
  if block_given?
    start
    yield self
    stop
  end
end

Instance Method Details

#captureObject



32
33
34
35
36
37
38
39
40
41
42
# File 'ext/qrtools/qrtools_ui_camera.c', line 32

static VALUE capture(VALUE self)
{
  CvCapture * capture;
  Data_Get_Struct(self, CvCapture, capture);

  IplImage * cam = cvQueryFrame(capture);
  if(cam)
    return QRTools_Wrap_Image(cvCloneImage(cam));

  return Qnil;
}

#startObject



17
18
19
20
# File 'lib/qrtools/ui/camera.rb', line 17

def start
  @@locks[@camera_number].lock
  native_start
end

#stopObject



22
23
24
25
# File 'lib/qrtools/ui/camera.rb', line 22

def stop
  @@locks[@camera_number].unlock
  native_stop
end