# how to detect only 60-degree lines (a question from 《learning opencv3》chapter 10)

hi,guys learningOpencv3 chapter10 question15 ,says

15 Use cv::filter2D() to create a filter that detects only 60-degree lines in an image. Display the results on a sufficiently interesting image scene.

I know how to detects 45-degree lines ,as

Mat srcLines(100,100,CV_8UC1,Scalar::all(0));//draw lines
line(srcLines,Point(0,0),Point(100,100),Scalar(255),1);
line(srcLines,Point(50,50),Point(100,0),Scalar(255),1);//45 - degree
line(srcLines,Point(0,100),Point(50,0),Scalar(255),1);//60 - degree
Mat srcH(3,3,CV_8UC1,Scalar::all(0));

srcH.at<char>(0,0) = 255;
srcH.at<char>(1,1) = 255;
srcH.at<char>(2,2) = 255;

filter2D(srcLines,dst,srcLines.depth(),srcH);


but ,how to create a 60-degree kenrel? any help will be welcomed. thanks

edit retag close merge delete

1

Take a look here

( 2018-08-09 23:09:58 -0500 )edit
1

take a look at this

( 2018-08-10 03:39:34 -0500 )edit

thanks guys,your ideas are great. but the book need us do this work by using

cv::filter2D()

any ideas?

( 2018-08-10 21:14:59 -0500 )edit

Sort by » oldest newest most voted

That is a kernel for a theoretic angle of 62.5 degree.

cv::Mat1f k = (cv::Mat1f(9,9)<<
0,0,0,0,0,0,1,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,1,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,1,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,1,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,1,0,0,0,0,0,0);

more