Skip to content

Commit

Permalink
Speedup HoughLinesP by filtering image before
Browse files Browse the repository at this point in the history
  • Loading branch information
bansan85 committed Nov 17, 2020
1 parent 667b56f commit 5c7409b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 43 deletions.
19 changes: 4 additions & 15 deletions page/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,11 @@ def __found_candidates_split_line_with_line(
apertureSize=param.canny.aperture_size,
)
cv2ext.write_image_if(canny, enable_debug, "_2_3.png")
canny_filtered = cv2.bitwise_and(canny, cv2.bitwise_not(images_mask))
cv2ext.write_image_if(canny_filtered, enable_debug, "_2_4.png")

list_lines_p = cv2.HoughLinesP(
canny,
canny_filtered,
param.hough_lines.delta_rho,
param.hough_lines.delta_tetha,
param.hough_lines.threshold,
Expand Down Expand Up @@ -446,21 +448,8 @@ def __found_candidates_split_line_with_line(
image, lines_valid, (0, 0, 255), 1
),
)
lines_valid2 = list(
filter(
lambda x: cv2ext.is_line_not_cross_images(x[0], images_mask),
lines_valid,
)
)
if enable_debug is not None:
cv2ext.secure_write(
enable_debug + "_2_8.png",
cv2ext.draw_lines_from_hough_lines(
image, lines_valid2, (0, 0, 255), 1
),
)

return list(map(lambda p: p[0], lines_valid2))
return list(map(lambda p: p[0], lines_valid))


def __loop_to_find_best_mean_angle_pos(
Expand Down
34 changes: 8 additions & 26 deletions page/unskew.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,15 @@ def find_rotation(
apertureSize=parameters.canny.aperture_size,
)
cv2ext.write_image_if(canny, enable_debug, "_" + str(n_page) + "_3.png")
canny_filtered = cv2.bitwise_and(canny, cv2.bitwise_not(images_mask))
cv2ext.write_image_if(
canny_filtered, enable_debug, "_" + str(n_page) + "_4.png"
)

# Détection des lignes.
# La précision doit être de l'ordre de 0.05°
list_lines = cv2.HoughLinesP(
canny,
canny_filtered,
parameters.hough_lines.delta_rho,
parameters.hough_lines.delta_tetha,
parameters.hough_lines.threshold,
Expand Down Expand Up @@ -169,34 +173,12 @@ def find_rotation(
1,
)
cv2ext.secure_write(
enable_debug + "_" + str(n_page) + "_4.png", image_with_lines
)
cv2ext.secure_write(
enable_debug + "_" + str(n_page) + "_4bbbb.png", img
)

lines_filtered = list(
filter(
lambda x: cv2ext.is_line_not_cross_images(x, images_mask), lines
)
)

if enable_debug is not None:
image_with_lines = cv2ext.convertion_en_couleur(image)
for line_x1, line_y1, line_x2, line_y2 in lines_filtered:
cv2.line(
image_with_lines,
(line_x1, line_y1),
(line_x2, line_y2),
(255, 0, 0),
1,
)
cv2ext.secure_write(
enable_debug + "_" + str(n_page) + "_4ccccc.png", image_with_lines
enable_debug + "_" + str(n_page) + "_5.png", image_with_lines
)
cv2ext.secure_write(enable_debug + "_" + str(n_page) + "_6.png", img)

return found_angle_unskew_page(
lines_filtered,
lines,
parameters.hough_lines.delta_tetha / np.pi * 180.0,
approximate_angle,
)
2 changes: 1 addition & 1 deletion script.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def unskew_page(
img_rotated = cv2ext.rotate_image(image, rotate_angle)
if enable_debug is not None:
cv2ext.secure_write(
enable_debug + "_" + str(n_page) + "_5.png", img_rotated
enable_debug + "_" + str(n_page) + "_8.png", img_rotated
)
return img_rotated

Expand Down
2 changes: 1 addition & 1 deletion tests
Submodule tests updated from 7be350 to 9f1a55

0 comments on commit 5c7409b

Please sign in to comment.