Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. import sys
  2. import os
  3. import cv2
  4. import numpy as np
  5. from PyQt4 import QtGui, QtCore, Qt
  6. from PyQt4.QtCore import *
  7. from PyQt4.QtGui import *
  8. from ui_login_Opencv import Ui_MainWindow
  9.  
  10. class Video():
  11. def __init__(self,capture):
  12. self.capture = capture
  13. self.currentFrame=np.array([])
  14.  
  15.  
  16. def captureNextFrame(self):
  17. """
  18. capture frame and reverse RBG BGR and return opencv image
  19. """
  20.  
  21. ret, readFrame=self.capture.read()
  22. if(ret==True):
  23. self.currentFrame=cv2.cvtColor(readFrame,cv2.COLOR_BGR2RGB)
  24.  
  25.  
  26. def convertFrame(self):
  27. """ converts frame to format suitable for QtGui """
  28. try:
  29. height,width=self.currentFrame.shape[:2]
  30. img=QtGui.QImage(self.currentFrame,width,height,QtGui.QImage.Format_RGB888)
  31. img=QtGui.QPixmap.fromImage(img)
  32. self.previousFrame = self.currentFrame
  33. return img
  34. except:
  35.  
  36. return None
  37.  
  38.  
  39. class Gui(QtGui.QMainWindow):
  40. def __init__(self,parent=None):
  41. QtGui.QWidget.__init__(self,parent)
  42. self.ui = Ui_MainWindow()
  43. self.ui.setupUi(self)
  44. self.video = Video(cv2.VideoCapture(0))
  45. self._timer = QtCore.QTimer(self)
  46. self._timer.timeout.connect(self.play)
  47. self._timer.start(27)
  48. self.update()
  49.  
  50. def play(self):
  51. try:
  52. self.video.captureNextFrame()
  53. self.ui.videoFrame.setPixmap(self.video.convertFrame())
  54. self.ui.videoFrame.setScaledContents(True)
  55. except TypeError:
  56. print "No frame"
  57.  
  58. def main():
  59. import sys, time
  60. app = QtGui.QApplication(sys.argv)
  61.  
  62. # Create and display the splash screen
  63. splash_pixmap = QPixmap('Imagenes/SplashScreem.png')
  64. splash = QSplashScreen(splash_pixmap, Qt.WindowStaysOnTopHint)
  65. splash.setMask(splash_pixmap.mask())
  66. splash.show()
  67. app.processEvents()
  68.  
  69. # Simulate something that takes time
  70. time.sleep(2)
  71.  
  72. ex = Gui()
  73. ex.show()
  74. splash.finish(ex)
  75. sys.exit(app.exec_())
  76.  
  77. if __name__ == '__main__':
  78. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement