Guest User

Untitled

a guest
Jun 14th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 17.75 KB | None | 0 0
  1. #ifndef _CS440P0_H
  2. #define _CS440P0_H
  3.  
  4. #include <cv.h>
  5. #include "Image.h"
  6. #include <vector>
  7. #include <cstdlib>
  8. #include <utility>
  9. #include <sstream>
  10. #include <map>
  11. #include <algorithm>
  12.  
  13. class CS440P0
  14. {
  15. public:
  16.     CS440P0():
  17.       myChar(0)
  18.       {
  19.           //make a new window where we can show our processed results
  20.           namedWindow("detected",1);
  21.  
  22.       }
  23.  
  24.       CS440P0(Mat& frame):
  25.       myChar(0)
  26.       {
  27.  
  28.           //make a new window where we can show our processed results
  29.           namedWindow("detected",1);
  30.  
  31.           // release params = 4,10,255,3
  32.           this->bin_size = 4;
  33.           this->threshold = 10;
  34.           this->maxValue = 255;
  35.           this->MAX_ITEMS = 3;
  36.           this->MIN_MASS = 600/ (bin_size *bin_size);
  37.           this->filter = 0.1;
  38.  
  39.           // Get the cols and row values
  40.           this->ROWS = frame.rows;
  41.           this->COLS = frame.cols;
  42.  
  43.           // Initialize the boolean image array
  44.           this->bimage = new bool*[ROWS];
  45.  
  46.           for (int row = 0; row < ROWS; ++row)
  47.               bimage[row] = new bool[COLS];
  48.           for (int row = 0; row < ROWS; ++row)
  49.               for (int col = 0; col < COLS; ++col)
  50.                   bimage[row][col] = false;
  51.  
  52.           // Initialize the x and y projection vectors;
  53.           this->rp  = new int[ROWS]; //proj along x
  54.           this->cp =  new int[COLS]; //proj along y
  55.  
  56.           for (int row = 0; row < ROWS; ++row) { this->rp[row] =0;}
  57.           for (int col = 0; col < COLS; ++col) { this->cp[col] =0;}
  58.  
  59.           // Initialize the x and y bin vectors;
  60.           this->xbins  = new unsigned  int[COLS]; //bin along x
  61.           this->ybins =  new unsigned  int[ROWS]; //bin along y
  62.  
  63.           for (int row = 0; row < ROWS; ++row) { this->ybins[row] =0;}
  64.           for (int col = 0; col < COLS; ++col) { this->xbins[col] =0;}
  65.  
  66.           // Initialize the x and y boolean vectors;
  67.           this->xbool =  new bool [COLS/bin_size];
  68.           this->ybool =  new bool [ROWS/bin_size];
  69.  
  70.  
  71.           // Initialize the flood fill array
  72.           this->bin = new bool*[ROWS/bin_size];
  73.  
  74.           for (int row = 0; row < ROWS/bin_size; ++row)
  75.               this->bin[row] = new bool[COLS/bin_size];
  76.           for (int row = 0; row < ROWS/bin_size; ++row)
  77.               for (int col = 0; col < COLS/bin_size; ++col)
  78.                   this->bin[row][col] = false;
  79.  
  80.           // Initialize the flood fill array
  81.           this->fFill = new short*[ROWS/bin_size];
  82.  
  83.           for (int row = 0; row < ROWS/bin_size; ++row)
  84.               this->fFill[row] = new short[COLS/bin_size];
  85.           for (int row = 0; row < ROWS/bin_size; ++row)
  86.               for (int col = 0; col < COLS/bin_size; ++col)
  87.                   this->fFill[row][col] = 0;
  88.  
  89.  
  90.           // Initialize a new vector
  91.           this->areas = new int[MAX_ITEMS] ;
  92.           for (int ii = 0; ii < MAX_ITEMS; ++ii)
  93.           {
  94.               areas[ii]=0;
  95.           }
  96.  
  97.           // Make color chart
  98.           //this->colors = new cv::Scalar [];
  99.           int ii = 0; {}
  100.           this->colors.push_back(CV_RGB( 200,0,0 ));
  101.           this->colors.push_back(CV_RGB( 85,107,47));
  102.           this->colors.push_back(CV_RGB( 160,32 ,240));
  103.           this->colors.push_back(CV_RGB( 0  ,0  ,128));
  104.           this->colors.push_back(CV_RGB( 124,252,0)) ;
  105.           this->colors.push_back(CV_RGB( 255,255,0));
  106.           this->colors.push_back(CV_RGB( 255,165,0));
  107.           this->colors.push_back(CV_RGB( 255,105,180));
  108.           this->colors.push_back(CV_RGB( 0,0,0));
  109.           this->colors.push_back(CV_RGB( 255,255,255)) ;
  110.           this->colors.push_back(CV_RGB( 127,255,0));
  111.           this->colors.push_back(CV_RGB( 190,190,190));
  112.           this->colors.push_back(CV_RGB( 0,255,255));
  113.           this->colors.push_back(CV_RGB( 140,255,255));
  114.           this->colors.push_back(CV_RGB( 205,175,149));
  115.           this->colors.push_back(CV_RGB( 255,105,80));
  116.           this->colors.push_back(CV_RGB( 60,179,113));
  117.           this->colors.push_back(CV_RGB( 46,139,87));
  118.           this->colors.push_back(CV_RGB( 240,230,140));
  119.           this->colors.push_back(CV_RGB( 188,143,143));
  120.           this->colors.push_back(CV_RGB( 255,255,0));
  121.  
  122.           // Active Items list
  123.           this->active_item = new bool[MAX_ITEMS];
  124.           for (int ii = 0; ii < MAX_ITEMS; ++ii) active_item[ii] = false;
  125.  
  126.           // Min Max bounds
  127.           this->c_min = new short[MAX_ITEMS] ;
  128.           this->r_min = new short[MAX_ITEMS] ;
  129.           this->c_max = new short[MAX_ITEMS] ;
  130.           this->r_max = new short[MAX_ITEMS] ;
  131.  
  132.           for (int ii = 0; ii < MAX_ITEMS; ++ii) c_min[ii] = COLS/bin_size ;
  133.           for (int ii = 0; ii < MAX_ITEMS; ++ii) c_max[ii] = 0;
  134.           for (int ii = 0; ii < MAX_ITEMS; ++ii) r_min[ii] = ROWS/bin_size;
  135.           for (int ii = 0; ii < MAX_ITEMS; ++ii) r_max[ii] = 0;
  136.  
  137.           // For the moments and centroids
  138.           this->u1_x = new int[MAX_ITEMS] ;
  139.           this->u1_y = new int[MAX_ITEMS];
  140.           this->u2_yy = new int[MAX_ITEMS];
  141.           this->u2_xy = new int[MAX_ITEMS];
  142.           this->u2_xx = new int[MAX_ITEMS];
  143.  
  144.  
  145.           this->x_centroid = new short[MAX_ITEMS];
  146.           this->y_centroid = new short[MAX_ITEMS];
  147.  
  148.  
  149.           for (int ii = 0; ii < MAX_ITEMS; ++ii) u1_x[ii] = 0;
  150.           for (int ii = 0; ii < MAX_ITEMS; ++ii) u1_y[ii] = 0;
  151.           for (int ii = 0; ii < MAX_ITEMS; ++ii) u2_yy[ii] = 0;
  152.           for (int ii = 0; ii < MAX_ITEMS; ++ii) u2_xy[ii] = 0;
  153.           for (int ii = 0; ii < MAX_ITEMS; ++ii) u2_xx[ii] = 0;
  154.  
  155.           for (int ii = 0; ii < MAX_ITEMS; ++ii) x_centroid[ii] = 0;
  156.           for (int ii = 0; ii < MAX_ITEMS; ++ii) y_centroid[ii] = 0;
  157.  
  158.           this->squareness = new double[MAX_ITEMS];
  159.           for (int ii = 0; ii < MAX_ITEMS; ++ii) squareness[ii] = 0;
  160.  
  161.           this->headProb = new double[MAX_ITEMS];
  162.           for (int ii = 0; ii < MAX_ITEMS; ++ii) headProb[ii] = 0;
  163.  
  164.           this->handProb = new double[MAX_ITEMS];
  165.           for (int ii = 0; ii < MAX_ITEMS; ++ii) handProb[ii] = 0;
  166.  
  167.           this->headNeckProb = new double[MAX_ITEMS];
  168.           for (int ii = 0; ii < MAX_ITEMS; ++ii) headNeckProb[ii] = 0;
  169.  
  170.           this->fistProb = new double[MAX_ITEMS];
  171.           for (int ii = 0; ii < MAX_ITEMS; ++ii) fistProb[ii] = 0;
  172.  
  173.           this->rectangularity = new double[MAX_ITEMS];
  174.           for (int ii = 0; ii < MAX_ITEMS; ++ii) rectangularity[ii] = 0;
  175.          
  176.  
  177.       }
  178.  
  179.       template < typename T>
  180.       void empty2D( T* myArray, int row_size, int col_size)
  181.       {
  182.           for (int row = 0; row < row_size; ++row)
  183.               for (int col = 0; col < col_size; ++col)
  184.                   myArray[row][col] = 0;
  185.  
  186.       }
  187.  
  188.  
  189.  
  190.       void projections()
  191.       {
  192.  
  193.           // Clear X sums
  194.           for (int col = 0; col < COLS; ++col) { this->cp[col] = false;}
  195.           // Clear Y sums
  196.           for (int row = 0; row < ROWS; ++row) { this->rp[row] = false;}
  197.  
  198.  
  199.           // For every row and every column calculate the project and threshold
  200.           for(int rr= 0; rr<ROWS; rr++)
  201.           {
  202.               int r_sum = 0;
  203.               for(int cc=0; cc<COLS; cc++)
  204.               {
  205.  
  206.                   Color c = this->processed.get(cc,rr);
  207.                   c.r = c.r - .6*c.g - .6*c.b;
  208.                   c.r =  c.r > threshold ? maxValue : 0 ;
  209.                   c.g = 0;
  210.                   c.b = 0;
  211.  
  212.                   if (myChar == 'r'){ this->detected.set(cc,rr,c); }
  213.  
  214.                   // Running sum
  215.                   r_sum += c.r/255;
  216.  
  217.                   // Running sum the y projection
  218.                   this->cp[cc]+= c.r/255;
  219.                   this->bimage[rr][cc] = c.r ;
  220.               }
  221.               // Add the running sum to the x projection
  222.               this->rp[rr] = r_sum;
  223.           }
  224.       }
  225.  
  226.  
  227.       // Adds up the values of a projection
  228.       int binning(unsigned int* toReturn, int bin_size, int length, int* projection)
  229.       {
  230.           //Clear toReturn
  231.           empty(toReturn,length);
  232.  
  233.           // Running overall maximum
  234.           int max = 0;
  235.           int average = 0;
  236.           for(int ii=0;ii<length;ii++)
  237.           {
  238.               toReturn[ii] = 0;
  239.               for(int jj=0;jj<bin_size;jj++)
  240.               {
  241.                   toReturn[ii] += projection[(ii*bin_size) + jj];
  242.  
  243.               }
  244.               average += toReturn[ii];
  245.               // max = toReturn[jj] > max ? toReturn[ii] : max ;
  246.               // Average
  247.               //toReturn[ii] /= bin_size;
  248.           }
  249.           return average/length;
  250.       }
  251.  
  252.  
  253.       // Clears any arrays
  254.       template < typename T>
  255.       void empty( T * myArray, int length)
  256.       {
  257.           int ii =0 ;
  258.           while( ii < length )
  259.           {
  260.               myArray[ii++]=0;
  261.           }
  262.       }
  263.  
  264.  
  265.       // Fill a single value into any array
  266.       template < typename T>
  267.       void fillArray( T * myArray, int length, int fill_value)
  268.       {
  269.           int ii =0 ;
  270.           while( ii < length )
  271.           {
  272.               myArray[ii++]= fill_value;
  273.           }
  274.       }
  275.  
  276.  
  277.       // Threshold the binned values
  278.       void bound(unsigned int *bins, int length, int thresh, bool * valid)
  279.       {
  280.           empty(valid,length);
  281.           for ( int ii =0 ;  ii < length ;ii++)
  282.           {
  283.               if ( bins[ii] > thresh)
  284.               {
  285.                   valid[ii] = true ;
  286.               }
  287.               else
  288.               {  
  289.                   valid[ii] = false;
  290.               }
  291.           }
  292.       }
  293.  
  294.  
  295.  
  296.       // Calculate the area
  297.       int getArea( int cc, int rr)
  298.       {
  299.           int sum = 0;
  300.           int ccMax = cc*bin_size+bin_size;
  301.           int rrMax = rr*bin_size+bin_size;
  302.           for ( int aa = cc*bin_size ;  (aa < COLS) && (aa< ccMax)  ;aa++)
  303.           {
  304.               for ( int bb = rr*bin_size ; (bb <ROWS) && (bb< rrMax) ;bb++)
  305.               {
  306.                   if ( bimage[bb][aa] )
  307.                   {
  308.                       sum++;
  309.                   }
  310.               }
  311.           }
  312.           return sum;
  313.       }
  314.  
  315.  
  316.  
  317.  
  318.       // Draw a box around the regions where we are above the skin color threshold
  319.       void box()
  320.       {
  321.           empty2D(this->bin, ROWS/bin_size, COLS/bin_size);
  322.  
  323.           for(int ii=0; ii< COLS/bin_size; ii++)
  324.           {
  325.               if ( this->xbool[ii] )
  326.               {
  327.                   for(int jj=0; jj<ROWS/bin_size; jj++ )
  328.                   {
  329.                       if( this->ybool[jj] )
  330.                       {
  331.                           // Calculate the saturation
  332.                           int area = getArea(ii,jj);
  333.                           double saturation = double (area) / double (bin_size*bin_size);
  334.  
  335.                           if ( saturation > .2 )
  336.                           {
  337.                               //flood[ii][jj] = true;
  338.                               bin[jj][ii] = true;
  339.  
  340.                               if (myChar == 'n')
  341.                               { Point p1(ii * bin_size,jj * bin_size);
  342.                               Point p2( (ii+1) * bin_size, (jj+1) * bin_size);
  343.                               cv::rectangle(detected.getImage(),p1,p2, CV_RGB(0,255,0),3);
  344.                               }
  345.                           }
  346.                           else
  347.                           {
  348.                               bin[jj][ii] = false;
  349.                           }
  350.                       }
  351.                   }
  352.               }
  353.           }
  354.       }
  355.  
  356.  
  357.       // Cluster the touching points with flood fill
  358.       void cluster ()
  359.       {
  360.           empty2D(this->fFill, ROWS/bin_size, COLS/bin_size);
  361.           empty(this->areas,this->MAX_ITEMS);
  362.  
  363.           // Reset the bounding indices
  364.           fillArray(this->c_max,MAX_ITEMS, -1);
  365.           fillArray(this->r_max,MAX_ITEMS, -1);
  366.           fillArray(this->c_min,MAX_ITEMS,COLS/bin_size +1);
  367.           fillArray(this->r_min,MAX_ITEMS,ROWS/bin_size +1);
  368.  
  369.           short  index=0;
  370.           short  gCount=0;
  371.           std::map<int , short> good_values;
  372.           for (short ii=0 ; ii< COLS/bin_size; ii++ )
  373.  
  374.           {
  375.               for(short jj=0; jj<ROWS/bin_size; jj++ )
  376.               {
  377.                   // If we are max items skip
  378.                   if ( good_values.size() < MAX_ITEMS ){
  379.                       // Call flood fill and update the index if we have found a fill
  380.                       int sum = 0;
  381.                       int * psum = &sum;
  382.                       int result =  floodFill(jj,ii,index,psum);
  383.  
  384.                       // If we are large enough, start trackings
  385.                       if ( sum > MIN_MASS)
  386.                       {
  387.                           // result store
  388. //                        this->areas[gCount] = sum*(bin_size*bin_size);
  389.                           good_values.insert( std::pair<int, short>( result,gCount++) );
  390.                       }
  391.                       // INcrement
  392.                       index++;
  393.                   }
  394.               }
  395.           }
  396.  
  397.  
  398.           index = 0;
  399.  
  400.           for (short ii=0 ; ii< COLS/bin_size; ii++ )
  401.           {
  402.               for(short jj=0; jj<ROWS/bin_size; jj++ )
  403.               {
  404.                   int gVal = good_values.count(fFill[jj][ii]);
  405.                   if( gVal )
  406.                   {
  407.  
  408.                       int item_index = good_values[ fFill[jj][ii] ];
  409.  
  410.                       if (myChar == 'b')
  411.                       {
  412.                           Point p1( ii * bin_size,jj * bin_size);
  413.                           Point p2( (ii+1) * bin_size, (jj+1) * bin_size);
  414.                           cv::rectangle(detected.getImage(),p1,p2, this->colors[ item_index ], -1);
  415.                       }
  416.  
  417.                       if (ii > c_max[item_index])
  418.                       { c_max[item_index] = ii; }  
  419.                       if (jj > r_max[item_index])
  420.                       { r_max[item_index] = jj; }  
  421.                       if (ii < c_min[item_index])
  422.                       { c_min[item_index] = ii; }  
  423.                       if (jj < r_min[item_index])
  424.                       { r_min[item_index] = jj; }  
  425.                   }
  426.                   index++;
  427.  
  428.               }
  429.           }
  430.  
  431.           for ( int ii=0 ; ii < MAX_ITEMS ; ii++)
  432.           {
  433.               if ( c_min[ii] != COLS/bin_size+1  &&  
  434.                   r_min[ii] != ROWS/bin_size+1  &&
  435.                   c_max[ii] != -1 &&
  436.                   r_max[ii] != -1
  437.                   )
  438.               {
  439.                   active_item[ii] = true;
  440.                   Point p1( c_min[ii] * bin_size, r_min[ii]  * bin_size);
  441.                   Point p2( c_max[ii] * bin_size, r_max[ii]  * bin_size);
  442.  
  443.                   cv::rectangle(detected.getImage(),p1,p2, this->colors[ ii ], 3);
  444.               }
  445.               else
  446.               {
  447.                   active_item[ii] = false;
  448.               }
  449.           }
  450.       }
  451.  
  452.  
  453.  
  454.  
  455.       // recursive flood fill function
  456.       int floodFill(short rr, short cc, short index, int * sum)
  457.       {
  458.           // If out of bounds, return
  459.           if ( rr >= ROWS/bin_size || cc >= COLS/bin_size || rr < 0 || cc < 0 )
  460.           {
  461.               return index;
  462.           }
  463.           // If I am not a zero value in the bin, return
  464.           else if ( bin[rr][cc] == false )
  465.           {
  466.               return index;
  467.           }
  468.           // If I am zero, continue
  469.           else if ( fFill[rr][cc] == 0 )
  470.           {
  471.               fFill[rr][cc] = index+1;
  472.               // Increment the mass count
  473.               (*sum)++;
  474.  
  475.               floodFill(rr+1,cc,index,sum);
  476.               floodFill(rr-1,cc,index,sum);
  477.               floodFill(rr,cc+1,index,sum);
  478.               floodFill(rr,cc-1,index,sum);
  479.  
  480.               return index+1;
  481.           }
  482.           else
  483.           {
  484.               return index;
  485.           }
  486.  
  487.       }
  488.  
  489.  
  490.       // Sets Keys
  491.       void setKey(char c)
  492.       {
  493.           myChar = c;
  494.       }
  495.  
  496.  
  497.       /* Calculates the moments in a bounding box and stores to the moment arrays
  498.       * Ensure that the item_no passed in is within bounds
  499.       */
  500.       void calcStats( int item_no)
  501.       {
  502.  
  503.           u1_y[item_no] = 0;
  504.           u1_x[item_no] = 0;
  505.           areas[item_no] = 0;
  506.           for ( int ii = c_min[item_no]*bin_size ;  ii < c_max[item_no]*bin_size ; ii++ )
  507.           {
  508.               for ( int jj = r_min[item_no]*bin_size ; jj< r_max[item_no]*bin_size ; jj++ )
  509.               {
  510.                   // Find moment as  SUM( y*B(x,y) )
  511.                   u1_y[item_no] += jj * bimage[jj][ii];
  512.                   u1_x[item_no] += ii * bimage[jj][ii];
  513.                   areas[item_no] += bimage[jj][ii];
  514.               }
  515.           }
  516.  
  517.           y_centroid[item_no] = u1_y[item_no] / areas[item_no];
  518.           x_centroid[item_no] = u1_x[item_no] / areas[item_no];
  519.  
  520.           // Square ness
  521.           double hwRatio = (double)(this->r_max[item_no] - this->r_min[item_no]) / (double) (this->c_max[item_no] - this->c_min[item_no]) ;
  522.           this->squareness[item_no] = hwRatio;
  523.  
  524.           // Rectangularity
  525.           int total_area = (bin_size*bin_size)*(r_max[item_no]-r_min[item_no])*(c_max[item_no]-c_min[item_no]);
  526.           rectangularity[item_no] = (double) areas[item_no] / (double) total_area;
  527.  
  528.       }
  529.  
  530.       /* Calculate the 2nd central moments
  531.       *
  532.       */
  533.       void calcSecondMoment( int item_no)
  534.       {
  535.           u2_yy[item_no] = 0;
  536.           u2_xy[item_no] = 0;
  537.           u2_xx[item_no] = 0;
  538.           for ( int ii = c_min[item_no] ;  ii < c_max[item_no] ; ii++ )
  539.           {
  540.               for ( int jj = r_min[item_no] ; jj< r_max[item_no] ; jj++ )
  541.               {
  542.                   // Find moment as  SUM( y*B(x,y) )
  543.                   u2_yy[item_no] += (y_centroid[item_no] - jj) * (y_centroid[item_no] - jj)  * bimage[jj][ii];
  544.                   u2_xx[item_no] += (x_centroid[item_no] - ii) * (x_centroid[item_no] - ii)  * bimage[jj][ii];
  545.                   u2_xy[item_no] += (x_centroid[item_no] - ii) * (y_centroid[item_no] - jj)  * bimage[jj][ii];
  546.               }
  547.           }
  548.  
  549.       }
  550.  
  551.       //   void calcShape( int item_no)
  552.       //{
  553.       // e_min[item_no] = 0;
  554.       //e_max[item_no] = 0;
  555.       //
  556.       //
  557.       //}
  558.  
  559.       void getStats()
  560.       {
  561.           for (int  ii = 0 ; ii < MAX_ITEMS ; ii++ )
  562.           {
  563.               if (active_item[ii]){
  564.  
  565.                   calcStats(ii);
  566.                   Point center( x_centroid[ii], y_centroid[ii] );
  567.                   cv::circle(detected.getImage(),center,3,colors[ii],-1);
  568.                  
  569.                   Point stats(c_min[ii]*bin_size, r_max[ii]*bin_size+40);
  570.                   std::stringstream ss (std::stringstream::in | std::stringstream::out);
  571.                   ss << this->rectangularity[ii] << "  " << this->squareness[ii];
  572.                   cv::putText(detected.getImage(),ss.str(),stats,FONT_HERSHEY_SIMPLEX,0.5,colors[ii],1);
  573.               }
  574.           }
  575.       }
  576.  
  577.  
  578.       // Main doWork Loop
  579.       bool doWork(Mat& frame)
  580.       {
  581.           // Preprocessed Blurring step
  582.           Mat blurred ,blurred2, blurred3;
  583.           // cv::GaussianBlur(frame , blurred , cv::Size(7,7),1.5);
  584.           int erosion_elem = 0;
  585.           int erosion_size = 0;
  586.           int dilation_elem = 0;
  587.           int dilation_size = 0;
  588.           int const max_elem = 2;
  589.           int const max_kernel_size = 21;
  590.           int erosion_type;
  591.           if( erosion_elem == 0 ){ erosion_type = MORPH_RECT; }
  592.           else if( erosion_elem == 1 ){ erosion_type = MORPH_CROSS; }
  593.           else if( erosion_elem == 2) { erosion_type = MORPH_ELLIPSE; }
  594.           Mat element = getStructuringElement( erosion_type,
  595.               Size( 2*erosion_size + 1, 2*erosion_size+1 ),
  596.               Point( erosion_size, erosion_size ) );
  597.  
  598.           /// Apply the erosion operation
  599.           erode( frame, blurred2, element );
  600.           dilate(blurred2, blurred3, element);
  601.           cv::blur(blurred3 , blurred , cv::Size(9,9)) ;
  602.           processed(blurred);
  603.           detected(frame);
  604.  
  605.           // Calculate Projections
  606.           projections();
  607.  
  608.           // Calculate the bins and bounds
  609.           int xmax  = binning( this->xbins , bin_size, this->COLS/bin_size, this->cp );
  610.           int ymax  = binning( this->ybins , bin_size, this->ROWS/bin_size, this->rp );
  611.  
  612.           bound ( this->xbins , COLS/bin_size, xmax  * filter, this->xbool );
  613.           bound ( this->ybins , ROWS/bin_size, ymax * filter , this->ybool );
  614.  
  615.           box();
  616.           cluster();
  617.           getStats();
  618.  
  619.           imshow("detected", detected.getImage());
  620.           cvWaitKey(40);
  621.  
  622.           return true;
  623.       }
  624.  
  625.  
  626.  
  627.  
  628.       Image processed;
  629.       Image detected;
  630.  
  631.       // X and Y Projection vectors
  632.       int * rp;
  633.       int * cp;
  634.  
  635.       // Bins
  636.       unsigned int * ybins;
  637.       unsigned int * xbins;
  638.  
  639.       // Binary image
  640. public: bool** bimage;
  641.         bool** bin;
  642.         char myChar;
  643.         short** fFill;
  644.  
  645.         // Row and column sizes
  646.         int ROWS;
  647.         int COLS;
  648.  
  649.         bool * xbool;
  650.         bool * ybool;
  651.  
  652.         // Members for the threshold and maxValue
  653.         int threshold;
  654.         int maxValue;
  655.         int bin_size ;
  656.         int MAX_ITEMS;
  657.         int MIN_MASS;
  658.  
  659.         // A vector to keep track of the area of each mass
  660.         int  * areas;
  661.  
  662.         // Color Array
  663.         vector<cv::Scalar> colors;
  664.  
  665.         double filter;
  666.  
  667.         // Arrays for bounds
  668.         bool  *active_item;
  669.         short *c_max;
  670.         short *r_max;
  671.         short *c_min;
  672.         short *r_min;
  673.         int *u1_x;
  674.         int *u1_y;
  675.         int *u2_yy;
  676.         int *u2_xy;
  677.         int *u2_xx;
  678.         short *x_centroid;
  679.         short *y_centroid;
  680.  
  681.         double* headProb;
  682.         double* handProb;
  683.         double* headNeckProb;
  684.         double* fistProb;
  685.         double* rectangularity;
  686.         double* squareness;
  687.  
  688.  
  689. };
  690.  
  691. #endif
Add Comment
Please, Sign In to add comment