plate_recognizer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a28477960756b2a14ead59c0f48285d2766dfc86d32ba45f9d8a7ef38dcb6fba
4
+ data.tar.gz: 30b36fb0c746f241974c6c80938e9f5002de3f93e8874a2e63af2a38002aae78
5
+ SHA512:
6
+ metadata.gz: 387fce98d0e1821af20179ed6565d84b2b09fb0c3a5d0b270022471ccb6609f4a269be2909e3794887687c8a36b0f58b943d744933a909eabb7073958a7bf9f1
7
+ data.tar.gz: a1d939106ed2194bf46db8b53b015256dfbb65c97762d797a5b1b78b9bdb529118a749eea9bb1ba15d043892e986bc36c9c3dfff834ef6748e588f4ffa0c877a
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.gem
data/.rubocop.yml ADDED
@@ -0,0 +1,25 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'db/schema.rb'
4
+ TargetRubyVersion: 2.3
5
+ Style/FrozenStringLiteralComment:
6
+ Enabled: false
7
+ Documentation:
8
+ Enabled: false
9
+ Naming/PredicateName:
10
+ Enabled: false
11
+ Naming/AccessorMethodName:
12
+ Enabled: false
13
+ Style/ClassVars:
14
+ Enabled: false
15
+ Style/MultilineOperationIndentation:
16
+ EnforcedStyle: indented
17
+ Style/RegexpLiteral:
18
+ Enabled: false
19
+ Style/RescueStandardError:
20
+ Enabled: false
21
+ Metrics/MethodLength:
22
+ Max: 25
23
+ Metrics/LineLength:
24
+ Max: 80
25
+ IgnoredPatterns: ['#']
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in plate_recognizer.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ plate_recognizer (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.5.0)
10
+ zeitwerk (2.2.2)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ bundler (~> 2.0)
17
+ plate_recognizer!
18
+ rake (~> 10.0)
19
+ zeitwerk (~> 2.2.2)
20
+
21
+ BUNDLED WITH
22
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 James Huynh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # PlateRecognizer
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/plate_recognizer`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'plate_recognizer'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install plate_recognizer
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/plate_recognizer.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "plate_recognizer"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module PlateRecognizer
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,132 @@
1
+ # rubocop:disable AbcSize
2
+ require 'plate_recognizer/version'
3
+ require 'net/http'
4
+
5
+ module PlateRecognizer
6
+ class Error < StandardError; end
7
+
8
+ class Output
9
+ attr_accessor :processing_time, :version, :filename, :camera_id
10
+ attr_accessor :timestamp
11
+ attr_accessor :results
12
+
13
+ def initialize(opts)
14
+ @processing_time = opts['processing_time']
15
+ @filename = opts['filename']
16
+ @version = opts['version']
17
+ @camera_id = opts['camera_id']
18
+ @timestamp = opts['timestamp']
19
+
20
+ @results = []
21
+ opts['results'].each do |result_hash|
22
+ @results << Result.new(result_hash)
23
+ end
24
+ end
25
+ end
26
+
27
+ class Result
28
+ attr_accessor :box
29
+ attr_accessor :plate, :region, :vehicle, :score, :candidates, :ds_score
30
+
31
+ def initialize(opts)
32
+ @plate = opts['plate']
33
+ @score = opts['score']
34
+ @dscore = opts['dscore']
35
+
36
+ @box = Box.new(opts.fetch('box'))
37
+ @region = Region.new(opts['region'])
38
+ @vehicle = Vehicle.new(opts['vehicle'])
39
+
40
+ @candidates = []
41
+ opts['candidates'].each do |candidate_hash|
42
+ @candidates << Candidate.new(candidate_hash)
43
+ end
44
+ end
45
+ end
46
+
47
+ class Box
48
+ attr_accessor :ymin, :xmin, :ymax, :xmax
49
+
50
+ def initialize(opts)
51
+ @ymin = opts.fetch('ymin')
52
+ @xmin = opts.fetch('xmin')
53
+ @ymax = opts.fetch('ymax')
54
+ @xmax = opts.fetch('xmax')
55
+ end
56
+
57
+ def width
58
+ xmax - xmin
59
+ end
60
+
61
+ def height
62
+ ymax - ymin
63
+ end
64
+
65
+ def polygon
66
+ [
67
+ "#{xmin},#{ymin}",
68
+ "#{xmin},#{ymax}",
69
+ "#{xmax},#{ymax}",
70
+ "#{xmax},#{ymin}"
71
+ ].join(' ')
72
+ end
73
+ end
74
+
75
+ class Candidate
76
+ attr_accessor :score, :plate
77
+
78
+ def initialize(opts)
79
+ return unless opts
80
+
81
+ @score = opts['score']
82
+ @plate = opts['plate']
83
+ end
84
+ end
85
+
86
+ class Vehicle
87
+ attr_accessor :score, :type
88
+
89
+ def initialize(opts)
90
+ return unless opts
91
+
92
+ @score = opts['score']
93
+ @type = opts['type']
94
+ end
95
+ end
96
+
97
+ class Region
98
+ attr_accessor :score, :code
99
+
100
+ def initialize(opts)
101
+ return unless opts
102
+
103
+ @score = opts['score']
104
+ @type = opts['code']
105
+ end
106
+ end
107
+
108
+ mattr_accessor :api_key
109
+ @@api_key = nil
110
+
111
+ def self.setup
112
+ yield self
113
+ end
114
+
115
+ def self.process(image_path)
116
+ raise 'Plate Recognizer API must be set!' if PlateRecognizer.api_key.blank?
117
+
118
+ url = URI.parse('https://api.platerecognizer.com/v1/plate-reader')
119
+ req = Net::HTTP::Post.new(url.path)
120
+ req['Accept'] = 'application/json'
121
+ req['Authorization'] = "TOKEN #{PlateRecognizer.api_key}"
122
+ form_data = [['upload', File.open(image_path)]]
123
+ req.set_form form_data, 'multipart/form-data'
124
+
125
+ sock = Net::HTTP.new(url.host, url.port)
126
+ sock.use_ssl = true
127
+ response = sock.start { |http| http.request(req) }
128
+
129
+ Output.new(JSON.parse(response.body))
130
+ end
131
+ end
132
+ # rubocop:enable all
@@ -0,0 +1,35 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'plate_recognizer/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'plate_recognizer'
7
+ spec.version = PlateRecognizer::VERSION
8
+ spec.authors = ['James Huynh']
9
+ spec.email = ['james@rubify.com']
10
+
11
+ spec.summary = 'Integrate with https://platerecognizer.com/'
12
+ spec.description = 'Integrate with https://platerecognizer.com/'
13
+ spec.homepage = 'https://github.com/jameshuynh/plate_recognizer'
14
+ spec.license = 'MIT'
15
+
16
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
17
+
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = 'https://github.com/jameshuynh/plate_recognizer'
20
+ spec.metadata['changelog_uri'] = 'https://github.com/jameshuynh/plate_recognizer/README.md'
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_development_dependency 'bundler', '~> 2.0'
34
+ spec.add_development_dependency 'rake', '~> 10.0'
35
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plate_recognizer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Huynh
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-12-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Integrate with https://platerecognizer.com/
42
+ email:
43
+ - james@rubify.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rubocop.yml"
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/setup
57
+ - lib/plate_recognizer.rb
58
+ - lib/plate_recognizer/version.rb
59
+ - plate_recognizer.gemspec
60
+ homepage: https://github.com/jameshuynh/plate_recognizer
61
+ licenses:
62
+ - MIT
63
+ metadata:
64
+ allowed_push_host: https://rubygems.org
65
+ homepage_uri: https://github.com/jameshuynh/plate_recognizer
66
+ source_code_uri: https://github.com/jameshuynh/plate_recognizer
67
+ changelog_uri: https://github.com/jameshuynh/plate_recognizer/README.md
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubygems_version: 3.0.3
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Integrate with https://platerecognizer.com/
87
+ test_files: []