-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqml_bridge.py
executable file
·81 lines (58 loc) · 2.14 KB
/
qml_bridge.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
78
79
80
81
import platform
import time
from typing import Tuple
from urllib.parse import urlparse
from PyQt5.QtCore import QObject, QSize, pyqtSlot, pyqtSignal, Qt
from PyQt5.QtGui import QImage
from PyQt5.QtQuick import QQuickImageProvider
import cv2 as cv
from bounding_box import BoundingBox
from utils import take_a_frame
from video_to_slides import VideoToSlides
class QMLBridge(QObject):
frame : cv.Mat
selected_bbox = None
def __init__(self):
self.video_to_slides = VideoToSlides()
self.frame = None
super().__init__()
@pyqtSlot(str, str)
def convert(self, video_path, output_path):
if(video_path == "" or output_path == "" ):
return
video_path = self.pypath_to_ospath(video_path)
output_path = self.pypath_to_ospath(output_path)
self.video_to_slides.convert(video_path, output_path, self.selected_bbox)
@pyqtSlot(int, int, int, int)
def save_selected_bbox(self, x_start, x_end, y_start, y_end ):
self.selected_bbox = BoundingBox(x_start, x_end, y_start, y_end)
@pyqtSlot()
def reset_selected_bbox(self):
self.selected_bbox = None
@pyqtSlot(str)
def take_a_frame(self, video_path):
video_path = self.pypath_to_ospath(video_path)
self.frame = take_a_frame(video_path)
def pypath_to_ospath(self, video_path):
video_path = urlparse(video_path)
if platform.system() == "Windows":
video_path = video_path.path.lstrip('/').replace('/', '\\')
else:
video_path = video_path.path
return video_path
class FrameImageProvider(QQuickImageProvider):
imageChanged = pyqtSignal(QImage)
def __init__(self, qml_bridge : QMLBridge):
super(FrameImageProvider, self).__init__(QQuickImageProvider.Image)
self.qml_bridge = qml_bridge
self.frame = None
def update_image(self, img):
self.imageChanged.emit(img)
self.frame = img
def requestImage(self, id: str | None, requestedSize: QSize):
time.sleep(5)
img = cv.cvtColor(self.qml_bridge.frame, cv.COLOR_BGR2RGB)
h,w,ch = img.shape
q_img = QImage(img.data, w,h,w*ch, QImage.Format_RGB888)
print(q_img)
return q_img, q_img.rect().size()