У меня есть код pyQt5, когда я открываю диалог, и есть 2 кнопки, одна для открытия веб-камеры, другая для снимка. когда я нажимаю на открытую камеру, она показывает Camera On, затем Close автоматически и говорит Camera Off.
Также в некоторой части говорится: "" 'Этот код недоступен "" "", как ясно видно в классе части кода "class Ui_Dialog () "недостижимая часть. Также я не могу опубликовать недоступную часть. Ищу любезный ответ, спасибо
Код:
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
import cv2
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtGui import QImage, QPixmap
from PyQt5.QtWidgets import QDialog, QApplication
from PyQt5.uic import loadUi
class employirisScan(QDialog):
def __init__(self):
super(employirisScan, self).__init__()
loadUi('EmployScan.ui', self)
self.logic = 0
self.value = 1
self.SHOW.clicked.connect(self.onClicked)
self.TEXT.setText('Kindly Press "SHOW" to open webcam')
self.CAPTURE.clicked.connect(self.CaptureClicked)
@QtCore.pyqtSlot()
def onClicked(self):
self.TEXT.setText('Kindly Press "CAPTURE" to store image')
cap = cv2.VideoCapture(0)
while (cap.isOpened()):
ret, frame = cap.read()
if ret == True:
self.displayImage(frame, 1)
cv2.waitKey()
if (self.logic == 2):
self.value = self.value + 1
cv2.imwrite('C:/Users/Azmat Hayat/Desktop/New folder/%s.png' % (self.value), frame)
self.logic = 1
self.TEXT.setText('Your Image Saved Successfully, For another Press CAPTURE Button again')
else:
print('return not found')
cap.release()
cv2.destroyAllwindows()
def CaptureClicked(self):
self.logic = 2
def displayImage(self, img, window=1):
qformat = QImage.Format_Indexed8
if len(img.shape) == 3:
if (img.shape[2]) == 4:
qformat = QImage.Format_RGBA8888
else:
qformat = QImage.Format_RGB888
img = QImage(img, img.shape[1], img.shape[0], qformat)
img = img.rgbSwapped()
self.imgLabel.setPixmap(QPixmap.fromImage(img))
self.imgLabel.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())