def find_lines_by_standard_hough(the_image): cur_image = the_image.copy() ''' This blur operation is quite useful ''' # cur_image = cv2.GaussianBlur(cur_image,ksize=(5,5), sigmaX=0) # cur_image = cv2.GaussianBlur(cur_image,ksize=(3,3), sigmaX=0) ''' open, it could remove the border ''' # kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3)) # cur_image = cv2.morphologyEx(cur_image, cv2.MORPH_OPEN, kernel) # cv2_helper.Image.show(cur_image) # low_threshold, high_threshold = 40, 80 low_threshold, high_threshold = 70, 140 cur_image = cv2.Canny(cur_image, low_threshold, high_threshold) # cv2_helper.Image.show(cur_image) lines = cv2.HoughLines(cur_image, rho=1, theta=numpy.pi/180, threshold= 200) ''' this is true line list''' if numpy_helper.is_array_none(lines): return [] lines = lines[0] len(lines).pp() ''' you can decline the count line by canny low_threshold ''' if len(lines) > 200 or len(lines) < 1: return [] show_lines(the_image, lines)
def find(low_threshold): cur_image = the_image.copy() high_threshold = low_threshold * 2 # low_threshold,high_threshold = 50, 100 cur_image.shape.pp() threshold = int(cur_image.shape[0] * 0.4) threshold.pp() cur_image = cv2.Canny(cur_image, low_threshold, high_threshold) lines = cv2.HoughLines(cur_image, rho=1, theta=numpy.pi/180, threshold= threshold) ''' this is true line list''' if numpy_helper.is_array_none(lines): return [] return lines[0]