+1 oy
OpenCv kategorisinde (230 puan) tarafından soruldu

Merhaba Python Opencv Pyqt ile Bir Proje Geliştiriyorum.  Amaçladığım Kamerayı başlatıp durduran yuz tanımayı başlatan bir uygulama Fakat kamerayı Qlabelin içerisinde Açamıyorum Kodlar Bu şekilde Acaba bu hatayı nasıl Düzeltebilirim.


 
  1. import cv2
  2. import sys
  3.  
  4. from PyQt5.QtCore import QTimer
  5. from PyQt5.QtGui import QImage, QPixmap
  6. from PyQt5.QtWidgets import QApplication, QDialog
  7. from PyQt5 import QtCore, QtGui, QtWidgets
  8.  
  9.  
  10. class Ui_Yuztanima(object):
  11.  
  12.  
  13. def setupUi(self, Yuztanima):
  14.  
  15. Yuztanima.setObjectName("Yuztanima")
  16. Yuztanima.setWindowModality(QtCore.Qt.NonModal)
  17. Yuztanima.resize(1098, 896)
  18. icon = QtGui.QIcon()
  19. icon.addPixmap(QtGui.QPixmap("Giris/Flag_of.png"), QtGui.QIcon.Normal,
  20. QtGui.QIcon.Off)
  21. Yuztanima.setWindowIcon(icon)
  22. self.centralwidget = QtWidgets.QWidget(Yuztanima)
  23. self.centralwidget.setObjectName("centralwidget")
  24. self.imgLabel = QtWidgets.QLabel(self.centralwidget)
  25. self.imgLabel.setGeometry(QtCore.QRect(240, 80, 640, 480))
  26. self.imgLabel.setFrameShape(QtWidgets.QFrame.Box)
  27. self.imgLabel.setText("")
  28. self.imgLabel.setObjectName("imgLabel")
  29. self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
  30. self.horizontalLayoutWidget.setGeometry(QtCore.QRect(10, 700, 1081, 151))
  31. self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
  32. self.Menuduzen_2 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
  33. self.Menuduzen_2.setContentsMargins(0, 0, 0, 0)
  34. self.Menuduzen_2.setObjectName("Menuduzen_2")
  35. self.startButton = QtWidgets.QPushButton(self.horizontalLayoutWidget)
  36. icon1 = QtGui.QIcon()
  37. icon1.addPixmap(QtGui.QPixmap("../../Desktop/camera-play-699330.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
  38. self.startButton.setIcon(icon1)
  39. self.startButton.setIconSize(QtCore.QSize(100, 100))
  40. self.startButton.setObjectName("startButton")
  41. self.startButton.clicked.connect(self.start_webcam)
  42. self.Menuduzen_2.addWidget(self.startButton)
  43. self.stopButton = QtWidgets.QPushButton(self.horizontalLayoutWidget)
  44. icon2 = QtGui.QIcon()
  45. icon2.addPixmap(QtGui.QPixmap("../../Desktop/stop_song_red-512.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
  46. self.stopButton.setIcon(icon2)
  47. self.stopButton.setIconSize(QtCore.QSize(100, 100))
  48. self.stopButton.setObjectName("stopButton")
  49. self.stopButton.clicked.connect(self.stop_webcam)
  50. self.Menuduzen_2.addWidget(self.stopButton)
  51. self.yuztanimabaslatbutton = QtWidgets.QPushButton(self.horizontalLayoutWidget)
  52. icon3 = QtGui.QIcon()
  53. icon3.addPixmap(QtGui.QPixmap("Turkce/YuzTanima.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
  54. self.yuztanimabaslatbutton.setIcon(icon3)
  55. self.yuztanimabaslatbutton.setIconSize(QtCore.QSize(100, 100))
  56. self.yuztanimabaslatbutton.setObjectName("yuztanimabaslatbutton")
  57. self.Menuduzen_2.addWidget(self.yuztanimabaslatbutton)
  58. self.cikisbutton = QtWidgets.QPushButton(self.horizontalLayoutWidget)
  59. icon4 = QtGui.QIcon()
  60. icon4.addPixmap(QtGui.QPixmap("Giris/erase_delete_remove_wipe_out-512.png"), QtGui.QIcon.Normal,
  61. QtGui.QIcon.Off)
  62. self.cikisbutton.setIcon(icon4)
  63. self.cikisbutton.setIconSize(QtCore.QSize(100, 100))
  64. self.cikisbutton.setObjectName("cikisbutton")
  65. self.Menuduzen_2.addWidget(self.cikisbutton)
  66. Yuztanima.setCentralWidget(self.centralwidget)
  67. self.menubar = QtWidgets.QMenuBar(Yuztanima)
  68. self.menubar.setGeometry(QtCore.QRect(0, 0, 1098, 26))
  69. self.menubar.setObjectName("menubar")
  70. Yuztanima.setMenuBar(self.menubar)
  71. self.statusbar = QtWidgets.QStatusBar(Yuztanima)
  72. self.statusbar.setObjectName("statusbar")
  73. Yuztanima.setStatusBar(self.statusbar)
  74.  
  75. self.retranslateUi(Yuztanima)
  76. self.cikisbutton.clicked.connect(Yuztanima.close)
  77. QtCore.QMetaObject.connectSlotsByName(Yuztanima)
  78. self.image = None
  79.  
  80. def retranslateUi(self, Yuztanima):
  81. _translate = QtCore.QCoreApplication.translate
  82. Yuztanima.setWindowTitle(_translate("Yuztanima", "Yuz Tanıma Yazılımı"))
  83. self.startButton.setText(_translate("Yuztanima", "Kamerayı Başlat"))
  84. self.stopButton.setText(_translate("Yuztanima", "Kamerayı Durdur"))
  85. self.yuztanimabaslatbutton.setText(_translate("Yuztanima", "Yuz Tanımayı Başlat"))
  86. self.cikisbutton.setText(_translate("Yuztanima", "Çıkış"))
  87.  
  88. def start_webcam(self):
  89.  
  90. self.capture = cv2.VideoCapture(0)
  91. self.capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
  92. self.capture.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
  93.  
  94. self.timer = QTimer(self)
  95. self.timer.timeout.connect(self.update_frame)
  96. self.timer.start(5)
  97.  
  98. def update_frame(self):
  99.  
  100. ret, self.image = self.capture.read()
  101. self.image = cv2.flip(self.image, 1)
  102. self.displayImage(self.image, 1)
  103.  
  104. def stop_webcam(self):
  105.  
  106. self.timer.stop()
  107.  
  108. def displayImage(self, img):
  109.  
  110. qformat = QImage.Format_Indexed8
  111. if len(img.shape) == 3:
  112. if img.shape[2] == 4:
  113. qformat = QImage.Format_RGBA8888
  114. else:
  115. qformat = QImage.Format_RGB888
  116.  
  117. outImage = QImage(img, img.shape[1], img.shape[0], img.strides[0], qformat)
  118. outImage = outImage.rgbSwapped()
  119.  
  120. if Yuztanima == 1:
  121. self.imgLabel.setPixmap(QPixmap.fromImage(outImage))
  122. self.imgLabel.setScaledContents(True)
  123. if __name__ == "__main__":
  124. app = QtWidgets.QApplication(sys.argv)
  125. Yuztanima = QtWidgets.QMainWindow()
  126. ui = Ui_Yuztanima()
  127. ui.setupUi(Yuztanima)
  128. Yuztanima.show()
  129. sys.exit(app.exec_())

1 cevap

0 oy
(4.1k puan) tarafından cevaplandı

Bu sayfadaki kaynağı inceleyebilirsin.

Kaynak: http://benhoff.net/face-detection-opencv-pyqt.html

Yazılım Biliminin Soru Cevap Platformuna hepiniz hoşgeldiniz. Bu platformda kurallara uyarak diğer geliştiricilerle yardımlaşabilirsiniz.

Kategoriler

...