-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathui.py
127 lines (104 loc) · 4.51 KB
/
ui.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#importing dependencies
import os
import sys
import pandas as pd
import numpy as np
import pyqtgraph as pg
from pyqtgraph import PlotWidget, plot
from PyQt5 import QtWidgets, QtMultimedia, uic, QtCore, QtGui
from PyQt5.QtWidgets import QFileDialog
from PyQt5.QtCore import QDir, Qt, QUrl
from PyQt5.QtMultimedia import QMediaContent, QMediaPlayer
#defining main class for window
class Form(QtWidgets.QMainWindow):
def __init__(self, parent=None):
QtWidgets.QDialog.__init__(self, parent)
""""" Loading the UI File """
self.ui = uic.loadUi(os.path.join(os.path.dirname(__file__), "Try2.ui"),self)
""" Setting Multimedia player to play video"""
self.player = QtMultimedia.QMediaPlayer(None, QtMultimedia.QMediaPlayer.VideoSurface)
""" Setting up the Video Widget, Slider and Layout"""
self.player.setVideoOutput(self.ui.widget)
self.widget = QtGui.QWidget()
self.widget.setLayout(QtGui.QHBoxLayout())
self.slider.show()
self.slider.setRange(0, 0)
self.slider.sliderMoved.connect(self.setPosition)
""" Slider position and duratio synchronization"""
self.player.positionChanged.connect(self.positionChanged)
self.player.durationChanged.connect(self.durationChanged)
imv = pg.ImageView()
self.widget.layout().addWidget(imv)
self.actionOpen.setStatusTip('Open movie')
""" Triggering File Open when File button is clicked"""
self.actionOpen.triggered.connect(self.openFile)
self.show()
def positionChanged(self, position):
"""Slider position change manually """
self.slider.setValue(position)
def play(self):
""" Play video on the video widget """
if self.player.state() == QMediaPlayer.PlayingState:
self.player.pause()
else:
self.player.play()
""" Duration change attachment from slider to video """
def durationChanged(self, duration):
self.slider.setRange(0, duration)
global vidlen
vidlen = duration
print('duration')
print(vidlen)
def setPosition(self, position):
""" Setting the position and play"""
self.player.setPosition(position)
self.player.play()
"""Synchronize the signal slider when video slider is moved"""
#print(position)
p= ((position/vidlen)*column)
p=int(p)
#print(p)
self.graphicsView.setCurrentIndex(p)
#print(self.graphicsView.currentIndex)
def setCurrentIndex(self, ind):
"""Set the currently displayed frame index"""
self.currentIndex = np.clip(ind, 0, self.getProcessedImage().shape[self.axes['t']]-1)
print("here")
self.updateImage()
self.ignoreTimeLine = True
self.timeLine.setValue(self.tVals[self.currentIndex])
self.ignoreTimeLine = False
def openFile(self):
""" To open folder and setting up the respective files"""
dir_ = QtGui.QFileDialog.getExistingDirectory(None, 'Select a folder:', 'C:\\', QtGui.QFileDialog.ShowDirsOnly)
fileName = f'{dir_}/video.avi'
dataName = f'{dir_}/signal.csv'
if fileName != '' and dataName != '':
self.player.setMedia(
QMediaContent(QUrl.fromLocalFile(fileName)))
"""Open the signal file"""
data = pd.read_csv(dataName,header=None)
test_read = data.values
"""Pre-Process the signal file"""
a = np.transpose(test_read)
#print(test_read)
#print(test_read.shape)
global column
column = test_read.shape[1]
print(column)
query=a.reshape(column,118,48)
query=query.transpose(0, 2, 1)
"""Pass the signal data to the Widget"""
self.graphicsView.show()
self.graphicsView.setImage(query)
"""Set the color, threshold and auto play or signal data"""
self.graphicsView.setPredefinedGradient('flame')
self.graphicsView.setLevels(0,80)
self.graphicsView.play(1)
self.player.play()
if __name__ == '__main__':
"""Start the application"""
app = QtWidgets.QApplication(sys.argv)
w = Form()
w.show()
sys.exit(app.exec())