similie 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/ext/similie.c +13 -0
- data/test/test_basic.rb +9 -3
- data/test/test_distance.rb +3 -2
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/ext/similie.c
CHANGED
@@ -154,6 +154,18 @@ VALUE rb_image_distance_func(VALUE self, VALUE file1, VALUE file2) {
|
|
154
154
|
return INT2NUM(dist);
|
155
155
|
}
|
156
156
|
|
157
|
+
VALUE rb_image_phash_func(VALUE self, VALUE file) {
|
158
|
+
IplImage *img;
|
159
|
+
img = cvLoadImage(CSTRING(file), -1);
|
160
|
+
if (!img)
|
161
|
+
rb_raise(rb_eArgError, "Invalid image or unsupported format: %s", CSTRING(file));
|
162
|
+
|
163
|
+
uint64_t phash = image_phash(img);
|
164
|
+
cvReleaseImage(&img);
|
165
|
+
|
166
|
+
return SIZET2NUM(phash);
|
167
|
+
}
|
168
|
+
|
157
169
|
void Init_similie() {
|
158
170
|
VALUE cSimilie = rb_define_class("Similie", rb_cObject);
|
159
171
|
rb_define_alloc_func(cSimilie, rb_image_alloc);
|
@@ -162,4 +174,5 @@ void Init_similie() {
|
|
162
174
|
rb_define_method(cSimilie, "distance", RUBY_METHOD_FUNC(rb_image_distance), 1);
|
163
175
|
|
164
176
|
rb_define_singleton_method(cSimilie, "distance", RUBY_METHOD_FUNC(rb_image_distance_func), 2);
|
177
|
+
rb_define_singleton_method(cSimilie, "phash", RUBY_METHOD_FUNC(rb_image_phash_func), 1);
|
165
178
|
}
|
data/test/test_basic.rb
CHANGED
@@ -2,16 +2,22 @@ require_relative 'helper'
|
|
2
2
|
|
3
3
|
describe 'Similie image load' do
|
4
4
|
it 'should load image' do
|
5
|
-
assert Similie.new(File.join($testdir, 'lena1.
|
5
|
+
assert Similie.new(File.join($testdir, 'lena1.png'))
|
6
6
|
end
|
7
7
|
|
8
8
|
it 'should barf on invalid path' do
|
9
|
-
assert_raises(ArgumentError) { Similie.new(File.join($testdir, '
|
9
|
+
assert_raises(ArgumentError) { Similie.new(File.join($testdir, 'foo')) }
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'should hash image' do
|
13
|
-
img = Similie.new(File.join($testdir, 'lena1.
|
13
|
+
img = Similie.new(File.join($testdir, 'lena1.png'))
|
14
14
|
assert img
|
15
15
|
assert_equal 216455360913932544, img.hash
|
16
16
|
end
|
17
|
+
|
18
|
+
it 'should hash image using class method' do
|
19
|
+
hash = Similie.phash(File.join($testdir, 'lena1.png'))
|
20
|
+
assert hash
|
21
|
+
assert_equal 216455360913932544, hash
|
22
|
+
end
|
17
23
|
end
|
data/test/test_distance.rb
CHANGED
@@ -2,15 +2,16 @@ require_relative 'helper'
|
|
2
2
|
|
3
3
|
describe 'Similie image distance' do
|
4
4
|
it 'should work for similar images' do
|
5
|
-
images =
|
5
|
+
images = (1..5).map {|n| Similie.new(File.join($testdir, 'lena%d.png' % n ))}
|
6
6
|
|
7
7
|
assert_equal 1, images[0].distance(images[1])
|
8
8
|
assert_equal 2, images[1].distance(images[2])
|
9
9
|
assert_equal 0, images[2].distance(images[3])
|
10
|
+
assert_equal 1, images[0].distance(images[3])
|
10
11
|
assert_equal 6, images[3].distance(images[4])
|
11
12
|
end
|
12
13
|
|
13
14
|
it 'should work using the singleton method' do
|
14
|
-
assert_equal 6, Similie.distance(File.join($testdir, 'lena4.png'), File.join($testdir, 'lena5.
|
15
|
+
assert_equal 6, Similie.distance(File.join($testdir, 'lena4.png'), File.join($testdir, 'lena5.png'))
|
15
16
|
end
|
16
17
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Bharanee Rathna
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-06-
|
17
|
+
date: 2011-06-07 00:00:00 +10:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|