Advertisement
dan-masek

Untitled

Sep 23rd, 2023
1,014
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3.  
  4. img = cv2.imread("oYeWE.png", cv2.IMREAD_COLOR)
  5.  
  6. gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  7.  
  8. medians = np.median(gray, axis=1)
  9. borders = np.where(np.median(gray, axis=1) < 255)[0]
  10. borders = np.hstack([[0], borders, [gray.shape[0]]])
  11.  
  12. locations = np.where(np.diff(borders) > 1)[0]
  13.  
  14. regions = []
  15. for l in locations:
  16.     regions.append(img[borders[l]:borders[l+1],:])
  17.  
  18. for i, region in enumerate(regions):
  19.     cv2.imshow('Section%d' % i, region)
  20.  
  21. cv2.waitKey()
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement