[opencv] 霍夫變換Hough

HoughLines(dstImage, lines, 1, CV_PI / 180, 90, 0, 0);
cvtColor(dstImage, dstImage, CV_GRAY2BGR);
//【4】依次在圖中繪製出每條線段
for (size_t i = 0; i < lines.size(); i++)
{
    float rho = lines[i][0], theta = lines[i][1];
    //if (abs((int)rho%180)>15) continue;
    //cout << "斜率: " << abs((int)rho % 180) << endl;
    Point pt1, pt2;
    double a = cos(theta), b = sin(theta);
    double x0 = a*rho, y0 = b*rho;
    pt1.x = cvRound(x0 + 1000 * (-b));
    pt1.y = cvRound(y0 + 1000 * (a));
    pt2.x = cvRound(x0 - 1000 * (-b));
    pt2.y = cvRound(y0 - 1000 * (a));
    line(dstImage, pt1, pt2, Scalar(0, 0, 255), 2, CV_AA);
}
imshow("dstImg", dstImage);
cout << "num of lines:" << lines.size() << endl;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章