opencv-color 1.0.1 → 1.0.2

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: f8384ba1119bb0e1bcdaa51e4dd9e6f672ac531b
4
- data.tar.gz: 5b128b24d27bdfffcd1465c0dd65c07c2496506b
3
+ metadata.gz: 3d1ab524bb6fc4578ddff0366bf1211fa8aeb075
4
+ data.tar.gz: fd49bdf066ced28c96961ef4a9e2694d3f8ad4ce
5
5
  SHA512:
6
- metadata.gz: 8ccb6cc737e2250ba3b99e620995c69d72fa3433dbbcc1cc6a2757035b68ed7b3c372953133f89a6f1c122daaffeb6363c93bcc8d3fc74ae74f8640ac359be41
7
- data.tar.gz: d8ca0106ca1a427f7c237fe9f949f8edfe24a8bbed0c54e848fe88642712c4a4b8a4d41f84df3b15979f1c595fd89cf43caf4e012b773bd43217a0e1a7a64412
6
+ metadata.gz: f99dfd480a7d83a3b9039e4d99fe0d096756daa70dcad9cda613126f137286ec4588c4a9d502fb3efc27b3aa165070516f730282bfd0beb45e51f17702a2c9be
7
+ data.tar.gz: 2ea7688d6a4e4a7501e5aa59cb0b9fa717c6eeb6ce33aa0be418ef6f87f96737145b20e785ed54326d4dc6ed2663636938a87dc7db8c33a840e3405516a69bc9
data/TODO ADDED
@@ -0,0 +1,2 @@
1
+ * red/pink color is special, it's range should be 0~2x and 16x~179
2
+ ** cluster colors before caculate mean and sd
@@ -33,28 +33,45 @@ module OpenCVColor
33
33
  end
34
34
 
35
35
  def learn(dir)
36
- Hash[samples(dir).map do |color, files|
37
- group = [[], [], [], []]
36
+ Hash[samples(dir).map do |color_dir, files|
37
+ group = [[], [], []]
38
38
  files.map(&method(:load_image_colors)).each do |colors|
39
39
  colors.each do |c|
40
- 4.times do |i|
40
+ 3.times do |i|
41
41
  group[i] << c[i]
42
42
  end
43
43
  end
44
44
  end
45
- range = group.map(&:to_scale).inject({low: [], high: []}) do |memo, g|
45
+ range = group.map(&:to_scale).each_with_index.inject({low: [], high: [], mean: [], sd: []}) do |memo, d|
46
+ g, index = d
46
47
  sd = g.sd
47
48
  mean = g.mean
48
- memo[:low] << ([mean - 3 * sd, 0].max).floor
49
- memo[:high] << (mean + 3 * sd).ceil
49
+ memo[:low] << ([mean - 3 * sd, min_value].max).floor
50
+ memo[:high] << ([mean + 3 * sd, max_value(index)].min).ceil
51
+ memo[:mean] << mean
52
+ memo[:sd] << sd
50
53
  memo
51
54
  end
52
- [File.basename(color).downcase.gsub(/[^a-z_]/, '_'), range]
55
+ [color_name(color_dir), range]
53
56
  end]
54
57
  end
55
58
 
59
+ def color_name(path)
60
+ File.basename(path).downcase.gsub(/[^a-z_]/, '_')
61
+ end
62
+
63
+ def min_value
64
+ 0
65
+ end
66
+
67
+ def max_value(i)
68
+ # H => 0
69
+ i == 0 ? 179 : 255
70
+ end
71
+
56
72
  def load_image_colors(file)
57
- Colors.new(IplImage.load(file, OpenCV::CV_LOAD_IMAGE_ANYCOLOR | OpenCV::CV_LOAD_IMAGE_ANYDEPTH).BGR2HSV)
73
+ img = IplImage.load(file, OpenCV::CV_LOAD_IMAGE_ANYCOLOR | OpenCV::CV_LOAD_IMAGE_ANYDEPTH)
74
+ Colors.new(img.smooth(:median, 3).BGR2HSV)
58
75
  end
59
76
 
60
77
  end
@@ -16,7 +16,7 @@ namespace cr {
16
16
  };
17
17
  };
18
18
 
19
- <%= data.map {|color, range| " static ColorRange #{color} = ColorRange(#{color.inspect}, Scalar(#{range[:low].join(', ')}), Scalar(#{range[:high].join(', ')}));" }.join("\n") %>
19
+ <%= data.map {|color, range| " static ColorRange #{color} = ColorRange(#{color.inspect}, Scalar(#{range[:low].join(', ')}), Scalar(#{range[:high].join(', ')})); // mean: #{range[:mean]}, sd: #{range[:sd]}" }.join("\n") %>
20
20
 
21
21
  static ColorRange colors[<%= data.size %>] {
22
22
  <%= data.map {|c, r| c}.join(",\n ") %>
@@ -1,3 +1,3 @@
1
1
  module OpenCVColor
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
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: 1.0.1
4
+ version: 1.0.2
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-28 00:00:00.000000000 Z
11
+ date: 2014-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-opencv
@@ -81,6 +81,7 @@ files:
81
81
  - LICENSE.txt
82
82
  - README.md
83
83
  - Rakefile
84
+ - TODO
84
85
  - bin/opencv-color
85
86
  - color-samples/blue/blue01.png
86
87
  - color-samples/blue/blue02.png