From 8d1540f099295c55b8f2508e678006e9ba43d242 Mon Sep 17 00:00:00 2001 From: sbosse Date: Wed, 28 Aug 2024 21:43:01 +0200 Subject: [PATCH] Wed 28 Aug 21:38:52 CEST 2024 --- src/SimNDT/gui/generateVideoController.py | 107 ++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 src/SimNDT/gui/generateVideoController.py diff --git a/src/SimNDT/gui/generateVideoController.py b/src/SimNDT/gui/generateVideoController.py new file mode 100644 index 0000000..52fae07 --- /dev/null +++ b/src/SimNDT/gui/generateVideoController.py @@ -0,0 +1,107 @@ +__author__ = 'Miguel Molero' + + + +import copy, os + +from PySide.QtCore import * +from PySide.QtGui import * + + +try: + import cv2 +except: + print ("problem at importing cv2") + + +from SimNDT.gui.HelperMethods import sort_nicely +from SimNDT.gui.ui_generatevideo import Ui_generateVideoDialog + +from SimNDT.gui.Warnings import WarningParms, DoneParms + + +class GenerateVideo(QDialog, Ui_generateVideoDialog): + + def __init__(self, parent = None): + super(GenerateVideo, self).__init__(parent) + self.setupUi(self) + + self.addImagesPushButton.pressed.connect(self.addImages) + self.videoBasenamePushButton.pressed.connect(self.videoBasename) + + self.dirpath = None + self.FilenameVideo = None + self.Images = None + + + + def addImages(self): + + fnames = "." + fnames, filters = QFileDialog.getOpenFileNames(None, "Choose the image files", fnames, self.tr("Image Files (*.png *.jpg *.bmp *.jpeg)")) + + if fnames is not None: + sort_nicely(fnames) + self.listWidget.addItems(fnames) + self.Images = fnames + + + + def videoBasename(self): + + dir = os.path.dirname(self.dirpath) if self.dirpath is not None else "." + formats = ["*.%s" % unicode("avi")] + fname = None + fname, filters = QFileDialog.getSaveFileName(None, "New Simulation File (.avi)", dir,"avi Files (%s)"%" ".join(formats)) + + if fname is not None: + self.FilenameVideo = fname + self.videoBasenameLineEdit.setText(self.FilenameVideo) + + + def accept(self): + + + if self.Images is None: + msgBox = WarningParms("Please add Images to generate the video") + if msgBox.exec_(): + return + + if self.FilenameVideo is None: + msgBox = WarningParms("Please define the video name") + if msgBox.exec_(): + return + + if len(self.Images) < 10: + msgBox = WarningParms("Please add more Images") + if msgBox.exec_(): + return + + + FPS = self.fPSSpinBox.value() + + img = cv2.imread(self.Images[0]) + height , width , layers = img.shape + print("start",self.FilenameVideo,height , width , layers) + fourcc = cv2.VideoWriter_fourcc(*'XVID') # cv2.cv.CV_FOURCC(*'XVID') + video = cv2.VideoWriter(self.FilenameVideo, fourcc=fourcc, + fps=FPS, frameSize=(width,height)) + + + try: + for item in self.Images: + print(item) + img = cv2.imread(item) + video.write(img) + + cv2.destroyAllWindows() + video.release() + print("end") + + except: + msgBox = WarningParms("Impossible to generate the video using the given images!!!!") + if msgBox.exec_(): + return + + + QDialog.accept(self)