Innerhlab dieses Repositorys ist ein showcase ausgearbeitet, welcher live die Funktion des EVM Algorithmus darstellt.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.py 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #..................................
  2. #........Visualisierung 2..........
  3. #..................................
  4. #...Eulerian Video Magnification...
  5. #..................................
  6. #.. Author: Galya Pavlova..........
  7. #..................................
  8. import os
  9. import sys
  10. import cv2
  11. from PyQt5.QtCore import QTimer
  12. from PyQt5.QtGui import QPixmap, QImage
  13. from PyQt5.QtWidgets import QApplication, QDialog, QFileDialog
  14. from PyQt5.uic import loadUi
  15. import butterworth_filter
  16. import ideal_filter
  17. class App(QDialog):
  18. def __init__(self):
  19. '''
  20. Initializes and loads the GUI PyQt file
  21. '''
  22. super(App, self).__init__()
  23. self.vid = None
  24. self.name = None
  25. self.capture = None
  26. self.len = None
  27. self.l = 0
  28. loadUi('gui.ui', self)
  29. self.startButton.clicked.connect(self.on_start_clicked)
  30. self.lButton.clicked.connect(self.open_file)
  31. self.playButton.clicked.connect(self.play_video)
  32. def play_video(self):
  33. '''
  34. A function to play a given video
  35. '''
  36. self.capture = cv2.VideoCapture(self.videoOut)
  37. frame_rate = self.capture.get(cv2.CAP_PROP_FPS)
  38. self.len = int(self.capture.get(cv2.CAP_PROP_FRAME_COUNT))
  39. self.timer = QTimer(self)
  40. self.timer.timeout.connect(self.dispayImage)
  41. self.timer.start(frame_rate)
  42. def dispayImage(self):
  43. '''
  44. Each video frame is read and loaded
  45. '''
  46. self.l += 1
  47. if self.l >= self.len:
  48. self.timer.stop()
  49. self.timer.deleteLater()
  50. self.l = 0
  51. ret, img = self.capture.read()
  52. qformat = QImage.Format_RGB888
  53. outImage = QImage(img, img.shape[1], img.shape[0], qformat)
  54. outImage = outImage.rgbSwapped()
  55. self.video.setPixmap(QPixmap.fromImage(outImage))
  56. def open_file(self):
  57. '''
  58. Opens Files
  59. '''
  60. filename, _ = QFileDialog.getOpenFileName(self, 'Open Video File', '../', 'All Files(*)')
  61. if filename:
  62. self.vid = filename
  63. base = os.path.basename(filename)
  64. self.name = os.path.splitext(base)[0]
  65. self.nameLabel.setText(base)
  66. def on_start_clicked(self):
  67. '''
  68. Reads the input from the GUI and uses the parameters to start the program
  69. '''
  70. self.finished.clear()
  71. QApplication.instance().processEvents()
  72. alpha = float(self.alpha.text())
  73. cutoff = float(self.cutoff.text())
  74. low = float(self.low.text())
  75. high = float(self.high.text())
  76. chromAttenuation = float(self.chromAtt.text())
  77. linearAttenuation = self.linearAtt.isChecked()
  78. mode = self.comboBox.currentIndex()
  79. if mode == 0:
  80. butterworth_filter.start(self.vid, alpha, cutoff, low, high, linearAttenuation, chromAttenuation, self.name)
  81. else:
  82. if mode == 1:
  83. ideal_filter.start(self.vid, alpha, low, high, chromAttenuation, self.name)
  84. self.finished.setText('Done!')
  85. self.videoOut = self.name+"Out.avi"
  86. if __name__ == "__main__":
  87. app = QApplication(sys.argv)
  88. window = App()
  89. window.setWindowTitle('Eulerian Video Magnification')
  90. window.show()
  91. sys.exit(app.exec_())