From fcde70c2fee643e9d60310f358b2b9345399b447 Mon Sep 17 00:00:00 2001 From: lipeng Date: Fri, 7 Aug 2020 15:17:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A3=8B=E7=9B=98=E8=AF=86=E5=88=AB=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 图像识别CV/pythoncv_learn/detection_chessboard_v4.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/图像识别CV/pythoncv_learn/detection_chessboard_v4.py b/图像识别CV/pythoncv_learn/detection_chessboard_v4.py index 5d9405d..ede7d39 100644 --- a/图像识别CV/pythoncv_learn/detection_chessboard_v4.py +++ b/图像识别CV/pythoncv_learn/detection_chessboard_v4.py @@ -34,6 +34,11 @@ else: image = img.copy() +# 图片锐化 +kernel = np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]], np.float32) +img = cv2.filter2D(img, -1, kernel=kernel) +cv2.imshow('sharpening', img) + # 边缘保护滤波 img = cv2.edgePreservingFilter(img) cv2.imshow('edgePreservingFilter', img) @@ -129,7 +134,7 @@ cv2.imshow('houghLinesImage', houghLinesImage) # Hough变换 thresh_min = min(dst.shape) -lines = cv2.HoughLinesP(dst, 1, np.pi / 180, 200, minLineLength=int(dst.shape[0] * 0.47), maxLineGap=int(thresh_min * 0.5)) +lines = cv2.HoughLinesP(dst, 1, np.pi / 180, 200, minLineLength=int(dst.shape[0] * 0.45), maxLineGap=int(thresh_min * 0.5)) houghLinesImage = img.copy() for line in lines: @@ -139,8 +144,8 @@ cv2.imshow('houghLinesImage', houghLinesImage) if lines is not None: - lines_vertical = filter(lambda line: True if abs(line[0][1] - line[0][3]) > length * 0.5 else False, lines) - lines_horizontal = filter(lambda line: True if abs(line[0][0] - line[0][2]) > height * 0.5 else False, lines) + lines_vertical = filter(lambda line: True if abs(line[0][1] - line[0][3]) > length * 0.2 else False, lines) + lines_horizontal = filter(lambda line: True if abs(line[0][0] - line[0][2]) > height * 0.2 else False, lines) # lines_vertical = filter(isVerticalLine, lines_vertical) # lines_horizontal = filter(isHorizontalLine, lines_horizontal)