screenpv.py: use pyqt5 + opencv to open a video or camera
首先用pyqt5+opencv写一个全屏播放视频的工具
import sys
import os
import cv2
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import QPalette, QBrush, QPixmap
import PyQt5 as pq
class Ui_MainWindow(QtWidgets.QWidget):
def __init__(self, parent=None):
super(Ui_MainWindow, self).__init__(parent)
self.videoName, _ = QFileDialog.getOpenFileName(self, "Open", "", "*.mp4;;*.avi;;All Files(*)")
self.timer_camera = QtCore.QTimer() # 初始化定时器
# self.cap = cv2.VideoCapture() # 初始化摄像头
self.cap = cv2.VideoCapture(self.videoName)
self.CAM_NUM = 0
self.set_ui()
self.slot_init()
def slot_init(self):
self.timer_camera.timeout.connect(self.show_camera)
def keyPressEvent(self, event):
print("按下:" + str