diff options
-rw-r--r-- | Makefile | 4 | ||||
-rwxr-xr-x | pdp_opencv_cvk-help.pd | 111 | ||||
-rwxr-xr-x | pdp_opencv_cvk.cc | 532 | ||||
-rw-r--r-- | plus/000.png | bin | 0 -> 367 bytes | |||
-rw-r--r-- | plus/001.png | bin | 0 -> 436 bytes | |||
-rw-r--r-- | plus/002.png | bin | 0 -> 407 bytes | |||
-rw-r--r-- | plus/003.png | bin | 0 -> 454 bytes | |||
-rw-r--r-- | plus/004.png | bin | 0 -> 421 bytes | |||
-rw-r--r-- | plus/005.png | bin | 0 -> 416 bytes | |||
-rw-r--r-- | plus/006.png | bin | 0 -> 429 bytes | |||
-rw-r--r-- | plus/007.png | bin | 0 -> 408 bytes | |||
-rw-r--r-- | plus/008.png | bin | 0 -> 373 bytes | |||
-rw-r--r-- | plus/009.png | bin | 0 -> 390 bytes | |||
-rw-r--r-- | plus/010.png | bin | 0 -> 406 bytes | |||
-rw-r--r-- | plus/011.png | bin | 0 -> 429 bytes | |||
-rw-r--r-- | plus/012.png | bin | 0 -> 460 bytes | |||
-rw-r--r-- | plus/013.png | bin | 0 -> 546 bytes | |||
-rw-r--r-- | plus/014.png | bin | 0 -> 486 bytes | |||
-rw-r--r-- | plus/015.png | bin | 0 -> 459 bytes | |||
-rw-r--r-- | plus/016.png | bin | 0 -> 440 bytes | |||
-rw-r--r-- | plus/017.png | bin | 0 -> 372 bytes | |||
-rw-r--r-- | plus/018.png | bin | 0 -> 434 bytes | |||
-rw-r--r-- | plus/019.png | bin | 0 -> 370 bytes | |||
-rw-r--r-- | plus/020.png | bin | 0 -> 399 bytes | |||
-rw-r--r-- | plus/021.png | bin | 0 -> 374 bytes | |||
-rw-r--r-- | plus/022.png | bin | 0 -> 452 bytes | |||
-rw-r--r-- | plus/023.png | bin | 0 -> 434 bytes | |||
-rw-r--r-- | plus/024.png | bin | 0 -> 417 bytes | |||
-rw-r--r-- | plus/025.png | bin | 0 -> 374 bytes | |||
-rw-r--r-- | plus/026.png | bin | 0 -> 381 bytes | |||
-rw-r--r-- | plus/027.png | bin | 0 -> 373 bytes | |||
-rw-r--r-- | plus/028.png | bin | 0 -> 412 bytes | |||
-rw-r--r-- | plus/029.png | bin | 0 -> 446 bytes | |||
-rw-r--r-- | plus/030.png | bin | 0 -> 373 bytes | |||
-rw-r--r-- | plus/031.png | bin | 0 -> 487 bytes | |||
-rw-r--r-- | plus/032.png | bin | 0 -> 410 bytes | |||
-rw-r--r-- | plus/033.png | bin | 0 -> 390 bytes | |||
-rw-r--r-- | plus/034.png | bin | 0 -> 454 bytes | |||
-rw-r--r-- | plus/035.png | bin | 0 -> 373 bytes | |||
-rw-r--r-- | plus/036.png | bin | 0 -> 406 bytes | |||
-rw-r--r-- | plus/037.png | bin | 0 -> 390 bytes | |||
-rw-r--r-- | plus/038.png | bin | 0 -> 381 bytes | |||
-rw-r--r-- | plus/039.png | bin | 0 -> 400 bytes | |||
-rw-r--r-- | plus/040.png | bin | 0 -> 413 bytes | |||
-rw-r--r-- | plus/041.png | bin | 0 -> 370 bytes | |||
-rw-r--r-- | plus/042.png | bin | 0 -> 447 bytes | |||
-rw-r--r-- | plus/043.png | bin | 0 -> 411 bytes | |||
-rw-r--r-- | plus/044.png | bin | 0 -> 502 bytes | |||
-rw-r--r-- | plus/045.png | bin | 0 -> 406 bytes | |||
-rw-r--r-- | plus/046.png | bin | 0 -> 417 bytes | |||
-rw-r--r-- | plus/047.png | bin | 0 -> 463 bytes | |||
-rw-r--r-- | plus/048.png | bin | 0 -> 438 bytes | |||
-rw-r--r-- | plus/049.png | bin | 0 -> 457 bytes |
53 files changed, 645 insertions, 2 deletions
@@ -37,9 +37,9 @@ endif .SUFFIXES = $(EXTENSION) -SOURCES = pdp_opencv_threshold.c pdp_opencv_edge.c pdp_opencv_distrans.c pdp_opencv_laplace.c pdp_opencv_motempl.c pdp_opencv_morphology.c pdp_opencv_haarcascade.c pdp_opencv_contours_convexity.c pdp_opencv_contours_boundingrect.c pdp_opencv_bgsubstract.c pdp_opencv_lk.c pdp_opencv_floodfill.c pdp_opencv_histo.c pdp_opencv_dft.c +SOURCES = pdp_opencv_threshold.c pdp_opencv_edge.c pdp_opencv_distrans.c pdp_opencv_laplace.c pdp_opencv_motempl.c pdp_opencv_morphology.c pdp_opencv_haarcascade.c pdp_opencv_contours_convexity.c pdp_opencv_contours_boundingrect.c pdp_opencv_bgsubstract.c pdp_opencv_lk.c pdp_opencv_floodfill.c pdp_opencv_histo.c pdp_opencv_dft.c pdp_opencv_cvk.cc -all: $(SOURCES:.c=.$(EXTENSION)) +all: $(SOURCES:.c=.$(EXTENSION)) $(SOURCES:.cc=.$(EXTENSION)) %.$(EXTENSION): %.o gcc $(LDFLAGS) -o $*.$(EXTENSION) $*.o $(LIBS) diff --git a/pdp_opencv_cvk-help.pd b/pdp_opencv_cvk-help.pd new file mode 100755 index 0000000..118284a --- /dev/null +++ b/pdp_opencv_cvk-help.pd @@ -0,0 +1,111 @@ +#N canvas 257 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 +1; +#X obj 226 -4 metro 40; +#X obj -15 303 cnv 15 621 300 empty empty empty 20 12 0 14 -258113 +-66577 0; +#X obj 26 626 pdp_xv; +#X msg 116 610 cursor 1; +#X floatatom 163 456 10 0 0 0 - - -; +#X obj 225 21 pdp_background; +#X obj 223 190 pdp_xv; +#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 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; +#X text -13 -75 adapted to PD by Yves Degoyon ( ydegoyon@gmail.com +); +#X text 253 -32 Hand drawing input; +#X msg 255 107 clear; +#X obj 48 -6 openpanel; +#X msg 29 -35 bang; +#X obj 28 62 pdp_background; +#X obj 30 139 pdp_imgloader; +#X obj 28 39 metro 40; +#X msg 47 18 load \$1 0 0; +#X floatatom 123 64 5 0 0 0 - - -; +#X obj 56 166 pdp_xv; +#X obj 29 86 pdp_convert image/YCrCb/*; +#X obj 3 11 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1 +; +#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 298 108 r pclear; +#X obj 109 398 del 1000; +#X msg 384 167 width 8; +#N canvas 5 49 634 415 thingsidontwanttosee 0; +#X msg 267 202 draw \$1 \$2; +#X obj 358 202 unpack f f; +#X obj 343 228 f; +#X obj 370 228 f; +#X msg 380 179 fill \$1 \$2; +#X obj 342 248 pack f f; +#X obj 227 179 route press drag release; +#X obj 230 148 inlet; +#X obj 258 274 outlet; +#X connect 0 0 8 0; +#X connect 1 0 2 1; +#X connect 1 1 3 1; +#X connect 2 0 5 0; +#X connect 3 0 5 1; +#X connect 4 0 8 0; +#X connect 5 0 4 0; +#X connect 6 0 1 0; +#X connect 6 1 0 0; +#X connect 7 0 6 0; +#X restore 270 138 pd thingsidontwanttosee; +#X text 421 137 <-- mouse events; +#X obj 19 423 pdp_opencv_cvk 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 9 0 8 0; +#X connect 10 0 35 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 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 26 0; +#X connect 23 0 21 0; +#X connect 24 0 22 0; +#X connect 25 0 21 3; +#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; diff --git a/pdp_opencv_cvk.cc b/pdp_opencv_cvk.cc new file mode 100755 index 0000000..e75accd --- /dev/null +++ b/pdp_opencv_cvk.cc @@ -0,0 +1,532 @@ +/* + * Pure Data Packet module. + * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * + * pdp_opencv_cvk : OCR like pattern recognition + * based on basic OCR with Open CV tutorial + * by damiles : http://blog.damiles.com/?p=93 + * + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <dirent.h> +#include <limits.h> +#include <dlfcn.h> +#include <ctype.h> + +#include "pdp.h" + +#include "cv.h" +#include "highgui.h" +#include "ml.h" + +#define MAX_MARKERS 10 + +const int MAX_COUNT = 500; + +typedef struct pdp_opencv_cvk_struct +{ + t_object x_obj; + t_float x_f; + + t_outlet *x_outlet0; + t_outlet *x_outlet1; + + int x_packet0; + int x_packet1; + int x_dropped; + int x_queue_id; + + int x_width; + int x_height; + int x_size; + + int x_classify; + int x_ROIx; + int x_ROIy; + int x_ROIw; + int x_ROIh; + + // The output and temporary images + IplImage *rgb, *grey; + + // open cv classifier data + char *x_filepath; + int x_nsamples; + int x_rsamples; + CvMat* trainData; + CvMat* trainClasses; + CvMat* x_nearest; + CvMat* x_dist; + int x_pwidth; + int x_pheight; + CvKNearest *knn; + +} t_pdp_opencv_cvk; + +IplImage pdp_opencv_cvk_preprocessing(IplImage* imgSrc,int new_width, int new_height); + +static void pdp_opencv_cvk_process_rgb(t_pdp_opencv_cvk *x) +{ + t_pdp *header = pdp_packet_header(x->x_packet0); + short int *data = (short int *)pdp_packet_data(x->x_packet0); + t_pdp *newheader = pdp_packet_header(x->x_packet1); + short int *newdata = (short int *)pdp_packet_data(x->x_packet1); + int i,j,k,im; + + if ((x->x_width != (t_int)header->info.image.width) || + (x->x_height != (t_int)header->info.image.height)) + { + + post("pdp_opencv_cvk :: resizing"); + + x->x_width = header->info.image.width; + x->x_height = header->info.image.height; + x->x_size = x->x_width*x->x_height; + x->x_ROIx = 0; + x->x_ROIy = 0; + x->x_ROIw = header->info.image.width; + x->x_ROIh = header->info.image.height; + + cvReleaseImage( &x->rgb ); + cvReleaseImage( &x->grey ); + + // create cv_images + x->rgb = cvCreateImage( cvSize(x->x_width, x->x_height), 8, 3 ); + x->grey = cvCreateImage( cvSize(x->x_width, x->x_height), 8, 1 ); + + } + + newheader->info.image.encoding = header->info.image.encoding; + newheader->info.image.width = x->x_width; + newheader->info.image.height = x->x_height; + + memcpy( x->rgb->imageData, data, x->x_size*3 ); + + cvCvtColor( x->rgb, x->grey, CV_BGR2GRAY ); + + if ( x->x_classify ) + { + IplImage prs_image; + float result; + CvMat row_header, *row1, odata; + + // post( "pdp_opencv_cvk : size : (%dx%d)", x->x_pwidth, x->x_pheight); + + // process file + prs_image = pdp_opencv_cvk_preprocessing(x->grey, x->x_pwidth, x->x_pheight); + + //Set data + IplImage* img32 = cvCreateImage( cvSize( x->x_pwidth, x->x_pheight ), IPL_DEPTH_32F, 1 ); + cvConvertScale(&prs_image, img32, 0.0039215, 0); + cvGetSubRect(img32, &odata, cvRect(0,0, x->x_pwidth, x->x_pheight)); + row1 = cvReshape( &odata, &row_header, 0, 1 ); + + result=x->knn->find_nearest(row1,x->x_nsamples,0,0,x->x_nearest,x->x_dist); + for ( i=0; i<x->x_nsamples; i++ ) + { + // post( "pdp_opencv_cvk : distance : %f", x->x_dist->data.fl[i] ); + } + outlet_float(x->x_outlet1, x->x_dist->data.fl[0]); + + // cvReleaseImage( &img32 ); + x->x_classify = 0; + } + + memcpy( newdata, x->rgb->imageData, x->x_size*3 ); + return; +} + +static void pdp_opencv_cvk_sendpacket(t_pdp_opencv_cvk *x) +{ + /* release the packet */ + pdp_packet_mark_unused(x->x_packet0); + x->x_packet0 = -1; + + /* unregister and propagate if valid dest packet */ + pdp_packet_pass_if_valid(x->x_outlet0, &x->x_packet1); +} + +static void pdp_opencv_cvk_process(t_pdp_opencv_cvk *x) +{ + int encoding; + t_pdp *header = 0; + char *parname; + unsigned pi; + int partype; + float pardefault; + t_atom plist[2]; + t_atom tlist[2]; + t_atom vlist[2]; + + /* check if image data packets are compatible */ + if ( (header = pdp_packet_header(x->x_packet0)) + && (PDP_BITMAP == header->type)){ + + /* pdp_opencv_cvk_process inputs and write into active inlet */ + switch(pdp_packet_header(x->x_packet0)->info.image.encoding){ + + case PDP_BITMAP_RGB: + x->x_packet1 = pdp_packet_clone_rw(x->x_packet0); + pdp_queue_add(x, (void*)pdp_opencv_cvk_process_rgb, (void*)pdp_opencv_cvk_sendpacket, &x->x_queue_id); + break; + + default: + /* don't know the type, so dont pdp_opencv_cvk_process */ + break; + + } + } + +} + +static void pdp_opencv_cvk_input_0(t_pdp_opencv_cvk *x, t_symbol *s, t_floatarg f) +{ + /* if this is a register_ro message or register_rw message, register with packet factory */ + + if (s == gensym("register_rw")) + x->x_dropped = pdp_packet_convert_ro_or_drop(&x->x_packet0, (int)f, pdp_gensym("bitmap/rgb/*") ); + + if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped)) + { + /* add the process method and callback to the process queue */ + pdp_opencv_cvk_process(x); + } +} + +static void pdp_opencv_cvk_free(t_pdp_opencv_cvk *x) +{ + int i; + + pdp_queue_finish(x->x_queue_id); + pdp_packet_mark_unused(x->x_packet0); + + // destroy cv_images + cvReleaseImage( &x->rgb ); + cvReleaseImage( &x->grey ); + +} + +t_class *pdp_opencv_cvk_class; + +// +// +// Find the min box. The min box respect original aspect ratio image +// The image is a binary data and background is white. +// +// + + +void pdp_opencv_cvk_findX(IplImage* imgSrc,int* min, int* max) +{ + int i; + int minFound=0; + CvMat data; + CvScalar maxVal=cvRealScalar(imgSrc->width * 255); + CvScalar val=cvRealScalar(0); + + // for each col sum, if sum < width*255 then we find the min + // then continue to end to search the max, if sum< width*255 then is new max + for (i=0; i< imgSrc->width; i++) + { + cvGetCol(imgSrc, &data, i); + val= cvSum(&data); + if(val.val[0] < maxVal.val[0]) + { + *max= i; + if(!minFound) + { + *min= i; + minFound= 1; + } + } + } +} + +void pdp_opencv_cvk_findY(IplImage* imgSrc,int* min, int* max) +{ + int i; + int minFound=0; + CvMat data; + CvScalar maxVal=cvRealScalar(imgSrc->width * 255); + CvScalar val=cvRealScalar(0); + + // for each col sum, if sum < width*255 then we find the min + // then continue to end to search the max, if sum< width*255 then is new max + for (i=0; i< imgSrc->height; i++) + { + cvGetRow(imgSrc, &data, i); + val= cvSum(&data); + if(val.val[0] < maxVal.val[0]) + { + *max=i; + if(!minFound) + { + *min= i; + minFound= 1; + } + } + } +} + +// +// +// Find the bounding box. +// +// + +CvRect pdp_opencv_cvk_findBB(IplImage* imgSrc) +{ + CvRect aux; + int xmin, xmax, ymin, ymax; + xmin=xmax=ymin=ymax=0; + + pdp_opencv_cvk_findX(imgSrc, &xmin, &xmax); + pdp_opencv_cvk_findY(imgSrc, &ymin, &ymax); + + aux=cvRect(xmin, ymin, xmax-xmin, ymax-ymin); + + return aux; +} + +IplImage pdp_opencv_cvk_preprocessing(IplImage* imgSrc,int new_width, int new_height) +{ + IplImage* result; + IplImage* scaledResult; + + CvMat data; + CvMat dataA; + CvRect bb;//bounding box + CvRect bba;//boundinb box maintain aspect ratio + + // find bounding box + bb=pdp_opencv_cvk_findBB(imgSrc); + + if ( ( bb.width == 0 ) || ( bb.height == 0 ) ) + { + bb.x = 0; + bb.y = 0; + bb.width = imgSrc->width; + bb.height = imgSrc->height; + } + + // get bounding box data and no with aspect ratio, the x and y can be corrupted + cvGetSubRect(imgSrc, &data, cvRect(bb.x, bb.y, bb.width, bb.height)); + // create image with this data with width and height with aspect ratio 1 + // then we get highest size betwen width and height of our bounding box + int size=(bb.width>bb.height)?bb.width:bb.height; + result=cvCreateImage( cvSize( size, size ), 8, 1 ); + cvSet(result,CV_RGB(255,255,255),NULL); + // copy de data in center of image + int x=(int)floor((float)(size-bb.width)/2.0f); + int y=(int)floor((float)(size-bb.height)/2.0f); + cvGetSubRect(result, &dataA, cvRect(x,y,bb.width, bb.height)); + cvCopy(&data, &dataA, NULL); + // scale result + scaledResult=cvCreateImage( cvSize( new_width, new_height ), 8, 1 ); + cvResize(result, scaledResult, CV_INTER_NN); + + // return processed data + return *scaledResult; + +} + +void pdp_opencv_cvk_load(t_pdp_opencv_cvk *x) +{ + IplImage* src_image; + IplImage prs_image; + CvMat row,data; + char file[255]; + int i=0,j; + CvMat row_header, *row1; + + x->x_rsamples = 0; + + for( j = 0; j< x->x_nsamples; j++) + { + + // load file + sprintf(file,"%s/%03d.png",x->x_filepath, j); + src_image = cvLoadImage(file,0); + if(!src_image) + { + post("pdp_opencv_cvk : error: couldn't load image %s\n", file); + continue; + } + if ( ( x->x_pwidth == -1 ) || ( x->x_pheight == -1 ) ) + { + x->x_pwidth = src_image->width; + x->x_pheight = src_image->height; + // post( "pdp_opencv_cvk : loaded : %s (%dx%d)", file, src_image->width, src_image->height); + x->x_rsamples++; + } + else if ( ( src_image->width != x->x_pwidth ) || ( src_image->height != x->x_pheight ) ) + { + post( "pdp_opencv_cvk : error : %s (%dx%d) : wrong size ( should be %dx%d )", file, src_image->width, src_image->height, x->x_pwidth, x->x_pheight); + continue; + } + else + { + // post( "pdp_opencv_cvk : loaded : %s (%dx%d)", file, src_image->width, src_image->height); + x->x_rsamples++; + } + + // process file + prs_image = pdp_opencv_cvk_preprocessing(src_image, x->x_pwidth, x->x_pheight); + // post( "pdp_opencv_cvk : preprocessed : %s (%dx%d)", file, x->x_pwidth, x->x_pheight); + + if ( ( x->trainData == NULL ) || ( x->trainClasses == NULL )) + { + x->trainData = cvCreateMat(x->x_nsamples, x->x_pwidth*x->x_pheight, CV_32FC1); + x->trainClasses = cvCreateMat(x->x_nsamples, 1, CV_32FC1); + } + + // set class label + cvGetRow(x->trainClasses, &row, j); + cvSet(&row, cvRealScalar(i), NULL); + // set data + cvGetRow(x->trainData, &row, j); + + IplImage* img = cvCreateImage( cvSize( x->x_pwidth, x->x_pheight ), IPL_DEPTH_32F, 1 ); + // convert 8 bits image to 32 float image + cvConvertScale(&prs_image, img, 0.0039215, 0); + + cvGetSubRect(img, &data, cvRect( 0, 0, x->x_pwidth, x->x_pheight) ); + + // convert data matrix sizexsize to vecor + row1 = cvReshape( &data, &row_header, 0, 1 ); + cvCopy(row1, &row, NULL); + } + + // create the classifier + post( "pdp_opencv_cvk : loaded : %d samples", x->x_rsamples); + if ( x->x_rsamples == x->x_nsamples ) + { + x->knn=new CvKNearest( x->trainData, x->trainClasses, 0, false, x->x_nsamples ); + x->x_nearest=cvCreateMat(1,x->x_nsamples,CV_32FC1); + x->x_dist=cvCreateMat(1,x->x_nsamples,CV_32FC1); + } +} + +static void pdp_opencv_cvk_classify(t_pdp_opencv_cvk *x) +{ + if ( x->trainData == NULL ) + { + post( "pdp_opencv_cvk : no patterns loaded : cannot process" ); + return; + } + x->x_classify=1; +} + +void *pdp_opencv_cvk_new(t_symbol *s, int argc, t_atom *argv ) +{ + int i; + + t_pdp_opencv_cvk *x = (t_pdp_opencv_cvk *)pd_new(pdp_opencv_cvk_class); + + x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); + x->x_outlet1 = outlet_new(&x->x_obj, &s_anything); + + x->x_packet0 = -1; + x->x_packet1 = -1; + x->x_queue_id = -1; + + x->x_width = 320; + x->x_height = 240; + x->x_size = x->x_width * x->x_height; + x->x_ROIx = 0; + x->x_ROIy = 0; + x->x_ROIw = x->x_width; + x->x_ROIh = x->x_height; + + x->rgb = cvCreateImage( cvSize(x->x_width, x->x_height), 8, 3 ); + x->grey = cvCreateImage( cvSize(x->x_width, x->x_height), 8, 1 ); + + x->x_filepath = ( char * ) getbytes( 1024 ); + sprintf( x->x_filepath, "./data" ); + x->x_nsamples = 10; + + if ( argc >= 1 ) + { + if ( argv[0].a_type != A_SYMBOL ) + { + error( "pdp_opencv_cvk : wrong argument (file path : 1)" ); + return NULL; + } + if ( !strcmp( argv[0].a_w.w_symbol->s_name, "" ) ) + { + error( "pdp_opencv_cvk : no extension specified" ); + error( "pdp_opencv_cvk : usage : pdp_opencv_cvk_new <file path> <nsamples>" ); + return NULL; + } + strcpy( x->x_filepath, argv[0].a_w.w_symbol->s_name ); + } + if ( argc >= 2 ) + { + if ( argv[1].a_type != A_FLOAT ) + { + error( "pdp_opencv_cvk : wrong argument (nsamples : 2)" ); + return NULL; + } + if ( (int)argv[1].a_w.w_float <= 0 ) + { + error( "pdp_opencv_cvk : wrong number of samples (%d)", (t_int)(int)argv[1].a_w.w_float ); + error( "pdp_opencv_cvk : usage : pdp_opencv_cvk_new <file path> <nsamples>" ); + return NULL; + } + x->x_nsamples = (int)argv[1].a_w.w_float; + } + + x->x_classify = 0; + x->x_pwidth = -1; + x->x_pheight = -1; + + x->trainData = NULL; + x->trainClasses = NULL; + + error( "pdp_opencv_cvk : loading %d samples from : %s", x->x_nsamples, x->x_filepath ); + pdp_opencv_cvk_load( x ); + + return (void *)x; +} + + +#ifdef __cplusplus +extern "C" +{ +#endif + + +void pdp_opencv_cvk_setup(void) +{ + + post( " pdp_opencv_cvk"); + pdp_opencv_cvk_class = class_new(gensym("pdp_opencv_cvk"), (t_newmethod)pdp_opencv_cvk_new, + (t_method)pdp_opencv_cvk_free, sizeof(t_pdp_opencv_cvk), CLASS_DEFAULT, A_GIMME, A_NULL); + + 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); + +} + +#ifdef __cplusplus +} +#endif diff --git a/plus/000.png b/plus/000.png Binary files differnew file mode 100644 index 0000000..87a27dc --- /dev/null +++ b/plus/000.png diff --git a/plus/001.png b/plus/001.png Binary files differnew file mode 100644 index 0000000..c79a7dc --- /dev/null +++ b/plus/001.png diff --git a/plus/002.png b/plus/002.png Binary files differnew file mode 100644 index 0000000..90e59f9 --- /dev/null +++ b/plus/002.png diff --git a/plus/003.png b/plus/003.png Binary files differnew file mode 100644 index 0000000..45385cb --- /dev/null +++ b/plus/003.png diff --git a/plus/004.png b/plus/004.png Binary files differnew file mode 100644 index 0000000..6f1c6d4 --- /dev/null +++ b/plus/004.png diff --git a/plus/005.png b/plus/005.png Binary files differnew file mode 100644 index 0000000..e58cb30 --- /dev/null +++ b/plus/005.png diff --git a/plus/006.png b/plus/006.png Binary files differnew file mode 100644 index 0000000..8ae55a5 --- /dev/null +++ b/plus/006.png diff --git a/plus/007.png b/plus/007.png Binary files differnew file mode 100644 index 0000000..e344d92 --- /dev/null +++ b/plus/007.png diff --git a/plus/008.png b/plus/008.png Binary files differnew file mode 100644 index 0000000..009f83e --- /dev/null +++ b/plus/008.png diff --git a/plus/009.png b/plus/009.png Binary files differnew file mode 100644 index 0000000..84c0867 --- /dev/null +++ b/plus/009.png diff --git a/plus/010.png b/plus/010.png Binary files differnew file mode 100644 index 0000000..1652678 --- /dev/null +++ b/plus/010.png diff --git a/plus/011.png b/plus/011.png Binary files differnew file mode 100644 index 0000000..e79637f --- /dev/null +++ b/plus/011.png diff --git a/plus/012.png b/plus/012.png Binary files differnew file mode 100644 index 0000000..4a24b39 --- /dev/null +++ b/plus/012.png diff --git a/plus/013.png b/plus/013.png Binary files differnew file mode 100644 index 0000000..ba9715a --- /dev/null +++ b/plus/013.png diff --git a/plus/014.png b/plus/014.png Binary files differnew file mode 100644 index 0000000..833d68d --- /dev/null +++ b/plus/014.png diff --git a/plus/015.png b/plus/015.png Binary files differnew file mode 100644 index 0000000..3cf9aa7 --- /dev/null +++ b/plus/015.png diff --git a/plus/016.png b/plus/016.png Binary files differnew file mode 100644 index 0000000..0b9e7d0 --- /dev/null +++ b/plus/016.png diff --git a/plus/017.png b/plus/017.png Binary files differnew file mode 100644 index 0000000..dfce6fc --- /dev/null +++ b/plus/017.png diff --git a/plus/018.png b/plus/018.png Binary files differnew file mode 100644 index 0000000..b88c6a3 --- /dev/null +++ b/plus/018.png diff --git a/plus/019.png b/plus/019.png Binary files differnew file mode 100644 index 0000000..c6aadf4 --- /dev/null +++ b/plus/019.png diff --git a/plus/020.png b/plus/020.png Binary files differnew file mode 100644 index 0000000..d93c43c --- /dev/null +++ b/plus/020.png diff --git a/plus/021.png b/plus/021.png Binary files differnew file mode 100644 index 0000000..1123c49 --- /dev/null +++ b/plus/021.png diff --git a/plus/022.png b/plus/022.png Binary files differnew file mode 100644 index 0000000..a211747 --- /dev/null +++ b/plus/022.png diff --git a/plus/023.png b/plus/023.png Binary files differnew file mode 100644 index 0000000..611e234 --- /dev/null +++ b/plus/023.png diff --git a/plus/024.png b/plus/024.png Binary files differnew file mode 100644 index 0000000..8f2507e --- /dev/null +++ b/plus/024.png diff --git a/plus/025.png b/plus/025.png Binary files differnew file mode 100644 index 0000000..0db7dc7 --- /dev/null +++ b/plus/025.png diff --git a/plus/026.png b/plus/026.png Binary files differnew file mode 100644 index 0000000..6f2e564 --- /dev/null +++ b/plus/026.png diff --git a/plus/027.png b/plus/027.png Binary files differnew file mode 100644 index 0000000..3726a5a --- /dev/null +++ b/plus/027.png diff --git a/plus/028.png b/plus/028.png Binary files differnew file mode 100644 index 0000000..caa3dc1 --- /dev/null +++ b/plus/028.png diff --git a/plus/029.png b/plus/029.png Binary files differnew file mode 100644 index 0000000..087a71c --- /dev/null +++ b/plus/029.png diff --git a/plus/030.png b/plus/030.png Binary files differnew file mode 100644 index 0000000..ab5e6f4 --- /dev/null +++ b/plus/030.png diff --git a/plus/031.png b/plus/031.png Binary files differnew file mode 100644 index 0000000..a8d3771 --- /dev/null +++ b/plus/031.png diff --git a/plus/032.png b/plus/032.png Binary files differnew file mode 100644 index 0000000..a94110b --- /dev/null +++ b/plus/032.png diff --git a/plus/033.png b/plus/033.png Binary files differnew file mode 100644 index 0000000..63e2200 --- /dev/null +++ b/plus/033.png diff --git a/plus/034.png b/plus/034.png Binary files differnew file mode 100644 index 0000000..889d5f5 --- /dev/null +++ b/plus/034.png diff --git a/plus/035.png b/plus/035.png Binary files differnew file mode 100644 index 0000000..b552f67 --- /dev/null +++ b/plus/035.png diff --git a/plus/036.png b/plus/036.png Binary files differnew file mode 100644 index 0000000..73190dd --- /dev/null +++ b/plus/036.png diff --git a/plus/037.png b/plus/037.png Binary files differnew file mode 100644 index 0000000..9e885b5 --- /dev/null +++ b/plus/037.png diff --git a/plus/038.png b/plus/038.png Binary files differnew file mode 100644 index 0000000..16eaf56 --- /dev/null +++ b/plus/038.png diff --git a/plus/039.png b/plus/039.png Binary files differnew file mode 100644 index 0000000..32e8def --- /dev/null +++ b/plus/039.png diff --git a/plus/040.png b/plus/040.png Binary files differnew file mode 100644 index 0000000..1b7bbfa --- /dev/null +++ b/plus/040.png diff --git a/plus/041.png b/plus/041.png Binary files differnew file mode 100644 index 0000000..d8b970e --- /dev/null +++ b/plus/041.png diff --git a/plus/042.png b/plus/042.png Binary files differnew file mode 100644 index 0000000..540920f --- /dev/null +++ b/plus/042.png diff --git a/plus/043.png b/plus/043.png Binary files differnew file mode 100644 index 0000000..4691fce --- /dev/null +++ b/plus/043.png diff --git a/plus/044.png b/plus/044.png Binary files differnew file mode 100644 index 0000000..110a46f --- /dev/null +++ b/plus/044.png diff --git a/plus/045.png b/plus/045.png Binary files differnew file mode 100644 index 0000000..ef2e42e --- /dev/null +++ b/plus/045.png diff --git a/plus/046.png b/plus/046.png Binary files differnew file mode 100644 index 0000000..d173fa7 --- /dev/null +++ b/plus/046.png diff --git a/plus/047.png b/plus/047.png Binary files differnew file mode 100644 index 0000000..7fec41a --- /dev/null +++ b/plus/047.png diff --git a/plus/048.png b/plus/048.png Binary files differnew file mode 100644 index 0000000..62c00f9 --- /dev/null +++ b/plus/048.png diff --git a/plus/049.png b/plus/049.png Binary files differnew file mode 100644 index 0000000..a9f41a4 --- /dev/null +++ b/plus/049.png |