Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- img = cv2.imread("9.jpg")
- lc = 0 # Line counter
- for line in img:
- last = (sum(line[0]) > 382) # Get colour of first pixel on the line (Black or White)
- lc += 1
- ctr = 0
- pos = 0
- print("Line:", lc, end=": ")
- for y in line:
- v = (sum(y) > 382) # Black = 0, White = 1
- if v == last: # Same colour as last pixel?
- ctr += 1
- else:
- print(last, ctr, end=" ")
- if last:
- print("mid:", pos + ctr // 2, end=" ")
- pos += ctr
- ctr = 1
- last = v
- print(last, ctr)
- # print("Line", lc, "White width", ctr)
- #show image
- cv2.imshow("img", img)
- cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement