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 +4 -4
- data/TODO +2 -0
- data/lib/opencv-color.rb +25 -8
- data/lib/opencv-color/objc.erb +1 -1
- data/lib/opencv-color/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d1ab524bb6fc4578ddff0366bf1211fa8aeb075
|
4
|
+
data.tar.gz: fd49bdf066ced28c96961ef4a9e2694d3f8ad4ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f99dfd480a7d83a3b9039e4d99fe0d096756daa70dcad9cda613126f137286ec4588c4a9d502fb3efc27b3aa165070516f730282bfd0beb45e51f17702a2c9be
|
7
|
+
data.tar.gz: 2ea7688d6a4e4a7501e5aa59cb0b9fa717c6eeb6ce33aa0be418ef6f87f96737145b20e785ed54326d4dc6ed2663636938a87dc7db8c33a840e3405516a69bc9
|
data/TODO
ADDED
data/lib/opencv-color.rb
CHANGED
@@ -33,28 +33,45 @@ module OpenCVColor
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def learn(dir)
|
36
|
-
Hash[samples(dir).map do |
|
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
|
-
|
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,
|
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,
|
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
|
-
[
|
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
|
-
|
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
|
data/lib/opencv-color/objc.erb
CHANGED
@@ -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 ") %>
|
data/lib/opencv-color/version.rb
CHANGED
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.
|
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-
|
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
|