I’m trying to detect lines just with linear filters. My first try was rotate a kernel like this but wouldn’t work:
kernel = zeros((13,13))
kernel60 = zeros((13,13))
kernel[4] = [0,0,0,0,-1,-1,-1,-1,-1,0,0,0,0]
#kernel[5] = [0,0,0,0,0]
kernel[6] = [0,0,0,0,2,2,2,2,2,0,0,0,0]
#kernel[7] = [0,0,0,0,0]
kernel[8] = [0,0,0,0,-1,-1,-1,-1,-1,0,0,0,0]
rotate60 = zeros((2,3))
GetRotationMatrix2D((6,6),60,1, rotate60)
WarpAffine(kernel,kernel60,rotate60,CV_WARP_FILL_OUTLIERS, ScalarAll(0))
After that I prepared a kernel that’s a linear combination from two Sobel kernels (steerable filters). This works but I would better like a non-sobel kernel, similar to the first try. Any alternative to the sobel kernels?
Sobel Kernel combination:
kernel_x[0] = [-1,0,+1]
kernel_x[1] = [-1,0,+1]
kernel_x[2] = [-1,0,+1]
kernel_y[0] = [-1,-1,-1]
kernel_y[1] = [0,0,0]
kernel_y[2] = [+1,+1,+1]
normal_theta = radians(-30)
kernel = multiply(cos(theta),kernel_x) + multiply(sin(theta),kernel_y)
Then filtering:
Filter2D(src,dst,kernel)
I use Python and numpy in a Windows machine.
You can use Canny algorithm for edge detection (which uses Sobel anyway) and Hough transform for line detection. Performing blur before Canny can help eliminate outlier lines. This is the classic approach. You can use OpenCV that implements both parts.
See the following:
http://en.wikipedia.org/wiki/Hough_transform
http://en.wikipedia.org/wiki/Canny_edge_detector
Here is the documentation for OpenCV implementation:
http://opencv.willowgarage.com/documentation/cpp/imgproc_feature_detection.html
see the cvHoughLines* functions there are sample code