import sys
import cv2
from PyQt5.QtCore import Qt, QThread, pyqtSignal
from PyQt5.QtGui import QImage, QPixmap
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QLabel
class VideoRecorder(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Video Recorder")
self.setGeometry(100, 100, 640, 480)
self.label = QLabel(self)
self.label.resize(640, 480)
self.label.move(0, 0)
self.start_button = QPushButton("Start", self)
self.start_button.move(10, 490)
self.start_button.clicked.connect(self.start_recording)
self.stop_button = QPushButton("Stop", self)
self.stop_button.move(80, 490)
self.stop_button.clicked.connect(self.stop_recording)
self.stop_button.setEnabled(False)
def start_recording(self):
self.start_button.setEnabled(False)
self.stop_button.setEnabled(True)
self.capture = cv2.VideoCapture(0) self.capture.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
self.capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
self.video_thread = VideoThread()
self.video_thread.changePixmap.connect(self.set_frame)
self.video_thread.start()
def stop_recording(self):
self.stop_button.setEnabled(False)
self.start_button.setEnabled(True)
self.video_thread.stop()
self.video_thread.wait()
self.capture.release()
def set_frame(self, frame):
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
image = QImage(frame, frame.shape[1], frame.shape[0], QImage.Format_RGB888)
self.label.setPixmap(QPixmap.fromImage(image))
class VideoThread(QThread):
changePixmap = pyqtSignal(np.ndarray)
def __init__(self, parent=None):
super().__init__(parent)
self.is_running = True
def run(self):
while self.is_running:
ret, frame = self.parent().capture.read()
if ret:
self.changePixmap
import cv2
from PyQt5.QtCore import Qt, QThread, pyqtSignal
from PyQt5.QtGui import QImage, QPixmap
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QLabel
class VideoRecorder(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Video Recorder")
self.setGeometry(100, 100, 640, 480)
self.label = QLabel(self)
self.label.resize(640, 480)
self.label.move(0, 0)
self.start_button = QPushButton("Start", self)
self.start_button.move(10, 490)
self.start_button.clicked.connect(self.start_recording)
self.stop_button = QPushButton("Stop", self)
self.stop_button.move(80, 490)
self.stop_button.clicked.connect(self.stop_recording)
self.stop_button.setEnabled(False)
def start_recording(self):
self.start_button.setEnabled(False)
self.stop_button.setEnabled(True)
self.capture = cv2.VideoCapture(0) self.capture.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
self.capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
self.video_thread = VideoThread()
self.video_thread.changePixmap.connect(self.set_frame)
self.video_thread.start()
def stop_recording(self):
self.stop_button.setEnabled(False)
self.start_button.setEnabled(True)
self.video_thread.stop()
self.video_thread.wait()
self.capture.release()
def set_frame(self, frame):
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
image = QImage(frame, frame.shape[1], frame.shape[0], QImage.Format_RGB888)
self.label.setPixmap(QPixmap.fromImage(image))
class VideoThread(QThread):
changePixmap = pyqtSignal(np.ndarray)
def __init__(self, parent=None):
super().__init__(parent)
self.is_running = True
def run(self):
while self.is_running:
ret, frame = self.parent().capture.read()
if ret:
self.changePixmap
No comments:
Post a Comment
Tell us how you like it.