I''m new to opencv, I am essentially trying to extract a table from an image, and I need to be able to get the columns separately,
I have come across this code here https://stackoverflow.com/questions/60521925/how-to-detect-the-horizontal-and-vertical-lines-of-a-table-and-eliminate-the-noi
It almost accomplishes that I need in terms of segmenting the table vertically. The issue is that I need those separate segments saved as separate images. Is there way to go about doing that?
import cv2
import numpy as np
# Load image, grayscale, Gaussian blur, Otsu's threshold
image = cv2.imread('x.png')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (3,3), 0)
thresh = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
# Detect vertical lines
vertical_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1,50))
vertical_mask = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, vertical_kernel, iterations=1)
# Combine masks and remove lines
table_mask = cv2.bitwise_or(0,vertical_mask)
image[np.where(table_mask==255)] = [255,255,255]
cv2.imshow('image', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
The code above removes the vertical lines, however I need those vertical images in separate files.
↧