Class: AlprCam::Recognizer

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

Instance Method Summary collapse

Constructor Details

#initialize(country: "eu", config: "/etc/openalpr/openalpr.conf", top_n: 10) ⇒ Recognizer

Returns a new instance of Recognizer.



8
9
10
11
12
# File 'lib/alpr_cam/recognizer.rb', line 8

def initialize(country: "eu", config: "/etc/openalpr/openalpr.conf", top_n: 10)
  @country = country
  @config = config
  @top_n = top_n
end

Instance Method Details

#recognize(image_path) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/alpr_cam/recognizer.rb', line 14

def recognize(image_path)
  cmd = [
    "alpr", "-j",
    "-c", @country,
    "--config", @config,
    "-n", @top_n.to_s,
    image_path
  ]

  stdout, stderr, status = Open3.capture3(*cmd)

  unless status.success?
    raise RecognitionError, "ALPR failed (exit #{status.exitstatus}): #{stderr}"
  end

  parse_results(stdout, image_path)
rescue JSON::ParserError => e
  raise RecognitionError, "Failed to parse ALPR output: #{e.message}"
end