Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

this is going to be final swt

  • Loading branch information...
commit ee61ab62621a7a92c34f79d661cbcadb682dd746 1 parent 6174b65
@liuliu authored
Showing with 56 additions and 88 deletions.
  1. +23 −40 bin/swtcreate.c
  2. +24 −43 bin/swtdetect.c
  3. +4 −4 bin/swtvldtr.rb
  4. +5 −1 doc/swt.md
View
63 bin/swtcreate.c
@@ -233,28 +233,28 @@ int main(int argc, char** argv)
if (argc <= 1)
exit_with_help();
ccv_swt_param_t params = {
- .interval = 5,
- .same_word_thresh = { 0.5, 0.9 },
- .min_neighbors = 2,
+ .interval = 1,
+ .same_word_thresh = { 0.2, 0.8 },
+ .min_neighbors = 1,
.scale_invariant = 0,
.size = 3,
- .low_thresh = 65,
- .high_thresh = 212,
- .max_height = 500,
- .min_height = 14,
- .min_area = 94,
- .letter_occlude_thresh = 4,
- .aspect_ratio = 9,
- .std_ratio = 0.95,
- .thickness_ratio = 1.7,
- .height_ratio = 1.8,
- .intensity_thresh = 34,
- .distance_ratio = 3.3,
- .intersect_ratio = 1.2,
- .letter_thresh = 4,
- .elongate_ratio = 1.9,
+ .low_thresh = 78,
+ .high_thresh = 214,
+ .max_height = 300,
+ .min_height = 10,
+ .min_area = 75,
+ .letter_occlude_thresh = 2,
+ .aspect_ratio = 10,
+ .std_ratio = 0.5,
+ .thickness_ratio = 1.5,
+ .height_ratio = 2.0,
+ .intensity_thresh = 45,
+ .distance_ratio = 3.0,
+ .intersect_ratio = 2.0,
+ .letter_thresh = 3,
+ .elongate_ratio = 1.3,
.breakdown = 1,
- .breakdown_ratio = 0.82,
+ .breakdown_ratio = 1.0,
};
ccv_swt_range_t size_range = {
.min_value = 1,
@@ -358,7 +358,7 @@ int main(int argc, char** argv)
.step = 0.01,
.enable = 1,
};
- int i, j, k, l, iterations = 10;
+ int i, j, k, iterations = 10;
while (getopt_long_only(argc - 1, argv + 1, "", swt_options, &k) != -1)
{
switch (k)
@@ -486,27 +486,10 @@ int main(int argc, char** argv)
ccv_read(name, &image, CCV_IO_GRAY | CCV_IO_ANY_FILE); \
ccv_array_t* truth = *(ccv_array_t**)ccv_array_get(aow, j); \
total_truth += truth->rnum; \
- int upscaled = (image->rows < 500 || image->cols < 500); \
- if (upscaled) \
- { \
- ccv_dense_matrix_t* up2x = 0; \
- ccv_sample_up(image, &up2x, 0, 0, 0); \
- ccv_matrix_free(image); \
- image = up2x; \
- } \
for (v = parameter##_range.min_value, k = 0; v <= parameter##_range.max_value; v += parameter##_range.step, k++) \
{ \
params.parameter = (type)(v + rounding); \
ccv_array_t* words = ccv_swt_detect_words(image, params); \
- if (upscaled) \
- for (l = 0; l < words->rnum; l++) \
- { \
- ccv_rect_t* word = (ccv_rect_t*)ccv_array_get(words, l); \
- word->x /= 2; \
- word->y /= 2; \
- word->width /= 2; \
- word->height /= 2; \
- } \
double one_precision = 0, one_recall = 0; \
_ccv_evaluate_wolf(words, truth, params, &one_precision, &one_recall); \
assert(one_precision <= words->rnum + 0.1); \
@@ -542,14 +525,12 @@ int main(int argc, char** argv)
for (i = 0; i < iterations; i++)
{
optimize(size, int, 0.5);
- optimize(low_thresh, int, 0.5);
- optimize(high_thresh, int, 0.5);
+ optimize(std_ratio, double, 0);
optimize(max_height, int, 0.5);
optimize(min_height, int, 0.5);
optimize(min_area, int, 0.5);
optimize(letter_occlude_thresh, int, 0.5);
optimize(aspect_ratio, double, 0);
- optimize(std_ratio, double, 0);
optimize(thickness_ratio, double, 0);
optimize(height_ratio, double, 0);
optimize(intensity_thresh, int, 0.5);
@@ -558,6 +539,8 @@ int main(int argc, char** argv)
optimize(letter_thresh, int, 0.5);
optimize(elongate_ratio, double, 0);
optimize(breakdown_ratio, double, 0);
+ optimize(low_thresh, int, 0.5);
+ optimize(high_thresh, int, 0.5);
printf("At iteration %d(of %d) : best parameters for swt is:\n"
"\tsize = %d\n"
"\tlow_thresh = %d\n"
View
67 bin/swtdetect.c
@@ -12,26 +12,26 @@ unsigned int get_current_time()
int main(int argc, char** argv)
{
ccv_swt_param_t params = {
- .interval = 2,
- .same_word_thresh = { 0.5, 0.9 },
- .min_neighbors = 0,
+ .interval = 1,
+ .same_word_thresh = { 0.1, 0.8 },
+ .min_neighbors = 1,
.scale_invariant = 1,
.size = 3,
- .low_thresh = 75,
- .high_thresh = 250,
+ .low_thresh = 124,
+ .high_thresh = 204,
.max_height = 300,
- .min_height = 14,
- .min_area = 75,
+ .min_height = 8,
+ .min_area = 38,
.letter_occlude_thresh = 3,
- .aspect_ratio = 10,
- .std_ratio = 0.75,
- .thickness_ratio = 2.0,
- .height_ratio = 2.0,
- .intensity_thresh = 35,
- .distance_ratio = 3.0,
- .intersect_ratio = 1.5,
+ .aspect_ratio = 8,
+ .std_ratio = 0.83,
+ .thickness_ratio = 1.5,
+ .height_ratio = 1.7,
+ .intensity_thresh = 31,
+ .distance_ratio = 2.9,
+ .intersect_ratio = 1.3,
.letter_thresh = 3,
- .elongate_ratio = 2.0,
+ .elongate_ratio = 1.9,
.breakdown = 1,
.breakdown_ratio = 1.0,
};
@@ -41,10 +41,7 @@ int main(int argc, char** argv)
if (image != 0)
{
unsigned int elapsed_time = get_current_time();
- ccv_dense_matrix_t* up2x = 0;
- ccv_sample_up(image, &up2x, 0, 0, 0);
- ccv_array_t* words = ccv_swt_detect_words(up2x, params);
- ccv_matrix_free(up2x);
+ ccv_array_t* words = ccv_swt_detect_words(image, params);
elapsed_time = get_current_time() - elapsed_time;
if (words)
{
@@ -52,7 +49,7 @@ int main(int argc, char** argv)
for (i = 0; i < words->rnum; i++)
{
ccv_rect_t* rect = (ccv_rect_t*)ccv_array_get(words, i);
- printf("%d %d %d %d\n", rect->x / 2, rect->y / 2, rect->width / 2, rect->height / 2);
+ printf("%d %d %d %d\n", rect->x, rect->y, rect->width, rect->height);
}
printf("total : %d in time %dms\n", words->rnum, elapsed_time);
ccv_array_free(words);
@@ -73,32 +70,16 @@ int main(int argc, char** argv)
read--;
file[read] = 0;
image = 0;
+ printf("%s\n", file);
ccv_read(file, &image, CCV_IO_GRAY | CCV_IO_ANY_FILE);
- if (image->rows < 500 || image->cols < 500)
+ ccv_array_t* words = ccv_swt_detect_words(image, params);
+ int i;
+ for (i = 0; i < words->rnum; i++)
{
- ccv_dense_matrix_t* up2x = 0;
- ccv_sample_up(image, &up2x, 0, 0, 0);
- ccv_array_t* words = ccv_swt_detect_words(up2x, params);
- ccv_matrix_free(up2x);
- int i;
- printf("%s\n", file);
- for (i = 0; i < words->rnum; i++)
- {
- ccv_rect_t* rect = (ccv_rect_t*)ccv_array_get(words, i);
- printf("%d %d %d %d\n", rect->x / 2, rect->y / 2, rect->width / 2, rect->height / 2);
- }
- ccv_array_free(words);
- } else {
- ccv_array_t* words = ccv_swt_detect_words(image, params);
- int i;
- printf("%s\n", file);
- for (i = 0; i < words->rnum; i++)
- {
- ccv_rect_t* rect = (ccv_rect_t*)ccv_array_get(words, i);
- printf("%d %d %d %d\n", rect->x, rect->y, rect->width, rect->height);
- }
- ccv_array_free(words);
+ ccv_rect_t* rect = (ccv_rect_t*)ccv_array_get(words, i);
+ printf("%d %d %d %d\n", rect->x, rect->y, rect->width, rect->height);
}
+ ccv_array_free(words);
ccv_matrix_free(image);
}
free(file);
View
8 bin/swtvldtr.rb
@@ -13,24 +13,24 @@
file = File.new(ARGV[0])
filename = nil
file.each do |line|
- if line =~ /\d+\s\d+\s\d+\s\d+/
+ if line =~ /-{0,1}\d+\s-{0,1}\d+\s-{0,1}\d+\s-{0,1}\d+/
truth[filename] = Array.new unless truth.has_key? filename
nb = line.split " "
truth[filename] << { :x => nb[0].to_f, :y => nb[1].to_f, :width => nb[2].to_f, :height => nb[3].to_f }
else
- filename = line
+ filename = line.strip
end
end
estimate = Hash.new
file = File.new(ARGV[1])
file.each do |line|
- if line =~ /\d+\s\d+\s\d+\s\d+/
+ if line =~ /-{0,1}\d+\s-{0,1}\d+\s-{0,1}\d+\s-{0,1}\d+/
estimate[filename] = Array.new unless estimate.has_key? filename
nb = line.split(" ")
estimate[filename] << { :x => nb[0].to_f, :y => nb[1].to_f, :width => nb[2].to_f, :height => nb[3].to_f }
else
- filename = line
+ filename = line.strip
end
end
View
6 doc/swt.md
@@ -35,7 +35,7 @@ method described in ICDAR 2003 contest, ccv's implementation was able to achieve
precision rate at 66% and recall rate at 59% (numbers reported in the paper are
precision rate 73% and recall rate at 60%).
-However, these results are quite out-dated, and using [ICDAR 2011 dataset](http://robustreading.opendfki.de/wiki/SceneText)
+However, these results are quite out-dated, and by using [ICDAR 2011 dataset](http://robustreading.opendfki.de/wiki/SceneText),
more meaningful comparison is possible.
With ccv's scale-invariant SWT implementation, and do parameter search on ICDAR
@@ -52,3 +52,7 @@ and doesn't use any language specific features.
Speed-wise:
+How can I adopt SWT for my application?
+---------------------------------------
+
+SWT has
Please sign in to comment.
Something went wrong with that request. Please try again.