我试图获取图像中表格的水平线和垂直线,以便提取单元格中的文本。这是我使用的图片:
我使用下面的代码来提取垂直线和水平线:
img = cv2.imread(img_for_box_extraction_path, 0) # Read the image
(thresh, img_bin) = cv2.threshold(img, 200, 255,
cv2.THRESH_BINARY | cv2.THRESH_OTSU) # Thresholding the image
img_bin = 255-img_bin # Invert the image
cv2.imwrite("Image_bin_2.jpg",img_bin)
# Defining a kernel length
kernel_length = np.array(img).shape[1]//140
# A verticle kernel of (1 X kernel_length), which will detect all the verticle lines from the image.
verticle_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1, kernel_length))
# A horizontal kernel of (kernel_length X 1), which will help to detect all the horizontal line from …Run Code Online (Sandbox Code Playgroud)