Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import matplotlib.image as mpimg
- from PIL import Image
- import cv2
- import numpy as np
- points = []
- def onMouse(event, x, y, flags,param):
- if event == cv2.EVENT_LBUTTONDBLCLK:
- print(x, y)
- points.append((x, y))
- if len(points) == 1:
- print("click on the red border")
- print("enter picture's name")
- while True:
- try:
- fname = input()
- img = cv2.imread(fname, 1)
- img = cv2.resize(img, (0,0), fx=0.5, fy=0.5)
- arr = img
- break
- except Exception:
- print("couldn't find image")
- print("click on the violet border")
- cv2.namedWindow('image')
- cv2.setMouseCallback('image', onMouse)
- while len(points) < 2:
- cv2.imshow('image',img)
- k = cv2.waitKey(20) & 0xFF
- if k == 27:
- break
- print(arr.shape)
- line = []
- print(points)
- for i in range(points[0][1], points[1][1]):
- pixel = arr[i][points[0][0]]
- #print(pixel)
- now = 0
- for j in pixel:
- now += j
- line.append(now)
- line = line[::-1]
- plot = plt.plot(line)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement