Class: AlprCam::Scanner

Inherits:
Object
  • Object
show all
Defined in:
lib/alpr_cam/scanner.rb

Instance Method Summary collapse

Constructor Details

#initialize(device: "/dev/video0", interval: 1.0, country: "eu", config: "/etc/openalpr/openalpr.conf", top_n: 10) ⇒ Scanner

Returns a new instance of Scanner.



5
6
7
8
9
10
11
# File 'lib/alpr_cam/scanner.rb', line 5

def initialize(device: "/dev/video0", interval: 1.0, country: "eu",
               config: "/etc/openalpr/openalpr.conf", top_n: 10)
  @frame_capture = FrameCapture.new(device: device)
  @recognizer = Recognizer.new(country: country, config: config, top_n: top_n)
  @interval = interval
  @running = false
end

Instance Method Details

#scan(&block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/alpr_cam/scanner.rb', line 13

def scan(&block)
  @running = true

  while @running
    image_path = nil
    begin
      image_path = @frame_capture.capture
      results = @recognizer.recognize(image_path)
      results.each { |result| block.call(result) }
    ensure
      File.delete(image_path) if image_path && File.exist?(image_path)
    end

    sleep @interval if @running
  end
end

#stopObject



30
31
32
# File 'lib/alpr_cam/scanner.rb', line 30

def stop
  @running = false
end