#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp" #include <iostream> using namespace cv;
using namespace std; void help()
{
cout << "\nThis program demonstrates line finding with the Hough transform.\n"
"Usage:\n"
"./houghlines <image_name>, Default is pic1.jpg\n" << endl;
} int main(int argc, char** argv)
{
const char* filename = argc >= ? argv[] : "pic1.jpg"; Mat src = imread(filename, );
if(src.empty())
{
help();
cout << "can not open " << filename << endl;
return -;
} Mat dst, cdst;
Canny(src, dst, , , );
cvtColor(dst, cdst, CV_GRAY2BGR); #if 0
vector<Vec2f> lines;
HoughLines(dst, lines, , CV_PI/, , , ); for( size_t i = ; i < lines.size(); i++ )
{
float rho = lines[i][], theta = lines[i][];
Point pt1, pt2;
double a = cos(theta), b = sin(theta);
double x0 = a*rho, y0 = b*rho;
pt1.x = cvRound(x0 + *(-b));
pt1.y = cvRound(y0 + *(a));
pt2.x = cvRound(x0 - *(-b));
pt2.y = cvRound(y0 - *(a));
line( cdst, pt1, pt2, Scalar(,,), , CV_AA);
}
#else
vector<Vec4i> lines;
HoughLinesP(dst, lines, , CV_PI/, , , );
for( size_t i = ; i < lines.size(); i++ )
{
Vec4i l = lines[i];
line( cdst, Point(l[], l[]), Point(l[], l[]), Scalar(,,), , CV_AA);
}
#endif
imshow("source", src);
imshow("detected lines", cdst); waitKey(); return ;
}