我正在尝试仅使用线性滤波器来检测线。我的第一个尝试是像这样旋转一个内核,但是不起作用:
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))
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)
Filter2D(src,dst,kernel)
最佳答案
您可以使用Canny算法进行边缘检测(无论如何仍使用Sobel)和使用Hough变换进行线检测。在Canny之前执行模糊可以帮助消除异常线。这是经典方法。您可以使用同时实现这两个部分的OpenCV。
请参阅以下内容:
http://en.wikipedia.org/wiki/Hough_transform
http://en.wikipedia.org/wiki/Canny_edge_detector
这是OpenCV实现的文档:
http://opencv.willowgarage.com/documentation/cpp/imgproc_feature_detection.html
看到cvHoughLines *函数有示例代码
https://stackoverflow.com/questions/7517208/