-
Notifications
You must be signed in to change notification settings - Fork 0
/
VideoStream.py
58 lines (38 loc) · 1.1 KB
/
VideoStream.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
import cv2, imutils
from PyQt5 import QtGui as qtg
from PyQt5 import QtCore as qtc
import sys
import numpy as np
import mimetypes
class VideoStream(qtc.QThread):
ImageUpdate = qtc.pyqtSignal(object)
def run(self):
self.play()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
count = 0
mimetypes.init()
def setFile(self, filepath):
self.filepath = filepath
self.mime = self.getMime(self.filepath);
def play(self):
self.Playing = True
if self.filepath:
while self.Playing:
self.ImageUpdate.emit(self.getImage())
def getImage(self):
if self.mime in ['video']:
capture = cv2.VideoCapture(self.filepath)
success, image = capture.read()
else:
image = cv2.imread(self.filepath, cv2.IMREAD_UNCHANGED)
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR)
return image
def stop(self):
self.Playing = False
def getMime(self, file):
mimestart = mimetypes.guess_type(file)[0]
if mimestart != None:
mimestart = mimestart.split('/')[0]
return mimestart