#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main()
{
Mat srcImage = imread("C:/Users/hasee-pc/Desktop/women.jpg");
Mat midImage, dstImage;
Canny(srcImage, midImage, 50, 200, 3);
cvtColor(midImage, dstImage, CV_GRAY2BGR);
vector<Vec2f> lines;
HoughLines(midImage,//输入图 八位单通道二进制
lines,// 存储了霍夫线变换检测到的输出矢量
1, //以像素单的距离精度,搜索的尺寸单位半径
CV_PI / 180, //角度精度
150,//累加平面阈值,识别某部分为途中的一条直线时它在累加平面中必须达到的值
0,//除数距离
0
);
for (size_t i = 0; i < lines.size(); ++i)
{
float rho = lines[i][0], theta = lines[i][1];
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(55, 100, 153), 1, LINE_AA);//画线
}
imshow("【原始图】", srcImage);
imshow("【边缘检测】", midImage);
imshow("【效果图】", dstImage);
waitKey(0);
return 0;
}