Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. import sys
  2. from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout
  3. from PyQt5.QtGui import QIcon, QFont, QImage, QPixmap
  4. from PyQt5.QtCore import QThread, pyqtSignal, pyqtSlot, Qt
  5. import numpy as np
  6. import cv2
  7.  
  8.  
  9. class Thread(QThread):
  10. changePixmap = pyqtSignal(QImage)
  11.  
  12. def run(self):
  13. cap = cv2.VideoCapture(0)
  14.  
  15. while True:
  16. ret, frame = cap.read()
  17.  
  18. if ret:
  19. rgbImage = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
  20. converToQtFormat = QImage(rgbImage.data, rgbImage.shape[1], rgbImage.shape[0], QImage.Format_RGB888)
  21. p = converToQtFormat.scaled(640, 480, Qt.KeepAspectRatio)
  22. self.changePixmap.emit(p)
  23.  
  24.  
  25.  
  26. app = QApplication(sys.argv)
  27. window = QWidget()
  28.  
  29. window.setGeometry(300, 100, 1000, 800)
  30. window.setWindowTitle("PyQT Test")
  31.  
  32. layout = QVBoxLayout()
  33.  
  34. font = QFont("Times", 12, QFont.Bold)
  35.  
  36. label = QLabel("Texto ejemplo")
  37. label.setFont(font)
  38. layout.addWidget(label)
  39. window.setLayout(layout)
  40.  
  41.  
  42. @pyqtSlot(QImage)
  43. def setImage(image):
  44. label.setPixmap(QPixmap.fromImage(image))
  45.  
  46. th = Thread(window)
  47. th.changePixmap.connect(setImage)
  48. th.start()
  49.  
  50.  
  51. window.show()
  52.  
  53. sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement