我想从指定的帧号开始播放视频

时间:2019-05-28 12:22:21

标签: python opencv

我想从指定的编号开始播放视频,并且正在使用功能import sys from PyQt5 import QtCore, QtWidgets, QtGui, QtPrintSupport import time import os from PyQt5.QtGui import QIcon, QPixmap, QImage path = "C:/Users/benni/Desktop/" folder_name = "exit_folder_test" name_list = "used_names.txt" source = "test" extension = "jpg" if not os.path.isfile(os.path.join(path, name_list)): used_names = open(path + name_list, "w+") used_names.close() names =[] else: used_names = open(path + name_list, "r") names = used_names.readlines() used_names.close() print(names) ##################################################################################### class MainWindow(QtWidgets.QMainWindow): switch_window = QtCore.pyqtSignal(str) def __init__(self): super(MainWindow, self).__init__() widget = QtWidgets.QWidget() self.setCentralWidget(widget) grid_layout = QtWidgets.QGridLayout(widget) rows, cols = 2, 3 self._labels = [] global image_width, image_height, number, pictures image_width, image_height, number = 600, 400, 0 pictures = [] for row in range(rows): for col in range(cols): label = QtWidgets.QLabel(alignment=QtCore.Qt.AlignCenter) label.setFixedSize(image_width, image_height) grid_layout.addWidget(label, row, col) self._labels.append(label) self.ComboBox = QtWidgets.QComboBox(self) grid_layout.addWidget(self.ComboBox, 3, 2, alignment=QtCore.Qt.AlignRight) self.ComboBox.setFixedSize(125,25) self.refresh_button = QtWidgets.QPushButton("aktuallisieren") grid_layout.addWidget(self.refresh_button, 3, 1) self.refresh_button.setFixedSize(125,25) self.refresh_button.clicked[bool].connect(self.update) self.print_button = QtWidgets.QPushButton("print") # print button grid_layout.addWidget(self.print_button, 3, 3) self.print_button.setFixedSize(75,25) self.print_button.clicked[bool].connect(self.print) self.resize(1920, 1080) def update(self): global number, pictures for file in os.listdir(os.path.join(path, source)): # add all files with ".jpg" to the list pictures if file.endswith(".{}".format(extension)): pictures.append(file) if len(pictures) > 0: for picture_name in pictures: number += 1 if 0 < number < 7: time.sleep(1) # wait until the picture is transferred picture_new_name = "image{}.{}".format(number, extension) os.rename( os.path.join(path, source, picture_name), os.path.join(path, folder_name, picture_new_name), ) # renames all the given pictures and transfer them in a new folder print(number) time.sleep(0.2) label = self._labels[number-1] pixmap = QtGui.QPixmap(os.path.join(path, folder_name, "image{}.{}".format(number, extension))).scaled(image_width, image_height) label.setPixmap(pixmap) self.ComboBox.addItem("image{}.{}".format(number, extension)) del pictures[:] def print(self): printer = QtPrintSupport.QPrinter() printer.setCopyCount(1) painter = QtGui.QPainter() painter.begin(printer) image = self.ComboBox.currentText() print(path + folder_name +"/"+ image) screen = QtGui.QImage(path + folder_name +"/"+ image) painter.drawImage(QtCore.QRect(0, 0, 700, 500), screen) # End painting painter.end() self.switch_window.emit() ########################################################################### class WindowTwo(QtWidgets.QWidget): switch_window = QtCore.pyqtSignal() def __init__(self): QtWidgets.QWidget.__init__(self) self.setWindowTitle('Window Two') layout = QtWidgets.QGridLayout() self.label = QtWidgets.QLabel("please wait") layout.addWidget(self.label,1,2, alignment=QtCore.Qt.AlignCenter) self.finish_button = QtWidgets.QPushButton('OK') self.finish_button.clicked.connect(self.close) self.finish_button.setFixedSize(75,23) layout.addWidget(self.finish_button, 3,3, alignment=QtCore.Qt.AlignBottom) self.setLayout(layout) self.resize(1920, 1080) ########################################################################### class Login(QtWidgets.QWidget): switch_window = QtCore.pyqtSignal() def __init__(self): QtWidgets.QWidget.__init__(self) self.setWindowTitle('Fotobox') self.resize(1920,1080) layout = QtWidgets.QGridLayout() self.Button = QtWidgets.QPushButton('Weiter') self.Button.setFixedSize(75,23) layout.addWidget(self.Button, 3,3, alignment=QtCore.Qt.AlignRight) self.Button.clicked.connect(self.on_click) self.label = QtWidgets.QLabel("Name: ") self.label.setFixedSize(120,51) layout.addWidget(self.label, 1,1, alignment=QtCore.Qt.AlignRight) self.error_label = QtWidgets.QLabel("") # the label where the error is shown self.error_label.setFixedSize(120,51) layout.addWidget(self.error_label, 2,2) self.lineEdit = QtWidgets.QLineEdit() # input label for the name of the person/group self.lineEdit.setFixedSize(260,31) layout.addWidget(self.lineEdit, 1,2) font2 = self.lineEdit.font() font2.setPointSize(17) self.lineEdit.setFont(font2) self.lineEdit.textChanged.connect(self.issue_test) self.setLayout(layout) def issue_test(self): # tests if the name is used before self.issue = False name = self.lineEdit.text() # reads input label for i in names: if name == i or name+"\n" == i: # if name is already used before: red & bg yellow + issue -> True self.lineEdit.setStyleSheet("color: red; background-color: yellow;") self.error_label.setText("Name bereits Vorhanden! \n Bitte Eingabe ändern.") self.error_label.setStyleSheet("color: red;") self.issue = True if self.issue == False: # when no problem exists the error message disapearse and the input label is white self.lineEdit.setStyleSheet("color: black; background-color: white;") self.issue = False self.error_label.setText("") def on_click(self): # when user click the button to confirm the input global folder_name name = self.lineEdit.text() if name == "": # tests if the input label is empty self.lineEdit.setStyleSheet("color: red; background-color: yellow;") self.error_label.setText(" Keine Eingabe! \n Bitte Eingabe ändern.") self.error_label.setStyleSheet("color: red;") self.issue = True if self.issue == False: # only when input is not empty and not used before folder_name = name os.mkdir(path + folder_name) # creates a folder for the user names.append(folder_name) # add the name to the list of the used names used_names = open(path + name_list, "a") used_names.write(name + "\n") used_names.close() self.switch_window.emit() # switch to the mainwindow ############################################################################## class Controller: def __init__(self): pass def show_login(self): self.login = Login() self.login.switch_window.connect(self.show_main) self.login.show() def show_main(self): self.window = MainWindow() self.window.switch_window.connect(self.show_window_two) self.login.close() self.window.show() def show_window_two(self): self.window_two = WindowTwo() self.window.close() self.window_two.show() def main(): app = QtWidgets.QApplication(sys.argv) controller = Controller() controller.show_login() sys.exit(app.exec_()) if __name__ == '__main__': main() 设置帧号,但是它不起作用。

cv2.VideoCapture.set(cv2.CAP_PROP_POS_FRAMES, x)

这里我要从cap2.set(cv2.CAP_PROP_POS_FRAMES,count)函数中的count开始播放视频。 但这会提高播放avi视频的速度,但不会从指定的计数帧开始播放视频

0 个答案:

没有答案