-
Notifications
You must be signed in to change notification settings - Fork 2
/
reader.py
48 lines (38 loc) · 1.33 KB
/
reader.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
import cv2
class Reader():
def __init__(self,filename=0,show=False):
self.cap = cv2.VideoCapture(filename)
if self.cap.isOpened():
print("File loaded")
else:
print("File not loaded")
raise Exception("shisthiatasfa")
self.show = show
def getWidth(self):
return self.cap.get(cv2.CAP_PROP_FRAME_WIDTH)
def getHeight(self):
return self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
def read(self,newsize=(0,0)):
if not self.cap.isOpened():
print("File not loaded")
return None
ret, frame = self.cap.read()
while not ret:
ret, frame = self.cap.read()
if newsize!=(0,0):
frame = cv2.resize(frame,newsize)
if self.show==True:
cv2.imshow("frame", frame) # eventuell anders benennen
return frame
def skipFrames(self,frames_to_skip):
try:
self.read()
self.cap.set(cv2.CAP_PROP_POS_FRAMES,self.cap.get(cv2.CAP_PROP_POS_FRAMES)+frames_to_skip)
print("Skipped " + str(frames_to_skip) + " frames")
except Exception as e:
print("Frame skippen fehlgeschlagen")
print(e)
def getFPS(self):
return self.cap.get(cv2.CAP_PROP_FPS)
def __del__(self):
self.cap.release()