-
Notifications
You must be signed in to change notification settings - Fork 0
/
openCV4_bouncingBox_copy.py
58 lines (48 loc) · 1.64 KB
/
openCV4_bouncingBox_copy.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
#program launches the rpi cam with jetson nano
#bouncing ball exercise
import cv2
print(cv2.__version__)
#Setting up the camera
dispW=640
dispH=480
flip=0
camSet='nvarguscamerasrc ! video/x-raw(memory:NVMM), width=3264, height=2464, format=NV12, framerate=21/1 ! nvvidconv flip-method='+str(flip)+' ! video/x-raw, width='+str(dispW)+', height='+str(dispH)+', format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink'
cam = cv2.VideoCapture(camSet)
#Read camera until q key is pressed
ballHeightTop = 20
ballHeightBottom = 460
ballWidthLeft = 20
ballWidthRight = 620
i = 0
flagHeight = 0
flagWidth = 0
while True:
ret, frame = cam.read()
frame = cv2.circle(frame, (ballWidthLeft,ballHeightBottom), 20, (0,255,0), -1)
cv2.imshow('piCam',frame)
cv2.moveWindow('piCam', 0, 0)
if flagHeight == 0:
ballHeightBottom = ballHeightBottom + 1
if ballHeightBottom == 461:
ballHeightBottom = ballHeightBottom - 2
flagHeight = 1
if flagHeight == 1:
ballHeightBottom = ballHeightBottom - 1
if ballHeightBottom == 19:
ballHeightBottom = ballHeightBottom + 2
flagHeight = 0
if flagWidth == 0:
ballWidthLeft = ballWidthLeft + 1
if ballWidthLeft == 621:
ballWidthLeft = ballWidthLeft - 2
flagWidth = 1
if flagWidth == 1:
ballWidthLeft = ballWidthLeft - 1
if ballWidthLeft == 19:
ballWidthLeft = ballWidthLeft + 2
flagWidth = 0
if cv2.waitKey(1) == ord('q'):
break
#After q is pressed, release the camera back to the system
cam.release()
cv2.destroyAllWindows()