-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathroi_selector.py
More file actions
27 lines (25 loc) · 887 Bytes
/
roi_selector.py
File metadata and controls
27 lines (25 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
import matplotlib.widgets as widgets
from grabscreen import grab_screen
#import win2gui
def onselect(eclick, erelease):
if eclick.ydata>erelease.ydata:
eclick.ydata,erelease.ydata=erelease.ydata,eclick.ydata
if eclick.xdata>erelease.xdata:
eclick.xdata,erelease.xdata=erelease.xdata,eclick.xdata
ax.set_ylim(erelease.ydata,eclick.ydata)
ax.set_xlim(eclick.xdata,erelease.xdata)
fig.canvas.draw()
fig = plt.figure()
ax = fig.add_subplot(111)
#filename="test.png"
filename = np.array(grab_screen((0,0,1366,768)))
#im = Image.open(filename)
#arr = np.asarray(im)
plt_image=plt.imshow(filename)
rs=widgets.RectangleSelector(
ax, onselect, drawtype='box',
rectprops = dict(facecolor='red', edgecolor = 'black', alpha=0.5, fill=True))
plt.show()