opencv-color 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +57 -0
- data/Rakefile +2 -0
- data/bin/opencv-color +23 -0
- data/color-samples/blue/blue01.png +0 -0
- data/color-samples/blue/blue02.png +0 -0
- data/color-samples/blue/blue2.png +0 -0
- data/color-samples/blue/blue31.png +0 -0
- data/color-samples/blue/blue4.png +0 -0
- data/color-samples/blue/blue5.png +0 -0
- data/color-samples/blue/blue6.png +0 -0
- data/color-samples/blue/blue7.png +0 -0
- data/color-samples/blue/blue8.png +0 -0
- data/color-samples/dark-yellow/dark-yellow1.png +0 -0
- data/color-samples/dark-yellow/dark-yellow2.png +0 -0
- data/color-samples/dark-yellow/dark-yellow3.png +0 -0
- data/color-samples/dark-yellow/dark-yellow4.png +0 -0
- data/color-samples/dark-yellow/dark-yellow5.png +0 -0
- data/color-samples/dark-yellow/dark-yellow6.png +0 -0
- data/color-samples/dark-yellow/dark-yellow7.png +0 -0
- data/color-samples/dark-yellow/dark-yellow8.png +0 -0
- data/color-samples/dark-yellow/dark-yellow9.png +0 -0
- data/color-samples/green/green1.png +0 -0
- data/color-samples/green/green2.png +0 -0
- data/color-samples/green/green3.png +0 -0
- data/color-samples/green/green4.png +0 -0
- data/color-samples/green/green5.png +0 -0
- data/color-samples/light-blue/light-blue1.png +0 -0
- data/color-samples/light-blue/light-blue2.png +0 -0
- data/color-samples/light-blue/light-blue3.png +0 -0
- data/color-samples/light-blue/light-blue4.png +0 -0
- data/color-samples/light-blue/light-blue5.png +0 -0
- data/color-samples/light-blue/light-blue61.png +0 -0
- data/color-samples/light-blue/light-blue7.png +0 -0
- data/color-samples/light-yellow/light-yellow1.png +0 -0
- data/color-samples/light-yellow/light-yellow2.png +0 -0
- data/color-samples/light-yellow/light-yellow3.png +0 -0
- data/color-samples/light-yellow/light-yellow4.png +0 -0
- data/color-samples/pink/pink1.png +0 -0
- data/color-samples/pink/pink2.png +0 -0
- data/color-samples/pink/pink3.png +0 -0
- data/color-samples/pink/pink5.png +0 -0
- data/color-samples/pink/pink61.png +0 -0
- data/color-samples/pink/pink71.png +0 -0
- data/color-samples/pink/pink8.png +0 -0
- data/color-samples/pink/pink9.png +0 -0
- data/color-samples/yellow-green/yellow-green1.png +0 -0
- data/color-samples/yellow-green/yellow-green2.png +0 -0
- data/color-samples/yellow-green/yellow-green3.png +0 -0
- data/color-samples/yellow/yellow01.png +0 -0
- data/color-samples/yellow/yellow10.png +0 -0
- data/color-samples/yellow/yellow2.png +0 -0
- data/color-samples/yellow/yellow3.png +0 -0
- data/lib/opencv-color.rb +60 -0
- data/lib/opencv-color/version.rb +3 -0
- data/opencv-color.gemspec +25 -0
- metadata +161 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3a6f9389ba605456ea89cc2df4da00aa6eaf41d3
|
4
|
+
data.tar.gz: ba4fb729a19870d603ecc5101efeab1d2f8b62c6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e61dd2da1acbeeafacb6188706867211c1c61bbbd303bf2eb6e7aa87ec1dcad160484c31df835a459b5bb9d51f00e2ba2d39b0b43c16ce6bf4949e60c322e8e8
|
7
|
+
data.tar.gz: 0f34aea2acef8ce948f57bf7418f5c8436e976a80cfc48ef9a4ca4a4f9f3267504b6c58e7ad4988858b29a0390803afb02c0406f1eae585e039a55fb187353e9
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Xiao Li
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# OpenCVColor
|
2
|
+
|
3
|
+
OpenCV is a great library for writing Computer Vision software. However, OpenCV's HSV format is different than what you would expect! This gem trys to learn HSV color range from sample images for your OpenCV program to detect color.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'opencv-color'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install opencv-color
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Put your color sample images input the following structure:
|
24
|
+
|
25
|
+
* color samples root directory
|
26
|
+
* color name
|
27
|
+
* color sample image files
|
28
|
+
|
29
|
+
See color-samples directory as example.
|
30
|
+
|
31
|
+
Run opencv-color command to extract color range data:
|
32
|
+
|
33
|
+
opencv-color <color samples root directory> > color-data.yml
|
34
|
+
|
35
|
+
The output data is a YAML dump of a Ruby Hash object:
|
36
|
+
|
37
|
+
{color name => {low: HSV color CvScalar array format, high: HSV color CvScalar array format}}
|
38
|
+
|
39
|
+
Use the data in your application, the following example uses ruby-opencv gem:
|
40
|
+
|
41
|
+
include OpenCV
|
42
|
+
|
43
|
+
colors = YAML.load(File.read('color-data.yml'))
|
44
|
+
low = CvScalar.new(*colors['blue']['low'])
|
45
|
+
high = CvScalar.new(*colors['blue']['high'])
|
46
|
+
|
47
|
+
image = IplImage.load('picture.png', CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
|
48
|
+
image.BGR2HSV.in_range(low, high)
|
49
|
+
....
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
1. Fork it ( https://github.com/[my-github-username]/opencv-color/fork )
|
54
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
55
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
56
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
57
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/opencv-color
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
#add lib for test environment
|
7
|
+
if File.exists?(File.expand_path(File.dirname(__FILE__) + '/../lib/opencv-color.rb'))
|
8
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
9
|
+
end
|
10
|
+
|
11
|
+
begin
|
12
|
+
require 'opencv-color'
|
13
|
+
rescue LoadError
|
14
|
+
require 'rubygems'
|
15
|
+
require 'opencv-color'
|
16
|
+
end
|
17
|
+
|
18
|
+
if ARGV.empty? || ['-h', '--help'].include?(ARGV[0])
|
19
|
+
puts "opencv-color <sample images directory path>"
|
20
|
+
end
|
21
|
+
|
22
|
+
data = OpenCVColor.learn(ARGV[0])
|
23
|
+
puts YAML.dump(data)
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/opencv-color.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require "opencv-color/version"
|
2
|
+
require 'opencv'
|
3
|
+
require 'statsample'
|
4
|
+
|
5
|
+
module OpenCVColor
|
6
|
+
class Colors
|
7
|
+
include Enumerable
|
8
|
+
|
9
|
+
def initialize(image)
|
10
|
+
@image = image
|
11
|
+
end
|
12
|
+
|
13
|
+
def size
|
14
|
+
@image.height * @image.width
|
15
|
+
end
|
16
|
+
|
17
|
+
def each(&block)
|
18
|
+
@image.height.times do |i|
|
19
|
+
@image.width.times do |j|
|
20
|
+
yield(@image[i, j])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
include OpenCV
|
27
|
+
|
28
|
+
module_function
|
29
|
+
def samples(dir)
|
30
|
+
Dir["#{dir}/*"].map do |color|
|
31
|
+
[color, Dir["#{color}/*"]]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def learn(dir)
|
36
|
+
Hash[samples(dir).map do |color, files|
|
37
|
+
group = [[], [], [], []]
|
38
|
+
files.map(&method(:load_image_colors)).each do |colors|
|
39
|
+
colors.each do |c|
|
40
|
+
4.times do |i|
|
41
|
+
group[i] << c[i]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
range = group.map(&:to_scale).inject({low: [], high: []}) do |memo, g|
|
46
|
+
sd = g.sd
|
47
|
+
mean = g.mean
|
48
|
+
memo[:low] << [mean - 3 * sd, 0].max
|
49
|
+
memo[:high] << mean + 3 * sd
|
50
|
+
memo
|
51
|
+
end
|
52
|
+
[File.basename(color), range]
|
53
|
+
end]
|
54
|
+
end
|
55
|
+
|
56
|
+
def load_image_colors(file)
|
57
|
+
Colors.new(IplImage.load(file, OpenCV::CV_LOAD_IMAGE_ANYCOLOR | OpenCV::CV_LOAD_IMAGE_ANYDEPTH).BGR2HSV)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'opencv-color/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "opencv-color"
|
8
|
+
spec.version = OpenCVColor::VERSION
|
9
|
+
spec.authors = ["Xiao Li"]
|
10
|
+
spec.email = ["swing1979@gmail.com"]
|
11
|
+
spec.summary = %q{Learn OpenCV HSV color range from sample images.}
|
12
|
+
spec.description = %q{OpenCV is a great library for writing Computer Vision software, However, OpenCV's HSV format is different than what you would expect! This gem trys to learn HSV color range from sample images for your OpenCV program to detect color.}
|
13
|
+
spec.homepage = "https://github.com/xli/opencv-color"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency('ruby-opencv', "~> 0.0.13")
|
22
|
+
spec.add_dependency('statsample', "~> 1.4.0")
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opencv-color
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Xiao Li
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruby-opencv
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.13
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.13
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: statsample
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.4.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.4.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: OpenCV is a great library for writing Computer Vision software, However,
|
70
|
+
OpenCV's HSV format is different than what you would expect! This gem trys to learn
|
71
|
+
HSV color range from sample images for your OpenCV program to detect color.
|
72
|
+
email:
|
73
|
+
- swing1979@gmail.com
|
74
|
+
executables:
|
75
|
+
- opencv-color
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- ".gitignore"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/opencv-color
|
85
|
+
- color-samples/blue/blue01.png
|
86
|
+
- color-samples/blue/blue02.png
|
87
|
+
- color-samples/blue/blue2.png
|
88
|
+
- color-samples/blue/blue31.png
|
89
|
+
- color-samples/blue/blue4.png
|
90
|
+
- color-samples/blue/blue5.png
|
91
|
+
- color-samples/blue/blue6.png
|
92
|
+
- color-samples/blue/blue7.png
|
93
|
+
- color-samples/blue/blue8.png
|
94
|
+
- color-samples/dark-yellow/dark-yellow1.png
|
95
|
+
- color-samples/dark-yellow/dark-yellow2.png
|
96
|
+
- color-samples/dark-yellow/dark-yellow3.png
|
97
|
+
- color-samples/dark-yellow/dark-yellow4.png
|
98
|
+
- color-samples/dark-yellow/dark-yellow5.png
|
99
|
+
- color-samples/dark-yellow/dark-yellow6.png
|
100
|
+
- color-samples/dark-yellow/dark-yellow7.png
|
101
|
+
- color-samples/dark-yellow/dark-yellow8.png
|
102
|
+
- color-samples/dark-yellow/dark-yellow9.png
|
103
|
+
- color-samples/green/green1.png
|
104
|
+
- color-samples/green/green2.png
|
105
|
+
- color-samples/green/green3.png
|
106
|
+
- color-samples/green/green4.png
|
107
|
+
- color-samples/green/green5.png
|
108
|
+
- color-samples/light-blue/light-blue1.png
|
109
|
+
- color-samples/light-blue/light-blue2.png
|
110
|
+
- color-samples/light-blue/light-blue3.png
|
111
|
+
- color-samples/light-blue/light-blue4.png
|
112
|
+
- color-samples/light-blue/light-blue5.png
|
113
|
+
- color-samples/light-blue/light-blue61.png
|
114
|
+
- color-samples/light-blue/light-blue7.png
|
115
|
+
- color-samples/light-yellow/light-yellow1.png
|
116
|
+
- color-samples/light-yellow/light-yellow2.png
|
117
|
+
- color-samples/light-yellow/light-yellow3.png
|
118
|
+
- color-samples/light-yellow/light-yellow4.png
|
119
|
+
- color-samples/pink/pink1.png
|
120
|
+
- color-samples/pink/pink2.png
|
121
|
+
- color-samples/pink/pink3.png
|
122
|
+
- color-samples/pink/pink5.png
|
123
|
+
- color-samples/pink/pink61.png
|
124
|
+
- color-samples/pink/pink71.png
|
125
|
+
- color-samples/pink/pink8.png
|
126
|
+
- color-samples/pink/pink9.png
|
127
|
+
- color-samples/yellow-green/yellow-green1.png
|
128
|
+
- color-samples/yellow-green/yellow-green2.png
|
129
|
+
- color-samples/yellow-green/yellow-green3.png
|
130
|
+
- color-samples/yellow/yellow01.png
|
131
|
+
- color-samples/yellow/yellow10.png
|
132
|
+
- color-samples/yellow/yellow2.png
|
133
|
+
- color-samples/yellow/yellow3.png
|
134
|
+
- lib/opencv-color.rb
|
135
|
+
- lib/opencv-color/version.rb
|
136
|
+
- opencv-color.gemspec
|
137
|
+
homepage: https://github.com/xli/opencv-color
|
138
|
+
licenses:
|
139
|
+
- MIT
|
140
|
+
metadata: {}
|
141
|
+
post_install_message:
|
142
|
+
rdoc_options: []
|
143
|
+
require_paths:
|
144
|
+
- lib
|
145
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
requirements: []
|
156
|
+
rubyforge_project:
|
157
|
+
rubygems_version: 2.2.0
|
158
|
+
signing_key:
|
159
|
+
specification_version: 4
|
160
|
+
summary: Learn OpenCV HSV color range from sample images.
|
161
|
+
test_files: []
|