-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwindow.py
More file actions
36 lines (30 loc) · 940 Bytes
/
Copy pathwindow.py
File metadata and controls
36 lines (30 loc) · 940 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
import cv2
import numpy as np
import random
class Window:
def __init__(self):
self.windowName = str(random.random())
cv2.namedWindow(self.windowName)
cv2.setMouseCallback(self.windowName, self.mousecallback)
self.xoff = 0
self.xinit = 0
self.yoff = 0
self.yinit = 0
self.dragging = False
self.placing = False
def showImage(self, image):
cv2.imshow(self.windowName, image)
def destroy(self):
cv2.destroyWindow(self.windowName)
def mousecallback(self,event, x,y, flags, params):
if self.placing:
if event == cv2.EVENT_LBUTTONDOWN:
self.dragging = True
self.xinit = x
self.yinit = y
elif event == cv2.EVENT_MOUSEMOVE:
if self.dragging == True:
self.xoff = (x - self.xinit)
self.yoff = (y - self.yinit)
elif event == cv2.EVENT_LBUTTONUP:
self.dragging = False