-
Notifications
You must be signed in to change notification settings - Fork 0
/
openCV.py
77 lines (60 loc) · 1.78 KB
/
openCV.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import cv2
import numpy as np
import time
#Open test data txt file
#file = open("data.txt", "r")
file = open("data_xy.txt", "r")
# Create a VideoCapture object and read from input file
# If the input is the camera, pass 0 instead of the video file name
cap = cv2.VideoCapture('tree.avi')
count = 0
x_pos = 100
y_pos = 100
a_x = 0
a_y = 0
frames = 60
# Check if camera opened successfully
if (cap.isOpened()== False):
print("Error opening video stream or file")
# Read until video is completed
while(cap.isOpened()):
start = time.time()
# Capture frame-by-frame
ret, frame = cap.read()
#gray =
line = file.readline()
if line:
line = line.strip()
a_x = int(line.split(' ')[0])
a_y = int(line.split(' ')[1])
scale_percent = int(line.split(' ')[2])
if ret == True:
# Display the resulting frame
resized = frame
width = int(frame.shape[1] * scale_percent / 100)
height = int(frame.shape[0] * scale_percent / 100)
dim = (width, height)
#resize video frame for 5 frames
resized = cv2.resize(frame, dim, interpolation = cv2.INTER_AREA)
cv2.imshow('Frame',resized)
#cv2.imshow('Frame', frame)
#acceleration in m/s**2
#x_pos = x_pos + int((a_x / frames) * (count - 50))
#y_pos = y_pos + int((a_y / frames) * (count - 50))
x_pos = x_pos + (a_x)
y_pos = y_pos + (a_y)
cv2.moveWindow('Frame', x_pos, y_pos)
count = count + 1
print(time.time() - start)
# Press Q on keyboard to exit
if cv2.waitKey(25) & 0xFF == ord('q'):
break
# Break the loop
else:
break
# When everything done, release the video capture object
cap.release()
# Closes all the frames
cv2.destroyAllWindows()
#Close txt file
file.close()