aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpdp_opencv_cvk-help.pd62
-rwxr-xr-xpdp_opencv_cvk.cc26
2 files changed, 59 insertions, 29 deletions
diff --git a/pdp_opencv_cvk-help.pd b/pdp_opencv_cvk-help.pd
index 118284a..ad16531 100755
--- a/pdp_opencv_cvk-help.pd
+++ b/pdp_opencv_cvk-help.pd
@@ -1,4 +1,4 @@
-#N canvas 257 49 833 785 10;
+#N canvas 262 49 833 785 10;
#X obj -17 -54 cnv 15 700 350 empty empty empty 20 12 0 14 -260097
-66577 0;
#X obj 226 -30 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1
@@ -14,7 +14,7 @@
#X msg 273 189 cursor 1;
#X msg 317 166 rgb 0 0 0;
#X obj 449 166 loadbang;
-#X msg 110 375 bang;
+#X msg 87 320 bang;
#X text -13 -110 pdp_opencv_cvk : OCR-like pattern recognition;
#X text -13 -99 based on basic OCR with Open CV tutorial;
#X text -13 -88 by damiles : http://blog.damiles.com/?p=93;
@@ -35,18 +35,15 @@
;
#X obj 28 109 pdp_scale 128 128;
#X text 65 -35 Test with an image;
-#X text 235 457 Distance of the incoming symbol compared to the patterns
-;
#X obj 29 226 pdp_binary;
-#X text 147 376 compare the incoming frame to the patterns;
#X text 359 108 <-- clear the input and try again;
#X obj 222 167 pdp_pen ------;
#X obj 226 48 pdp_convert image/YCrCb/*;
#X text 340 76 <-- this must be the same size as your patterns;
#X obj 226 78 pdp_scale 128 128;
-#X obj 167 397 s pclear;
+#X obj 144 342 s pclear;
#X obj 298 108 r pclear;
-#X obj 109 398 del 1000;
+#X obj 86 343 del 1000;
#X msg 384 167 width 8;
#N canvas 5 49 634 415 thingsidontwanttosee 0;
#X msg 267 202 draw \$1 \$2;
@@ -71,24 +68,31 @@
#X restore 270 138 pd thingsidontwanttosee;
#X text 421 137 <-- mouse events;
#X obj 19 423 pdp_opencv_cvk plus 50;
+#X text 235 457 Distance of the incoming frame compared to the patterns
+;
+#X msg 110 398 load ../plus 50;
+#X text 124 321 Compare the incoming frame to the patterns;
+#X text 210 379 Load a new set of patterns from a directory;
+#X text 211 391 All patterns should be of the same size;
+#X msg 100 371 load ../plus 50;
#X connect 1 0 2 0;
#X connect 2 0 7 0;
#X connect 5 0 4 0;
-#X connect 7 0 36 0;
-#X connect 8 0 43 0;
+#X connect 7 0 34 0;
+#X connect 8 0 41 0;
#X connect 9 0 8 0;
-#X connect 10 0 35 0;
+#X connect 10 0 33 0;
#X connect 11 0 10 0;
-#X connect 11 0 42 0;
-#X connect 12 0 41 0;
-#X connect 12 0 45 0;
-#X connect 18 0 35 0;
+#X connect 11 0 40 0;
+#X connect 12 0 39 0;
+#X connect 12 0 43 0;
+#X connect 18 0 33 0;
#X connect 19 0 24 0;
#X connect 20 0 19 0;
#X connect 20 0 23 0;
#X connect 20 0 28 0;
#X connect 21 0 27 0;
-#X connect 22 0 32 0;
+#X connect 22 0 31 0;
#X connect 22 0 26 0;
#X connect 23 0 21 0;
#X connect 24 0 22 0;
@@ -96,16 +100,18 @@
#X connect 27 0 29 0;
#X connect 28 0 23 0;
#X connect 29 0 22 0;
-#X connect 32 0 45 0;
-#X connect 35 0 8 0;
-#X connect 35 0 9 0;
-#X connect 35 0 32 0;
-#X connect 36 0 38 0;
-#X connect 38 0 35 0;
-#X connect 40 0 18 0;
-#X connect 41 0 39 0;
-#X connect 42 0 35 0;
-#X connect 43 0 35 0;
-#X connect 45 0 4 0;
-#X connect 45 0 5 0;
-#X connect 45 1 6 0;
+#X connect 31 0 43 0;
+#X connect 33 0 8 0;
+#X connect 33 0 9 0;
+#X connect 33 0 31 0;
+#X connect 34 0 36 0;
+#X connect 36 0 33 0;
+#X connect 38 0 18 0;
+#X connect 39 0 37 0;
+#X connect 40 0 33 0;
+#X connect 41 0 33 0;
+#X connect 43 0 4 0;
+#X connect 43 0 5 0;
+#X connect 43 1 6 0;
+#X connect 45 0 43 0;
+#X connect 49 0 43 0;
diff --git a/pdp_opencv_cvk.cc b/pdp_opencv_cvk.cc
index e75accd..5e94737 100755
--- a/pdp_opencv_cvk.cc
+++ b/pdp_opencv_cvk.cc
@@ -147,7 +147,7 @@ static void pdp_opencv_cvk_process_rgb(t_pdp_opencv_cvk *x)
}
outlet_float(x->x_outlet1, x->x_dist->data.fl[0]);
- // cvReleaseImage( &img32 );
+ cvReleaseImage( &img32 );
x->x_classify = 0;
}
@@ -222,6 +222,8 @@ static void pdp_opencv_cvk_free(t_pdp_opencv_cvk *x)
// destroy cv_images
cvReleaseImage( &x->rgb );
cvReleaseImage( &x->grey );
+ cvReleaseMat( &x->trainData );
+ cvReleaseMat( &x->trainClasses );
}
@@ -414,6 +416,7 @@ void pdp_opencv_cvk_load(t_pdp_opencv_cvk *x)
// convert data matrix sizexsize to vecor
row1 = cvReshape( &data, &row_header, 0, 1 );
cvCopy(row1, &row, NULL);
+ cvReleaseImage( &img );
}
// create the classifier
@@ -436,6 +439,26 @@ static void pdp_opencv_cvk_classify(t_pdp_opencv_cvk *x)
x->x_classify=1;
}
+static void pdp_opencv_cvk_pload(t_pdp_opencv_cvk *x, t_symbol *path, t_floatarg nsamples )
+{
+ if ( (int) nsamples <= 0 )
+ {
+ post( "pdp_opencv_cvk : wrong number of samples : %d", nsamples );
+ return;
+ }
+ else
+ {
+ x->x_nsamples = (int)nsamples;
+ x->x_rsamples = 0;
+ cvReleaseMat( &x->trainData );
+ cvReleaseMat( &x->trainClasses );
+ x->trainData = NULL;
+ x->trainClasses = NULL;
+ }
+ strcpy( x->x_filepath, path->s_name );
+ pdp_opencv_cvk_load(x);
+}
+
void *pdp_opencv_cvk_new(t_symbol *s, int argc, t_atom *argv )
{
int i;
@@ -524,6 +547,7 @@ void pdp_opencv_cvk_setup(void)
class_addmethod(pdp_opencv_cvk_class, (t_method)pdp_opencv_cvk_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL);
class_addmethod(pdp_opencv_cvk_class, (t_method)pdp_opencv_cvk_classify, gensym("bang"), A_NULL);
+ class_addmethod(pdp_opencv_cvk_class, (t_method)pdp_opencv_cvk_pload, gensym("load"), A_SYMBOL, A_DEFFLOAT, A_NULL);
}