主要代码:
<pre name="code" class="cpp">int ImageDeal::findLines( IplImage* I, std::vector<std::vector<int>> &lines) {
int x_threshold = 2; //x轴方向x_threshold范围内存在要检测的点,即看作直线连续
double width_proportion = 0.2; //直线连续超过图片宽度的width_proportion时,确定为一条跨越图片整个宽度的直线
double height_proportion = 0.1667; //检测图片从底部起的height_proportion部分区域
lines.clear(); //lines存储每条直线的起始、结束四个顶点的坐标
//I: binary graph,为canny处理过的二值图像
CV_Assert( I->depth != sizeof(uchar) );
int cols = I->width;
int rows = I->height;
int channels = I->nChannels;
if(channels != 1){
std::cout<<"the image needs to be binary graph!"<<std::endl;
return -1;
}
// push the bottom coordinates of image I(height_proportion)先将图片最底部作为一条直线,存储其顶点位置
std::vector<int> lines_botoom_temp;
lines_botoom_temp.clear();
lines_botoom_temp.push_back(0);
lines_botoom_temp.push_back(rows - 1);
lines_botoom_temp.push_back(cols-1);
lines_botoom_te