Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- img = cv2.imread("oYeWE.png", cv2.IMREAD_COLOR)
- gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
- medians = np.median(gray, axis=1)
- borders = np.where(np.median(gray, axis=1) < 255)[0]
- borders = np.hstack([[0], borders, [gray.shape[0]]])
- locations = np.where(np.diff(borders) > 1)[0]
- regions = []
- for l in locations:
- regions.append(img[borders[l]:borders[l+1],:])
- for i, region in enumerate(regions):
- cv2.imshow('Section%d' % i, region)
- cv2.waitKey()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement