-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcircleRectangleWithoutFill.py
More file actions
executable file
·48 lines (37 loc) · 1.08 KB
/
circleRectangleWithoutFill.py
File metadata and controls
executable file
·48 lines (37 loc) · 1.08 KB
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
40
41
42
43
44
45
46
47
48
# PROGRAM TO DRAW CIRCLE AND RECTANGLE WITHOUT FILL
import cv2
import numpy as np
from math import sqrt
draw = False
mode = True
ix=iy=0
fx=fy=0
def draw_figure(event, x, y, flags, param):
global draw,ix,iy,mode,fx,fy
if event == cv2.EVENT_LBUTTONDOWN:
draw = True
ix,iy = x,y
elif event == cv2.EVENT_MOUSEMOVE:
if draw == True:
fx,fy = x,y
# if mode == True:
# cv2.rectangle(img, (ix,iy), (fx,fy), (0,255,0), 2)
## else:
## cv2.circle(img, (x,y), 5, (0,0,255), 2)
elif event == cv2.EVENT_LBUTTONUP:
draw = False
if mode == True:
cv2.rectangle(img, (ix,iy), (fx,fy), (0,255,0), 2)
else:
cv2.circle(img, , int(sqrt((ix-fx)**2 + (iy-fy)**2)), (0,0,255), 2)
img = np.zeros((512,512,3), np.uint8)
cv2.namedWindow('image')
cv2.setMouseCallback('image', draw_figure)
while(True):
cv2.imshow('image', img)
key = cv2.waitKey(1) & 0xff
if key==ord('m'):
mode = not mode
elif key==ord('q'):
break
cv2.destroyAllWindows()