-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathscript.py
More file actions
39 lines (29 loc) · 989 Bytes
/
Copy pathscript.py
File metadata and controls
39 lines (29 loc) · 989 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
28
29
30
31
32
33
34
35
36
37
38
39
import sys
import cv2 # Opencv ver 3.1.0 used
import numpy as np
# Set recursion limit
sys.setrecursionlimit(10 ** 9)
import selectinwindow
# Initialize the drag object
wName = "select region"
imageWidth = 320
imageHeight = 240
image = np.ones([imageHeight, imageWidth, 3], dtype=np.uint8) # OR read an image using imread()
image *= 255
# Define the drag object
rectI = selectinwindow.DragRectangle(image, wName, imageWidth, imageHeight)
cv2.namedWindow(rectI.wname)
cv2.setMouseCallback(rectI.wname, selectinwindow.dragrect, rectI)
# keep looping until rectangle finalized
while True:
# display the image
cv2.imshow(wName, rectI.image)
key = cv2.waitKey(1) & 0xFF
# if returnflag is True, break from the loop
if rectI.returnflag:
break
print("Dragged rectangle coordinates")
print(str(rectI.outRect.x) + ',' + str(rectI.outRect.y) + ',' + \
str(rectI.outRect.w) + ',' + str(rectI.outRect.h))
# close all open windows
cv2.destroyAllWindows()