qt_drawer.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. __author__ = "heider"
  4. __doc__ = r"""
  5. Created on 9/9/22
  6. """
  7. __all__ = []
  8. from PIL.ImageQt import ImageQt
  9. from PyQt6 import QtGui
  10. from PyQt6.QtCore import QTimer
  11. from PyQt6.QtGui import QPixmap
  12. from PyQt6.QtWidgets import QMainWindow, QLabel, QScrollArea, QApplication
  13. from draugr.opencv_utilities import AsyncVideoStream
  14. def aushduah():
  15. """
  16. :return:
  17. :rtype:
  18. """
  19. import sys
  20. class CameraViewer(QMainWindow):
  21. """ """
  22. def __init__(self, hz=33):
  23. super().__init__()
  24. self.imageLabel = QLabel()
  25. self.imageLabel.setBackgroundRole(QtGui.QPalette.Base)
  26. self.imageLabel.setScaledContents(True)
  27. self.scrollArea = QScrollArea()
  28. self.scrollArea.setWidget(self.imageLabel)
  29. self.setCentralWidget(self.scrollArea)
  30. self.setWindowTitle("Image Viewer")
  31. self.resize(640, 480)
  32. timer = QTimer(self)
  33. timer.timeout.connect(self.open)
  34. timer.start(hz)
  35. def open(self):
  36. """
  37. :return:
  38. :rtype:
  39. """
  40. # get data and display
  41. _, pilimg = vs.read()
  42. image = ImageQt(pilimg)
  43. if image.isNull():
  44. return
  45. self.imageLabel.setPixmap(QPixmap.fromImage(image))
  46. self.imageLabel.adjustSize()
  47. with AsyncVideoStream() as vs:
  48. app = QApplication(sys.argv)
  49. camera_viewer = CameraViewer()
  50. camera_viewer.show()
  51. sys.exit(app.exec_())
  52. if __name__ == "__main__":
  53. aushduah()