objectdetect 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,13 +9,18 @@
9
9
 
10
10
  /*
11
11
  call-seq:
12
- ObjectDetect::detect(model_path, target_path) -> [[x,y,width,height]]
12
+ ObjectDetect::detect(model_path, target_path, rescale_size=nil) -> [[x,y,width,height]]
13
13
 
14
14
  Detects objects in the image file +target_path+.
15
15
  +model_path+ needs to point a model file (e.g. /usr/local/share/opencv/haarcascades/haarcascade_frontalface_alt2.xml).
16
+ If +rescale_size+ is specified and the width or height of the image is larger than +rescale_size+,
17
+ the image is rescaled to fit into the size before processing.
16
18
  */
17
- static VALUE rb_detect(VALUE self, VALUE model_path, VALUE target_path)
19
+ static VALUE rb_detect(int argc, VALUE *argv, VALUE self)
18
20
  {
21
+ VALUE model_path, target_path, rescale_size;
22
+ rb_scan_args(argc, argv, "21", &model_path, &target_path, &rescale_size);
23
+
19
24
  Check_Type(model_path, T_STRING);
20
25
  Check_Type(target_path, T_STRING);
21
26
 
@@ -27,7 +32,8 @@ static VALUE rb_detect(VALUE self, VALUE model_path, VALUE target_path)
27
32
 
28
33
  /* load the target picture */
29
34
  IplImage *img = cvLoadImage(RSTRING(target_path)->ptr, 1);
30
- if( img == 0 ) {
35
+ if( !img ) {
36
+ cvReleaseHaarClassifierCascade(&cascade);
31
37
  rb_raise(rb_eArgError, "Can't load the image file");
32
38
  }
33
39
 
@@ -37,13 +43,16 @@ static VALUE rb_detect(VALUE self, VALUE model_path, VALUE target_path)
37
43
  cvEqualizeHist(gray, gray);
38
44
 
39
45
  /* rescale */
40
- int width_limit = 320, height_limit = 320;
41
- double scale_w, scale_h, scale;
42
- scale_w = (double)img->width/width_limit;
43
- scale_h = (double)img->height/height_limit;
44
- scale = (scale_w>scale_h) ? scale_w : scale_h;
45
- if(scale < 1)
46
- scale = 1;
46
+ double scale = 1;
47
+ if(argc == 3 || rescale_size != Qnil) {
48
+ double limit = (double)NUM2INT(rescale_size);
49
+ double scale_w, scale_h;
50
+ scale_w = (double)img->width/limit;
51
+ scale_h = (double)img->height/limit;
52
+ scale = (scale_w>scale_h) ? scale_w : scale_h;
53
+ if(scale < 1)
54
+ scale = 1;
55
+ }
47
56
  IplImage* small_img = cvCreateImage( cvSize( cvRound (img->width/scale),
48
57
  cvRound (img->height/scale)),
49
58
  8, 1 );
@@ -81,5 +90,5 @@ void Init_objectdetect()
81
90
  {
82
91
  VALUE module;
83
92
  module = rb_define_module("ObjectDetect");
84
- rb_define_module_function(module, "detect", rb_detect, 2);
93
+ rb_define_module_function(module, "detect", rb_detect, -1);
85
94
  }
@@ -2,7 +2,7 @@ module Objectdetect #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.1
3
3
  specification_version: 1
4
4
  name: objectdetect
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.2
7
- date: 2007-03-14 00:00:00 +09:00
6
+ version: 0.0.3
7
+ date: 2007-03-16 00:00:00 +09:00
8
8
  summary: A simple library for detecting objects in pictures.
9
9
  require_paths:
10
10
  - lib