logo 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/ext/logo/recognize/extconf.rb +29 -0
- data/ext/logo/recognize/recognize.c +107 -0
- data/ext/logo/recognize/recognize.h +36 -0
- data/ext/logo/recognize/template_match.h +100 -0
- data/ext/logo/recognize/template_match_test.c +176 -0
- data/lib/logo.rb +10 -0
- data/lib/logo/scouts.rb +40 -0
- data/lib/logo/suite.rb +26 -0
- metadata +126 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 崔峥
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= rca_logo_recognition
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to rca_logo_recognition
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2013 崔峥. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
require 'pkg-config'
|
3
|
+
|
4
|
+
$CFLAGS << PKGConfig.cflags('opencv')
|
5
|
+
|
6
|
+
# unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O3')
|
7
|
+
# $CFLAGS << ' -O3'
|
8
|
+
# end
|
9
|
+
|
10
|
+
$CFLAGS << ' -g'
|
11
|
+
$CFLAGS.gsub!(/-O\d+/,'')
|
12
|
+
|
13
|
+
if CONFIG['CC'] =~ /gcc/
|
14
|
+
$CFLAGS << ' -Wall'
|
15
|
+
# if $DEBUG && !$CFLAGS.gsub!(/ -O[\dsz]?/, ' -O0 -ggdb')
|
16
|
+
# $CFLAGS << ' -O0 -ggdb'
|
17
|
+
# end
|
18
|
+
end
|
19
|
+
|
20
|
+
dir_config("opencv", "/usr/local/include/opencv", "/usr/local/lib")
|
21
|
+
|
22
|
+
opencv_libraries = ["opencv_core", "opencv_highgui"]
|
23
|
+
|
24
|
+
puts ">> check require libraries..."
|
25
|
+
opencv_libraries.each{|lib|
|
26
|
+
raise "lib#{lib} not found." unless have_library(lib)
|
27
|
+
}
|
28
|
+
|
29
|
+
create_makefile("logo/recognize")
|
@@ -0,0 +1,107 @@
|
|
1
|
+
#include "recognize.h"
|
2
|
+
|
3
|
+
static VALUE rb_c_recognize;
|
4
|
+
|
5
|
+
void Init_recognize()
|
6
|
+
{
|
7
|
+
VALUE m_logo, c_recognize;
|
8
|
+
m_logo = rb_const_get(rb_cObject, rb_intern("Logo"));
|
9
|
+
c_recognize = rb_define_class_under(m_logo, "Recognize", rb_cObject);
|
10
|
+
rb_define_method(c_recognize, "initialize", initialize, 0);
|
11
|
+
rb_define_method(c_recognize, "add_image", rb_add_image_template, 1);
|
12
|
+
rb_define_method(c_recognize, "image_feature", rb_init_image_feature, 1);
|
13
|
+
rb_define_method(c_recognize, "match", rb_match_image, 2);
|
14
|
+
rb_define_method(c_recognize, "release_feature", rb_release_image_feature, 1);
|
15
|
+
rb_define_method(c_recognize, "release", rb_release_template_match, 1);
|
16
|
+
}
|
17
|
+
|
18
|
+
void*
|
19
|
+
get_logo_ctx_ptr(VALUE self)
|
20
|
+
{
|
21
|
+
VALUE logo_ctx_ptr = rb_iv_get(self, "@c_logo_ctx_ptr");
|
22
|
+
return (void*)NUM2ULONG(logo_ctx_ptr);
|
23
|
+
}
|
24
|
+
|
25
|
+
static VALUE
|
26
|
+
initialize(VALUE self)
|
27
|
+
{
|
28
|
+
void *c_logo_ctx_ptr = init_template_match();
|
29
|
+
|
30
|
+
rb_iv_set(self, "@c_logo_ctx_ptr", LL2NUM(c_logo_ctx_ptr));
|
31
|
+
return self;
|
32
|
+
}
|
33
|
+
|
34
|
+
static VALUE
|
35
|
+
rb_add_image_template(VALUE self, VALUE hash)
|
36
|
+
{
|
37
|
+
void *ctx;
|
38
|
+
int rlt;
|
39
|
+
VALUE path;
|
40
|
+
VALUE label;
|
41
|
+
VALUE x, y, w, h;
|
42
|
+
|
43
|
+
ctx = get_logo_ctx_ptr(self);
|
44
|
+
|
45
|
+
path = rb_hash_fetch(hash, rb_str_new2("path"));
|
46
|
+
label = rb_hash_fetch(hash, rb_str_new2("label"));
|
47
|
+
x = rb_hash_fetch(hash, rb_str_new2("x"));
|
48
|
+
y = rb_hash_fetch(hash, rb_str_new2("y"));
|
49
|
+
w = rb_hash_fetch(hash, rb_str_new2("w"));
|
50
|
+
h = rb_hash_fetch(hash, rb_str_new2("h"));
|
51
|
+
|
52
|
+
rlt = add_image_template(ctx, StringValueCStr(path), StringValueCStr(label), NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h));
|
53
|
+
return INT2NUM(rlt);
|
54
|
+
}
|
55
|
+
|
56
|
+
static VALUE
|
57
|
+
rb_init_image_feature(VALUE self, VALUE img_path)
|
58
|
+
{
|
59
|
+
void *ctx;
|
60
|
+
void *feature;
|
61
|
+
|
62
|
+
ctx = get_logo_ctx_ptr(self);
|
63
|
+
feature = init_image_feature(ctx, StringValueCStr(img_path));
|
64
|
+
|
65
|
+
return LL2NUM(feature);
|
66
|
+
}
|
67
|
+
|
68
|
+
static VALUE
|
69
|
+
rb_match_image(VALUE self, VALUE rb_feature, VALUE label)
|
70
|
+
{
|
71
|
+
void *ctx;
|
72
|
+
void *feature;
|
73
|
+
float score;
|
74
|
+
|
75
|
+
ctx = get_logo_ctx_ptr(self);
|
76
|
+
feature = (void*)NUM2ULONG(rb_feature);
|
77
|
+
|
78
|
+
score = match_image(ctx, feature, StringValueCStr(label));
|
79
|
+
|
80
|
+
return rb_float_new(score);
|
81
|
+
}
|
82
|
+
|
83
|
+
static VALUE
|
84
|
+
rb_release_image_feature(VALUE self, VALUE rb_feature)
|
85
|
+
{
|
86
|
+
void *feature;
|
87
|
+
feature = (void*)NUM2ULONG(rb_feature);
|
88
|
+
|
89
|
+
release_image_feature(feature);
|
90
|
+
|
91
|
+
return Qnil;
|
92
|
+
}
|
93
|
+
|
94
|
+
static VALUE
|
95
|
+
rb_release_template_match(VALUE self)
|
96
|
+
{
|
97
|
+
void *ctx;
|
98
|
+
ctx = get_logo_ctx_ptr(self);
|
99
|
+
|
100
|
+
release_template_match(ctx);
|
101
|
+
|
102
|
+
return Qnil;
|
103
|
+
}
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#ifndef __LOGO_H
|
2
|
+
#define __LOGO_H
|
3
|
+
|
4
|
+
#include <ruby.h>
|
5
|
+
// #include "template_match.h"
|
6
|
+
|
7
|
+
extern void* init_template_match(void);
|
8
|
+
extern int add_image_template(void* ptemplate_match, const char* template_img_path, const char* label, int x, int y , int width, int height);
|
9
|
+
|
10
|
+
extern void* init_image_feature(void* ptemplate_match, const char* img_path);
|
11
|
+
extern float match_image(void* ptemplate_match, void* pimage_feature, char* label);
|
12
|
+
extern void release_image_feature(void* pimage_feature);
|
13
|
+
|
14
|
+
extern void release_template_match(void* ptemplate_match);
|
15
|
+
|
16
|
+
void*
|
17
|
+
get_logo_ctx_ptr(VALUE self);
|
18
|
+
|
19
|
+
static VALUE
|
20
|
+
initialize(VALUE self);
|
21
|
+
|
22
|
+
static VALUE
|
23
|
+
rb_add_image_template(VALUE self, VALUE hash);
|
24
|
+
|
25
|
+
static VALUE
|
26
|
+
rb_init_image_feature(VALUE self, VALUE img_path);
|
27
|
+
|
28
|
+
static VALUE
|
29
|
+
rb_match_image(VALUE self, VALUE rb_feature, VALUE label);
|
30
|
+
|
31
|
+
static VALUE
|
32
|
+
rb_release_image_feature(VALUE self, VALUE rb_feature);
|
33
|
+
|
34
|
+
static VALUE
|
35
|
+
rb_release_template_match(VALUE self);
|
36
|
+
#endif
|
@@ -0,0 +1,100 @@
|
|
1
|
+
#ifndef __TEMPLATE_MATCH_H_
|
2
|
+
#define __TEMPLATE_MATCH_H_
|
3
|
+
|
4
|
+
#include "cv.h"
|
5
|
+
#include <float.h>
|
6
|
+
#include <string>
|
7
|
+
#include <vector>
|
8
|
+
#include <fstream>
|
9
|
+
#include <sstream>
|
10
|
+
#include <iostream>
|
11
|
+
|
12
|
+
extern "C" void* init_template_match(void);
|
13
|
+
extern "C" int add_image_template(void* ptemplate_match, const char* template_img_path, const char* label, int x, int y , int width, int height);
|
14
|
+
|
15
|
+
extern "C" void* init_image_feature(void* ptemplate_match, const char* img_path);
|
16
|
+
extern "C" float match_image(void* ptemplate_match, void* pimage_feature, char* label);
|
17
|
+
extern "C" void release_image_feature(void* pimage_feature);
|
18
|
+
|
19
|
+
extern "C" void release_template_match(void* ptemplate_match);
|
20
|
+
|
21
|
+
|
22
|
+
using namespace cv;
|
23
|
+
using namespace std;
|
24
|
+
|
25
|
+
const int DEFAULT_X = 30;
|
26
|
+
const int DEFAULT_Y = 20;
|
27
|
+
const int DEFAULT_ROWS = 120;
|
28
|
+
const int DEFAULT_COLS = 250;
|
29
|
+
|
30
|
+
const float NO_MATCH_SCORE = 10.0;
|
31
|
+
|
32
|
+
typedef struct slogo{
|
33
|
+
string name;
|
34
|
+
Mat contourMat;
|
35
|
+
Mat templateMat;
|
36
|
+
Rect contourRect;
|
37
|
+
}
|
38
|
+
slogo;
|
39
|
+
|
40
|
+
|
41
|
+
/*
|
42
|
+
* This class implement template match mechanism.
|
43
|
+
* 1.provide template images to build a matching database.
|
44
|
+
* 2.for a input image, you can get the similarities the image to the templates.
|
45
|
+
*
|
46
|
+
* TODO
|
47
|
+
* 1.supply simple interfaces. (100%)
|
48
|
+
* 2.build .so library. (100%)
|
49
|
+
* 3.add threshold support and find a policy to use the threshold.
|
50
|
+
* 4.add matching database WriteToFile and ReadFromFile support.
|
51
|
+
* 5.improve the predict accuracy.
|
52
|
+
* 6.find a strategy for misprediction.
|
53
|
+
*/
|
54
|
+
class TemplateMatch{
|
55
|
+
|
56
|
+
enum method{
|
57
|
+
INTERSECT,
|
58
|
+
MINUSDIST
|
59
|
+
};
|
60
|
+
|
61
|
+
public:
|
62
|
+
TemplateMatch(void);
|
63
|
+
~TemplateMatch(void);
|
64
|
+
/* A simple wrapper of SetLogoTemplate.
|
65
|
+
* The invoker cares no implement detail when use this method instead of SetLogoTemplate.
|
66
|
+
*/
|
67
|
+
int AddImageTemplate(string& imgName, string& label, Rect& roi = TemplateMatch::DefaultROI);
|
68
|
+
int AddLogoTemplate(slogo logo);
|
69
|
+
int AddLogoTemplate(string& lgName, Mat& ctMat, Mat& tplMat);
|
70
|
+
Mat* ExtractImageContour(string& imgName);
|
71
|
+
float CalcHistScore(Mat& srcMat, Mat& dstMat);
|
72
|
+
Rect GetContourRect(Mat& ctMat);
|
73
|
+
|
74
|
+
float MatchOneTemplate(Mat& dstContourMat, string label);
|
75
|
+
string MatchImage(string& imgName, float* score);
|
76
|
+
string RetrievebyScore(Mat& dstContourMat, Mat& dstMat, float* score);
|
77
|
+
int InsertMatchResult(string label, float ratio);
|
78
|
+
int SortMatchResult(bool bAscend = true);
|
79
|
+
vector< pair<string, float> > & GetMatchResult()
|
80
|
+
{
|
81
|
+
return mMatchResult;
|
82
|
+
}
|
83
|
+
|
84
|
+
static void SetDefaultROI(int x, int y, int width, int height){
|
85
|
+
DefaultROI = Rect(x, y, width, height);
|
86
|
+
}
|
87
|
+
|
88
|
+
vector<pair<string, float> > mMatchResult;
|
89
|
+
|
90
|
+
protected:
|
91
|
+
static Rect DefaultROI;
|
92
|
+
vector<slogo> mslogoArray;
|
93
|
+
float mMatchThresh;
|
94
|
+
float BilateralMatch(Mat& srcMat, Mat& dstMat, enum method m);
|
95
|
+
};
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
#endif
|
@@ -0,0 +1,176 @@
|
|
1
|
+
#include <unistd.h>
|
2
|
+
#include <stdio.h>
|
3
|
+
#include <stdlib.h>
|
4
|
+
#include <sys/time.h>
|
5
|
+
#include <string.h>
|
6
|
+
|
7
|
+
extern void* init_template_match(void);
|
8
|
+
extern int add_image_template(void* ptemplate_match, const char* template_img_path, const char* label, int x, int y , int width, int height);
|
9
|
+
|
10
|
+
extern void* init_image_feature(void* ptemplate_match, const char* img_path);
|
11
|
+
extern float match_image(void* ptemplate_match, void* pimage_feature, char* label);
|
12
|
+
extern void release_image_feature(void* pimage_feature);
|
13
|
+
|
14
|
+
extern void release_template_match(void* ptemplate_match);
|
15
|
+
|
16
|
+
char template_file_buffer[128] = {"templates.txt"};
|
17
|
+
char test_file_buffer[128] = {"test.txt"};
|
18
|
+
char test_label_buffer[128] = {"anhuiweishi"};
|
19
|
+
char* g_pTemplateFile = template_file_buffer;
|
20
|
+
char* g_pTestFile = test_file_buffer;
|
21
|
+
char* g_plabel = test_label_buffer;
|
22
|
+
int g_firstN = 1;
|
23
|
+
char helpBuffer[128] = "usage:logoRecognition -t templates -i image [-l label]\n";
|
24
|
+
|
25
|
+
|
26
|
+
int read_template_file(const char* templates_file, void* ptm)
|
27
|
+
{
|
28
|
+
if(!templates_file)
|
29
|
+
{
|
30
|
+
printf("templates_file is null!\n");
|
31
|
+
exit(-1);
|
32
|
+
}
|
33
|
+
|
34
|
+
FILE *fp = fopen(templates_file, "r+");
|
35
|
+
if(!fp)
|
36
|
+
{
|
37
|
+
printf("open templates_file error\n");
|
38
|
+
exit(-1);
|
39
|
+
}
|
40
|
+
char record[128]={0};
|
41
|
+
char *label, *x, *y, *width, *height;
|
42
|
+
x = y = width = height = NULL;
|
43
|
+
while(fgets(record, 128, fp) != NULL)
|
44
|
+
{
|
45
|
+
int pos = 0;
|
46
|
+
//strip the end '\n'
|
47
|
+
while(record[pos] != '\0' && record[pos] != '\n')
|
48
|
+
pos++;
|
49
|
+
if(record[pos] == '\n')
|
50
|
+
record[pos] = '\0';
|
51
|
+
|
52
|
+
//seperate filename and label by ','
|
53
|
+
pos = 0;
|
54
|
+
while(record[pos] != '\0' && record[pos] != ',')
|
55
|
+
pos++;
|
56
|
+
if(record[pos] == '\0')
|
57
|
+
{
|
58
|
+
printf("templates_file format error\n");
|
59
|
+
exit(-1);
|
60
|
+
}
|
61
|
+
record[pos] = '\0';
|
62
|
+
label = record + pos + 1;
|
63
|
+
|
64
|
+
//get x
|
65
|
+
pos++;
|
66
|
+
while(record[pos] != '\0' && record[pos] != ',')
|
67
|
+
pos++;
|
68
|
+
if(record[pos] == '\0')
|
69
|
+
{
|
70
|
+
printf("templates_file format error\n");
|
71
|
+
exit(-1);
|
72
|
+
}
|
73
|
+
record[pos] = '\0';
|
74
|
+
x = record + pos + 1;
|
75
|
+
|
76
|
+
//get y
|
77
|
+
pos++;
|
78
|
+
while(record[pos] != '\0' && record[pos] != ',')
|
79
|
+
pos++;
|
80
|
+
if(record[pos] == '\0')
|
81
|
+
{
|
82
|
+
printf("templates_file format error\n");
|
83
|
+
exit(-1);
|
84
|
+
}
|
85
|
+
record[pos] = '\0';
|
86
|
+
y = record + pos + 1;
|
87
|
+
|
88
|
+
//get width
|
89
|
+
pos++;
|
90
|
+
while(record[pos] != '\0' && record[pos] != ',')
|
91
|
+
pos++;
|
92
|
+
if(record[pos] == '\0')
|
93
|
+
{
|
94
|
+
printf("templates_file format error\n");
|
95
|
+
exit(-1);
|
96
|
+
}
|
97
|
+
record[pos] = '\0';
|
98
|
+
width = record + pos + 1;
|
99
|
+
|
100
|
+
//get height
|
101
|
+
pos++;
|
102
|
+
while(record[pos] != '\0' && record[pos] != ',')
|
103
|
+
pos++;
|
104
|
+
if(record[pos] == '\0')
|
105
|
+
{
|
106
|
+
printf("templates_file format error\n");
|
107
|
+
exit(-1);
|
108
|
+
}
|
109
|
+
record[pos] = '\0';
|
110
|
+
height = record + pos + 1;
|
111
|
+
|
112
|
+
add_image_template(ptm, record, label, atoi(x), atoi(y), atoi(width), atoi(height));
|
113
|
+
}
|
114
|
+
fclose(fp);
|
115
|
+
return 0;
|
116
|
+
}
|
117
|
+
|
118
|
+
int parse_args(int argc, char**argv)
|
119
|
+
{
|
120
|
+
if(argc != 5 && argc != 7)
|
121
|
+
{
|
122
|
+
printf("%s", helpBuffer);
|
123
|
+
exit(-1);
|
124
|
+
}
|
125
|
+
if( strcmp(argv[1] ,"-t") == 0 && strcmp(argv[3] , "-i") == 0)
|
126
|
+
{
|
127
|
+
sprintf(template_file_buffer, "%s", argv[2]);
|
128
|
+
sprintf(test_file_buffer, "%s", argv[4]);
|
129
|
+
}
|
130
|
+
else if( strcmp(argv[3] ,"-t") == 0 && strcmp(argv[1] , "-i") == 0 )
|
131
|
+
{
|
132
|
+
sprintf(template_file_buffer, "%s", argv[4]);
|
133
|
+
sprintf(test_file_buffer, "%s", argv[2]);
|
134
|
+
}
|
135
|
+
else
|
136
|
+
{
|
137
|
+
printf("%s", helpBuffer);
|
138
|
+
exit(-1);
|
139
|
+
}
|
140
|
+
|
141
|
+
if(argc == 7 && strcmp(argv[5], "-l") == 0)
|
142
|
+
{
|
143
|
+
sprintf(test_label_buffer, "%s", argv[6]);
|
144
|
+
}
|
145
|
+
|
146
|
+
return 0;
|
147
|
+
}
|
148
|
+
|
149
|
+
int main(int argc, char** argv)
|
150
|
+
{
|
151
|
+
parse_args(argc, argv);
|
152
|
+
void *ptm = init_template_match();
|
153
|
+
if(!ptm)
|
154
|
+
{
|
155
|
+
printf("init template match error, abort\n");
|
156
|
+
exit(-1);
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
read_template_file(g_pTemplateFile, ptm);
|
161
|
+
|
162
|
+
void *pfeature = init_image_feature(ptm, g_pTestFile);
|
163
|
+
if(!pfeature)
|
164
|
+
{
|
165
|
+
printf("init image feature error, abort\n");
|
166
|
+
exit(-1);
|
167
|
+
}
|
168
|
+
char result[32] = {0};
|
169
|
+
float score = match_image(ptm, pfeature, g_plabel);
|
170
|
+
printf("the match score is :%03f template:%20s\n", score, g_plabel);
|
171
|
+
release_image_feature(pfeature);
|
172
|
+
release_template_match(ptm);
|
173
|
+
|
174
|
+
|
175
|
+
return 0;
|
176
|
+
}
|
data/lib/logo.rb
ADDED
data/lib/logo/scouts.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
class Logo::Scouts
|
2
|
+
def initialize(yml)
|
3
|
+
@recognize = Logo::Recognize.new
|
4
|
+
@suite = Logo::Suite.new(@recognize)
|
5
|
+
@data = load_suite(yml)
|
6
|
+
end
|
7
|
+
|
8
|
+
def load_suite(yml)
|
9
|
+
@suite.load(yml)
|
10
|
+
end
|
11
|
+
|
12
|
+
def feature(img)
|
13
|
+
@recognize.image_feature(img)
|
14
|
+
end
|
15
|
+
|
16
|
+
def inspect(the_feature, label)
|
17
|
+
@recognize.match(the_feature, label)
|
18
|
+
end
|
19
|
+
|
20
|
+
def release_feature(the_feature)
|
21
|
+
@recognize.release_feature(the_feature)
|
22
|
+
end
|
23
|
+
|
24
|
+
def show_hand(img)
|
25
|
+
the_feature = self.feature(img)
|
26
|
+
|
27
|
+
scores = {}
|
28
|
+
max_score = [1, '']
|
29
|
+
@data.each do |item|
|
30
|
+
label = item['label']
|
31
|
+
scores[label] = inspect(the_feature, label)
|
32
|
+
if scores[label] < max_score.first
|
33
|
+
max_score = [scores[label], label]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
self.release_feature(the_feature)
|
38
|
+
return scores, max_score
|
39
|
+
end
|
40
|
+
end
|
data/lib/logo/suite.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
class Logo::Suite
|
4
|
+
attr_accessor :recognize, :data
|
5
|
+
|
6
|
+
def initialize(recognize)
|
7
|
+
@recognize = recognize
|
8
|
+
end
|
9
|
+
|
10
|
+
def load(yml)
|
11
|
+
File.open(yml, 'r') do |file|
|
12
|
+
@data = YAML.load(file)
|
13
|
+
end
|
14
|
+
|
15
|
+
prefix = File.dirname(yml)
|
16
|
+
|
17
|
+
# item
|
18
|
+
# => {"path"=>"test/suite/snap4train_raw/anhuiweishi/1370432428.jpg", "label"=>"anhuiweishi", "x"=>40, "y"=>45, "w"=>102, "h"=>78}
|
19
|
+
@data.each do |item|
|
20
|
+
item['path'] = File.join(prefix, item['path'])
|
21
|
+
@recognize.add_image(item)
|
22
|
+
end
|
23
|
+
|
24
|
+
@data
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- 崔峥
|
9
|
+
- 邱戴飞
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-06-20 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rdoc
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: bundler
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: jeweler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: pkg-config
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
description: longer description of your gem
|
80
|
+
email: zheng.cuizh@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions:
|
83
|
+
- ext/logo/recognize/extconf.rb
|
84
|
+
extra_rdoc_files:
|
85
|
+
- LICENSE.txt
|
86
|
+
- README.rdoc
|
87
|
+
files:
|
88
|
+
- ext/logo/recognize/extconf.rb
|
89
|
+
- ext/logo/recognize/recognize.c
|
90
|
+
- ext/logo/recognize/recognize.h
|
91
|
+
- ext/logo/recognize/template_match.h
|
92
|
+
- ext/logo/recognize/template_match_test.c
|
93
|
+
- lib/logo.rb
|
94
|
+
- lib/logo/scouts.rb
|
95
|
+
- lib/logo/suite.rb
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.rdoc
|
98
|
+
homepage: http://github.com/charlescui/logo
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
segments:
|
112
|
+
- 0
|
113
|
+
hash: -3676594657977265235
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ! '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 1.8.24
|
123
|
+
signing_key:
|
124
|
+
specification_version: 3
|
125
|
+
summary: one-line summary of your gem
|
126
|
+
test_files: []
|