Preparation
import cv2
import matplotlib.pyplot as plt
processing
#Load image
img = cv2.imread("〜〜〜.png ")
#Grayscale the image
img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
#Display image
plt.imshow(img_gray)
plt.gray()
How to recognize table cells in OpenCV
You can use it by tweaking the numbers of edge extraction and the truncation of min size.
Introduction to image processing: Image processing starting with OpenCV and Python
Extract contour
image, contours, hierarchy = cv2.findContours(img_gray,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
#Draw on img2
img2 = cv2.drawContours(img_gray, contours, -1, (0,255,0), 3)
#Display and save img2
plt.imshow(img2)
cv2.imwrite('img2.png', img2)
plt.gray()
contours are contours, hierachy is contour hierarchy information
Explanation about cv2.findContours and cv2.drawContours ↓ Outline: First Step
[Python] Get the maximum and minimum values of the list and their indexes (max, min, index)
Connect images vertically and horizontally with Python, OpenCV (hconcat, vconcat, np.tile)
Recommended Posts