#include<opencv2/opencv.hpp>
#include<opencv2/core/core.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<iostream>
using namespace cv;
using namespace std;
int main()
{
Mat src = imread("wu.jpg");
imshow("yuantu",src);
Mat srcImage,dstImage;
Canny(src,srcImage,50,200,3);
cvtColor(srcImage,dstImage,CV_GRAY2BGR);
vector<Vec2f> lines;
HoughLines(srcImage,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 p1,p2;
double a = cos(theta),b = sin(theta);
double x0 = a*rho,y0 = b*rho;
p1.x = cvRound(x0+1000*(-b));
p1.y = cvRound(y0 + 1000*a);
p2.x = cvRound(x0 -1000*(-b));
p2.y = cvRound(y0 -1000*a);
line(dstImage,p1,p2,Scalar(55,100,195),1,LINE_AA,0);
}
imshow("xiaoguotu",dstImage);
waitKey(0);
return 0;
#include<opencv2/core/core.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<iostream>
using namespace cv;
using namespace std;
int main()
{
Mat src = imread("wu.jpg");
imshow("yuantu",src);
Mat srcImage,dstImage;
Canny(src,srcImage,50,200,3);
cvtColor(srcImage,dstImage,CV_GRAY2BGR);
vector<Vec2f> lines;
HoughLines(srcImage,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 p1,p2;
double a = cos(theta),b = sin(theta);
double x0 = a*rho,y0 = b*rho;
p1.x = cvRound(x0+1000*(-b));
p1.y = cvRound(y0 + 1000*a);
p2.x = cvRound(x0 -1000*(-b));
p2.y = cvRound(y0 -1000*a);
line(dstImage,p1,p2,Scalar(55,100,195),1,LINE_AA,0);
}
imshow("xiaoguotu",dstImage);
waitKey(0);
return 0;
}
运行图如下