This piece of code find the sum of column elements of a binary/gray image and stores it in a vector. It also finds the maximum value of vertical projection.
IplImage* img;
// find the vertical projection
std::vector v_vl_proj; // holds the column sum values
double max_vl_proj = 0; // holds the maximum value
for( int i=0;i<img->width;++i )
{
CvMat col;
CvScalar col_sum;
cvGetCol( img, &col, i ); // get individual columns
col_sum = cvSum( &col ); // find the sum of ith column
v_vl_proj.push_back( col_sum.val[0] ); // push back to vector
if( col_sum.val[0]>max_vl_proj ) max_vl_proj = col_sum.val[0];
}
The same logic can be used to find the row sum of the image.
No comments:
Post a Comment