Code

Project: jvfeatures

jvtypes.h      jvfeatures.h      chessSeg.cpp      jvtypes.cpp      jvtest.cpp      jvfeatures.cpp     

Project: Other

migrateMailbox.scpt.txt     

Project: Infinite HMM Tutorial

run.m      iHMM_tutorial.zip      HDP_HMM.m      README.txt      ConditionalProbabilityTable.m      HDP.m      HMMProblem.m      HMM.m     

Project: RRT

RRT.h      plot_output.py      RRT.tgz      rrt_test.cpp      RRT.cpp      BidirectionalRRT.cpp      AbstractRRT.cpp     

Project: Box2D_friction_mod

WheelConstraint.h      test_TopDownCar.py      b2FrictionJoint.h      python_friction_joint.patch      test_TopDownFrictionJoint.py      TestEntries.cpp      TopDownCar.h      b2FrictionJoint.cpp      box2d_friction_joint.patch     

Project: Dirichlet Process Mixture Tutorial

EM_GM.m      DP_Demo.m      DPMM.m      DP_Tutorial.zip      DirichletProcess.m      gaussian_EM.m     

Project: Arduino_Code

plot_ardunio_data.sh      Arduino_Code.zip      convert_range2D.py      arduino-serial.c      oscilloscope.sh      oscilloscope.pde      motordriver.pde      helicopter_controller.pde      accelerometer_test.pde      ranger_plane_sweep.pde      clodbuster_controller.pde      pwm_manual.pde      ranger_test.pde      servo_test.pde     

Project: ArduCom

arducom.py      setup.py     

Project: support

geshi.php      Protector.php     

Project: Cogent

CodePane.php      NotesPane.php      PicsPane.php      Cogent.php      PubsTable.php     
Click here to download "resources/code/jvfeatures/chessSeg.cpp"

resources/code/jvfeatures/chessSeg.cpp

/*
 * chessSeg.cpp
 *
 *  Created on: Nov 24, 2009
 *      Author: jscholz
 */


#include "jvfeatures.h"
#include <iostream>
#include <math.h>

using namespace std;

void segmentFromStats(IplImage *srcimg, IplImage *output);

typedef struct {
        double meanR;
        double meanG;
        double meanB;
        double varR;
        double varG;
        double varB;
} colorStats;

colorStats brownPiece;
colorStats whitePiece;
colorStats whiteSquare;
colorStats greenSquare;

int main(int argc, char *argv[]) {
        if (argc == 2) {
                const char* filename;
                filename = argv[1];

                cout << filename << endl;


                brownPiece.meanR = 62.43;
                brownPiece.meanG = 46.40;
                brownPiece.meanB = 30.22;
                brownPiece.varR = 210.74;
                brownPiece.varG = 133.51;
                brownPiece.varB = 86.08;

                whitePiece.meanR = 122.74;
                whitePiece.meanG = 95.53;
                whitePiece.meanB = 56.72;
                whitePiece.varR = 458.90;
                whitePiece.varG = 352.61;
                whitePiece.varB = 228.42;

                whiteSquare.meanR = 159.25;
                whiteSquare.meanG = 149.65;
                whiteSquare.meanB = 138.93;
                whiteSquare.varR = 11.67;
                whiteSquare.varG = 11.36;
                whiteSquare.varB = 24.06;

                greenSquare.meanR = 25.83;
                greenSquare.meanG = 38.44;
                greenSquare.meanB = 27.63;
                greenSquare.varR = 4.82;
                greenSquare.varG = 1.93;
                greenSquare.varB = 7.77;

                jvfeatures *jvf = new jvfeatures(filename, true);

                IplImage *segimg = cvCreateImage(cvGetSize(jvf->srcimg), 8, 3);
                segmentFromStats(jvf->srcimg, segimg);

                cvNamedWindow("segimg",0);
                cvShowImage("segimg",segimg);



                cvWaitKey(0);

        }
}

void segmentFromStats(IplImage *srcimg, IplImage *output)
{
        /*
         * Loop through srcimg and color each corresponding output
         * pixel according to the rules provide below
         */


        /*
         * TODO: write a new segmentation function for jvfeatures that uses
         * selectpixels to gather stats (right click to move on to new object, or done)
         * and colors the seg image based on the object color stats:
         * segment->selectpixel->[some new clickExtras function]
         *      * overload selectpixel to include a pfn argument
         */


        double sqthresh = 1.0;
        double piecethresh = 0.1;

        for (int y = 0; y < srcimg->height; y++) {
                uchar* yptr = (uchar*) (srcimg->imageData + y * srcimg->widthStep);
                uchar* outYptr = (uchar*) (output->imageData + y * output->widthStep);
                for (int x = 0; x < srcimg->width; x++) {
                    int r = yptr[3*x+2];
                    int g = yptr[3*x+1];
                    int b = yptr[3*x+0];

                    if ((fabs(r - brownPiece.meanR) < (piecethresh * brownPiece.varR)) &&
                                (fabs(g - brownPiece.meanG) < (piecethresh * brownPiece.varG)) &&
                        (fabs(b - brownPiece.meanB) < (piecethresh * brownPiece.varB))) {
                        outYptr[3*x+2] = 0;
                        outYptr[3*x+1] = 255;
                        outYptr[3*x+0] = 0;
                    }

                    if ((fabs(r - whitePiece.meanR) < (piecethresh * whitePiece.varR)) &&
                                (fabs(g - whitePiece.meanG) < (piecethresh * whitePiece.varG)) &&
                        (fabs(b - whitePiece.meanB) < (piecethresh * whitePiece.varB))) {
                        outYptr[3*x+2] = 255;
                        outYptr[3*x+1] = 0;
                        outYptr[3*x+0] = 0;
                    }

                    if ((fabs(r - whiteSquare.meanR) < (sqthresh * whiteSquare.varR)) &&
                                (fabs(g - whiteSquare.meanG) < (sqthresh * whiteSquare.varG)) &&
                        (fabs(b - whiteSquare.meanB) < (sqthresh * whiteSquare.varB))) {
                        outYptr[3*x+2] = 0;
                        outYptr[3*x+1] = 0;
                        outYptr[3*x+0] = 255;
                    }

                    if ((fabs(r - greenSquare.meanR) < (sqthresh * greenSquare.varR)) &&
                                (fabs(g - greenSquare.meanG) < (sqthresh * greenSquare.varG)) &&
                        (fabs(b - greenSquare.meanB) < (sqthresh * greenSquare.varB))) {
                        outYptr[3*x+2] = 255;
                        outYptr[3*x+1] = 255;
                        outYptr[3*x+0] = 0;
                    }
                }
        }


}
 

About me

Pic of me