Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import os
- import cv2
- import numpy as np
- from PyQt4 import QtGui, QtCore, Qt
- from PyQt4.QtCore import *
- from PyQt4.QtGui import *
- from ui_login_Opencv import Ui_MainWindow
- class Video():
- def __init__(self,capture):
- self.capture = capture
- self.currentFrame=np.array([])
- def captureNextFrame(self):
- """
- capture frame and reverse RBG BGR and return opencv image
- """
- ret, readFrame=self.capture.read()
- if(ret==True):
- self.currentFrame=cv2.cvtColor(readFrame,cv2.COLOR_BGR2RGB)
- def convertFrame(self):
- """ converts frame to format suitable for QtGui """
- try:
- height,width=self.currentFrame.shape[:2]
- img=QtGui.QImage(self.currentFrame,width,height,QtGui.QImage.Format_RGB888)
- img=QtGui.QPixmap.fromImage(img)
- self.previousFrame = self.currentFrame
- return img
- except:
- return None
- class Gui(QtGui.QMainWindow):
- def __init__(self,parent=None):
- QtGui.QWidget.__init__(self,parent)
- self.ui = Ui_MainWindow()
- self.ui.setupUi(self)
- self.video = Video(cv2.VideoCapture(0))
- self._timer = QtCore.QTimer(self)
- self._timer.timeout.connect(self.play)
- self._timer.start(27)
- self.update()
- def play(self):
- try:
- self.video.captureNextFrame()
- self.ui.videoFrame.setPixmap(self.video.convertFrame())
- self.ui.videoFrame.setScaledContents(True)
- except TypeError:
- print "No frame"
- def main():
- import sys, time
- app = QtGui.QApplication(sys.argv)
- # Create and display the splash screen
- splash_pixmap = QPixmap('Imagenes/SplashScreem.png')
- splash = QSplashScreen(splash_pixmap, Qt.WindowStaysOnTopHint)
- splash.setMask(splash_pixmap.mask())
- splash.show()
- app.processEvents()
- # Simulate something that takes time
- time.sleep(2)
- ex = Gui()
- ex.show()
- splash.finish(ex)
- sys.exit(app.exec_())
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement