-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCV_10_2_ROI.py
61 lines (53 loc) · 1.88 KB
/
CV_10_2_ROI.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
''' THis uses a mouseclick to getthe values that are used to creat a ROI
python -m venv .venv
source .venv/bin/activate
use the 3.9.6 ('venv':venv) version in the interpreter!!
'''
import sys
import cv2
print(f'OpenCV version: {cv2.__version__}')
import numpy as np
print(f"This python is version {sys.version}")
print(f'Numpy version is: {np.__version__}')
evt =0
xPos =0
yPos =0
Thickness = 2
CircleSize =25
Color =[0,0,255]
def mouseClick(event,xPos,yPos,flags,params):
global evt
global pnt
if event == cv2.EVENT_LBUTTONDOWN:
print('Left Mouse Down was: ',event)
print('at Postion',xPos,' x ',yPos, ' y')
evt = event
pnt = (xPos,yPos)
if event == cv2.EVENT_LBUTTONUP:
print('Left Mouse Up was: ',event)
print('at Postion',xPos,' x ',yPos, ' y')
evt = event
if event == cv2.EVENT_RBUTTONUP:
print('Right Mouse Up was: ',event)
print('at Postion',xPos,' x ',yPos, ' y')
evt = event #evt will be set to 5 and will not put the circle on the frame. thus the circle wil disappear
# want to put a circle when the button is clicked. Have to put it in the while loop because the cicle would be present only for One frame if it was up here.
width=640
height=360
cam = cv2.VideoCapture(0)
# cam=cv2.VideoCapture(0,cv2.CAP_DSHOW)
cam.set(cv2.CAP_PROP_FRAME_WIDTH, width)
cam.set(cv2.CAP_PROP_FRAME_HEIGHT,height)
cam.set(cv2.CAP_PROP_FPS, 30)
cam.set(cv2.CAP_PROP_FOURCC,cv2.VideoWriter_fourcc(*'MJPG'))
cv2.namedWindow('my WEBcam')
cv2.setMouseCallback('my WEBcam', mouseClick)
while True:
ignore, frame = cam.read()
if evt == 1 or evt == 4:
cv2.circle(frame,pnt,CircleSize,Color,Thickness)
cv2.imshow('my WEBcam', frame)
cv2.moveWindow('my WEBcam',0,0)
if cv2.waitKey(1) & 0xff ==ord('q'):
break
cam.release()