Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/avilleret/pix_opencv
Browse files Browse the repository at this point in the history
  • Loading branch information
avilleret committed Jan 18, 2014
2 parents ed2e811 + 653390e commit 14b0ab1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
4 changes: 3 additions & 1 deletion pix_opencv_knear-help.pd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#N canvas 564 203 1154 642 10;
#N canvas 562 208 1154 642 10;
#X obj 384 31 gemhead;
#X obj 365 414 pix_texture;
#X obj 365 442 square 2;
Expand Down Expand Up @@ -66,6 +66,8 @@ a character image;
#X obj 367 215 pix_separator;
#X obj 365 336 pix_opencv_knear;
#X obj 575 199 t b b;
#X text 638 309 Directory could be ether relative to patch or absolute
;
#X connect 0 0 26 0;
#X connect 1 0 2 0;
#X connect 4 0 5 0;
Expand Down
24 changes: 14 additions & 10 deletions pix_opencv_knear.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include "pix_opencv_knear.h"

#include <stdio.h>

CPPEXTERN_NEW_WITH_TWO_ARGS(pix_opencv_knear, t_symbol *, A_DEFSYM, t_floatarg, A_DEFFLOAT )

Expand Down Expand Up @@ -117,7 +116,6 @@ IplImage pix_opencv_knear :: preprocessing(IplImage* imgSrc,int new_width, int n
CvMat data;
CvMat dataA;
CvRect bb;//bounding box
CvRect bba;//boundinb box maintain aspect ratio

// find bounding box
bb=this->findBB(imgSrc);
Expand Down Expand Up @@ -165,8 +163,14 @@ void pix_opencv_knear :: load_patterns(void)
for( j = 0; j< this->x_nsamples; j++)
{

// load file
sprintf(file,"%s/%03d.png",this->x_filepath, j);
// load fileath

if ( x_filepath[0] == '/' ){ // absolute path
sprintf(file,"%s/%03d.png",this->x_filepath, j);
} else { // relative path
std::string absolutePath = localPath + x_filepath;
sprintf(file,"%s/%03d.png",absolutePath.c_str(), j);
}
src_image = cvLoadImage(file,0);
if(!src_image)
{
Expand Down Expand Up @@ -256,6 +260,9 @@ pix_opencv_knear :: pix_opencv_knear(t_symbol *path, t_floatarg nsamples)
trainData = NULL;
trainClasses = NULL;

t_canvas* canvas = canvas_getcurrent();
localPath = std::string(canvas_getdir(canvas)->s_name) + "/";

try {
this->load_patterns();
} catch(...) {
Expand Down Expand Up @@ -311,7 +318,6 @@ void pix_opencv_knear :: processRGBAImage(imageStruct &image)
if ( this->x_classify )
{
IplImage prs_image;
float result;
CvMat row_header, *row1, odata;

// post( "pix_opencv_knear : size : (%dx%d)", this->x_pwidth, this->x_pheight);
Expand All @@ -325,7 +331,7 @@ void pix_opencv_knear :: processRGBAImage(imageStruct &image)
cvGetSubRect(img32, &odata, cvRect(0,0, this->x_pwidth, this->x_pheight));
row1 = cvReshape( &odata, &row_header, 0, 1 );

result=this->knn->find_nearest(row1,this->x_nsamples,0,0,this->x_nearest,this->x_dist);
this->knn->find_nearest(row1,this->x_nsamples,0,0,this->x_nearest,this->x_dist);
for ( i=0; i<this->x_nsamples; i++ )
{
// post( "pix_opencv_knear : distance : %f", this->x_dist->data.fl[i] );
Expand Down Expand Up @@ -367,7 +373,6 @@ void pix_opencv_knear :: processRGBImage(imageStruct &image)
if ( this->x_classify )
{
IplImage prs_image;
float result;
CvMat row_header, *row1, odata;

// post( "pix_opencv_knear : size : (%dx%d)", this->x_pwidth, this->x_pheight);
Expand All @@ -381,7 +386,7 @@ void pix_opencv_knear :: processRGBImage(imageStruct &image)
cvGetSubRect(img32, &odata, cvRect(0,0, this->x_pwidth, this->x_pheight));
row1 = cvReshape( &odata, &row_header, 0, 1 );

result=this->knn->find_nearest(row1,this->x_nsamples,0,0,this->x_nearest,this->x_dist);
this->knn->find_nearest(row1,this->x_nsamples,0,0,this->x_nearest,this->x_dist);
for ( i=0; i<this->x_nsamples; i++ )
{
// post( "pix_opencv_knear : distance : %f", this->x_dist->data.fl[i] );
Expand Down Expand Up @@ -427,7 +432,6 @@ void pix_opencv_knear :: processGrayImage(imageStruct &image)
if ( this->x_classify )
{
IplImage prs_image;
float result;
CvMat row_header, *row1, odata;

// post( "pix_opencv_knear : size : (%dx%d)", this->x_pwidth, this->x_pheight);
Expand All @@ -441,7 +445,7 @@ void pix_opencv_knear :: processGrayImage(imageStruct &image)
cvGetSubRect(img32, &odata, cvRect(0,0, this->x_pwidth, this->x_pheight));
row1 = cvReshape( &odata, &row_header, 0, 1 );

result=this->knn->find_nearest(row1,this->x_nsamples,0,0,this->x_nearest,this->x_dist);
this->knn->find_nearest(row1,this->x_nsamples,0,0,this->x_nearest,this->x_dist);
for ( i=0; i<this->x_nsamples; i++ )
{
// post( "pix_opencv_knear : distance : %f", this->x_dist->data.fl[i] );
Expand Down
5 changes: 5 additions & 0 deletions pix_opencv_knear.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ LOG

#include "Base/GemPixObj.h"

#include <string>
#include <stdio.h>

/*-----------------------------------------------------------------
-------------------------------------------------------------------
CLASS
Expand Down Expand Up @@ -94,6 +97,8 @@ class GEM_EXPORT pix_opencv_knear : public GemPixObj
int x_pwidth;
int x_pheight;
CvKNearest *knn;

std::string localPath;

// The output and temporary images
IplImage *rgba, *rgb, *grey;
Expand Down

0 comments on commit 14b0ab1

Please sign in to comment.