opencv-color 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a6f9389ba605456ea89cc2df4da00aa6eaf41d3
4
- data.tar.gz: ba4fb729a19870d603ecc5101efeab1d2f8b62c6
3
+ metadata.gz: feff117de0280ff57b59285aa76db2724f144938
4
+ data.tar.gz: ccdf925278830e065a2d77433037c7983637376a
5
5
  SHA512:
6
- metadata.gz: e61dd2da1acbeeafacb6188706867211c1c61bbbd303bf2eb6e7aa87ec1dcad160484c31df835a459b5bb9d51f00e2ba2d39b0b43c16ce6bf4949e60c322e8e8
7
- data.tar.gz: 0f34aea2acef8ce948f57bf7418f5c8436e976a80cfc48ef9a4ca4a4f9f3267504b6c58e7ad4988858b29a0390803afb02c0406f1eae585e039a55fb187353e9
6
+ metadata.gz: 52c6b3df2aead4ceb7786594374eeac3b8b4acd88136a77edc6d12a517a2c1754fd78b6fe1d079b44732da37d3becaf52baf2db5d6f8358f159d5b9801bc42b1
7
+ data.tar.gz: ea9a61f505b2d88a6aec3342b497462a741fe084d236723bde736afa892d8245e418dfe75838e59342e322fcf74a09bcdd2b1f018b402345a57a392438352be6
data/README.md CHANGED
@@ -20,11 +20,11 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- Put your color sample images input the following structure:
23
+ Put your color sample images into the following structure:
24
24
 
25
25
  * color samples root directory
26
- * color name
27
- * color sample image files
26
+ * color name
27
+ * color sample image files
28
28
 
29
29
  See color-samples directory as example.
30
30
 
@@ -50,7 +50,7 @@ Use the data in your application, the following example uses ruby-opencv gem:
50
50
 
51
51
  ## Contributing
52
52
 
53
- 1. Fork it ( https://github.com/[my-github-username]/opencv-color/fork )
53
+ 1. Fork it ( https://github.com/xli/opencv-color/fork )
54
54
  2. Create your feature branch (`git checkout -b my-new-feature`)
55
55
  3. Commit your changes (`git commit -am 'Add some feature'`)
56
56
  4. Push to the branch (`git push origin my-new-feature`)
data/bin/opencv-color CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'optparse'
4
4
  require 'yaml'
5
+ require 'erb'
5
6
 
6
7
  #add lib for test environment
7
8
  if File.exists?(File.expand_path(File.dirname(__FILE__) + '/../lib/opencv-color.rb'))
@@ -15,9 +16,31 @@ rescue LoadError
15
16
  require 'opencv-color'
16
17
  end
17
18
 
18
- if ARGV.empty? || ['-h', '--help'].include?(ARGV[0])
19
- puts "opencv-color <sample images directory path>"
20
- end
19
+ require 'optparse'
20
+
21
+ sample_images_dir = ARGV.pop
22
+
23
+ options = {
24
+ format: 'yaml'
25
+ }
26
+ OptionParser.new do |opts|
27
+ opts.banner = "Usage: opencv-color [options] <sample images directory path>"
28
+
29
+ opts.on("-f", "--format [FORMAT]", "Output format 'yaml' or 'objc', default is yaml") do |format|
30
+ options[:format] = format
31
+ end
32
+
33
+ opts.on("-h", "--help", "Show this message") do |v|
34
+ puts opts
35
+ exit
36
+ end
37
+ end.parse!
21
38
 
22
- data = OpenCVColor.learn(ARGV[0])
23
- puts YAML.dump(data)
39
+ data = OpenCVColor.learn(sample_images_dir)
40
+ puts case options[:format]
41
+ when 'objc'
42
+ template = File.join(File.dirname(__FILE__), '..', 'lib', 'opencv-color', 'objc.erb')
43
+ ERB.new(File.read(template)).result(binding)
44
+ else
45
+ YAML.dump(data)
46
+ end
data/lib/opencv-color.rb CHANGED
@@ -45,11 +45,11 @@ module OpenCVColor
45
45
  range = group.map(&:to_scale).inject({low: [], high: []}) do |memo, g|
46
46
  sd = g.sd
47
47
  mean = g.mean
48
- memo[:low] << [mean - 3 * sd, 0].max
49
- memo[:high] << mean + 3 * sd
48
+ memo[:low] << ([mean - 3 * sd, 0].max).floor
49
+ memo[:high] << (mean + 3 * sd).ceil
50
50
  memo
51
51
  end
52
- [File.basename(color), range]
52
+ [File.basename(color).downcase.gsub(/[^a-z_]/, '_'), range]
53
53
  end]
54
54
  end
55
55
 
@@ -0,0 +1,26 @@
1
+ #ifndef ColorRanges_h
2
+ #define ColorRanges_h
3
+
4
+ #import <opencv2/opencv.hpp>
5
+ using namespace cv;
6
+
7
+ namespace cr {
8
+ struct ColorRange {
9
+ String name;
10
+ Scalar low;
11
+ Scalar high;
12
+ ColorRange(const String& n, const Scalar& l, const Scalar& h) {
13
+ name = n;
14
+ low = l;
15
+ high = h;
16
+ };
17
+ };
18
+
19
+ <%= data.map {|color, range| " static ColorRange #{color} = ColorRange(#{color.inspect}, Scalar(#{range[:low].join(', ')}), Scalar(#{range[:high].join(', ')}));" }.join("\n") %>
20
+
21
+ static ColorRange colors[<%= data.size %>] {
22
+ <%= data.map {|c, r| c}.join(",\n ") %>
23
+ };
24
+ }
25
+
26
+ #endif
@@ -1,3 +1,3 @@
1
1
  module OpenCVColor
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opencv-color
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xiao Li
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-21 00:00:00.000000000 Z
11
+ date: 2014-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-opencv
@@ -132,6 +132,7 @@ files:
132
132
  - color-samples/yellow/yellow2.png
133
133
  - color-samples/yellow/yellow3.png
134
134
  - lib/opencv-color.rb
135
+ - lib/opencv-color/objc.erb
135
136
  - lib/opencv-color/version.rb
136
137
  - opencv-color.gemspec
137
138
  homepage: https://github.com/xli/opencv-color