1 | initial version |
I couldn't use the histogram functions descriped in openCV doc , because it try to find color histogram , and the question try to find projection in on X-axis and Y-axis for black and white image. i used the following code the find vertical and herozontal projection.
//2-find x ,y projections (horizontal projection)
Mat horizontal(ROIimg.cols,1,CV_32S);//horizontal histogram
horizontal = Scalar::all(0);
Mat vertical(ROIimg.rows,1,CV_32S);//vertical histogram
vertical = Scalar::all(0);
for(int i=0;i<ROIimg.cols;i++)
{
horizontal.at<int>(i,0)=countNonZero(ROIimg(Rect(i,0,1,ROIimg.rows)));
}
for(int i=0;i<ROIimg.rows;i++)
{
vertical.at<int>(i,0) = countNonZero(ROIimg(Rect(0,i,ROIimg.cols,1)));
}
where ROIimg is balck and white