Python openCv Pyqt5 [closed]

asked 2018-11-03 11:53:44 -0600

Hi I am Developing a Project with Python Opencv Pyqt. An application that starts the camera recognition that starts and stops the camera. But I can't turn on the camera in Qlabelin Codes This way I wonder how I can fix this error.

image description

       import cv2
      import sys

     from PyQt5.QtCore import QTimer
     from PyQt5.QtGui import QImage, QPixmap
     from PyQt5.QtWidgets import QApplication, QDialog
     from PyQt5 import QtCore, QtGui, QtWidgets


    class Ui_Yuztanima(object):


def setupUi(self, Yuztanima):

    Yuztanima.setObjectName("Yuztanima")
    Yuztanima.setWindowModality(QtCore.Qt.NonModal)
    Yuztanima.resize(1098, 896)
    icon = QtGui.QIcon()
    icon.addPixmap(QtGui.QPixmap("Giris/Flag_of.png"), QtGui.QIcon.Normal,
                   QtGui.QIcon.Off)
    Yuztanima.setWindowIcon(icon)
    self.centralwidget = QtWidgets.QWidget(Yuztanima)
    self.centralwidget.setObjectName("centralwidget")
    self.imgLabel = QtWidgets.QLabel(self.centralwidget)
    self.imgLabel.setGeometry(QtCore.QRect(240, 80, 640, 480))
    self.imgLabel.setFrameShape(QtWidgets.QFrame.Box)
    self.imgLabel.setText("")
    self.imgLabel.setObjectName("imgLabel")
    self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
    self.horizontalLayoutWidget.setGeometry(QtCore.QRect(10, 700, 1081, 151))
    self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
    self.Menuduzen_2 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
    self.Menuduzen_2.setContentsMargins(0, 0, 0, 0)
    self.Menuduzen_2.setObjectName("Menuduzen_2")
    self.startButton = QtWidgets.QPushButton(self.horizontalLayoutWidget)
    icon1 = QtGui.QIcon()
    icon1.addPixmap(QtGui.QPixmap("../../Desktop/camera-play-699330.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
    self.startButton.setIcon(icon1)
    self.startButton.setIconSize(QtCore.QSize(100, 100))
    self.startButton.setObjectName("startButton")
    self.startButton.clicked.connect(self.start_webcam)
    self.Menuduzen_2.addWidget(self.startButton)
    self.stopButton = QtWidgets.QPushButton(self.horizontalLayoutWidget)
    icon2 = QtGui.QIcon()
    icon2.addPixmap(QtGui.QPixmap("../../Desktop/stop_song_red-512.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
    self.stopButton.setIcon(icon2)
    self.stopButton.setIconSize(QtCore.QSize(100, 100))
    self.stopButton.setObjectName("stopButton")
    self.stopButton.clicked.connect(self.stop_webcam)
    self.Menuduzen_2.addWidget(self.stopButton)
    self.yuztanimabaslatbutton = QtWidgets.QPushButton(self.horizontalLayoutWidget)
    icon3 = QtGui.QIcon()
    icon3.addPixmap(QtGui.QPixmap("Turkce/YuzTanima.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
    self.yuztanimabaslatbutton.setIcon(icon3)
    self.yuztanimabaslatbutton.setIconSize(QtCore.QSize(100, 100))
    self.yuztanimabaslatbutton.setObjectName("yuztanimabaslatbutton")
    self.Menuduzen_2.addWidget(self.yuztanimabaslatbutton)
    self.cikisbutton = QtWidgets.QPushButton(self.horizontalLayoutWidget)
    icon4 = QtGui.QIcon()
    icon4.addPixmap(QtGui.QPixmap("Giris/erase_delete_remove_wipe_out-512.png"), QtGui.QIcon.Normal,
                    QtGui.QIcon.Off)
    self.cikisbutton.setIcon(icon4)
    self.cikisbutton.setIconSize(QtCore.QSize(100, 100))
    self.cikisbutton.setObjectName("cikisbutton")
    self.Menuduzen_2.addWidget(self.cikisbutton)
    Yuztanima.setCentralWidget(self.centralwidget)
    self.menubar = QtWidgets.QMenuBar(Yuztanima)
    self.menubar.setGeometry(QtCore.QRect(0, 0, 1098, 26))
    self.menubar.setObjectName("menubar")
    Yuztanima.setMenuBar(self.menubar)
    self.statusbar = QtWidgets.QStatusBar(Yuztanima)
    self.statusbar.setObjectName("statusbar")
    Yuztanima.setStatusBar(self.statusbar)

    self.retranslateUi(Yuztanima)
    self.cikisbutton.clicked.connect(Yuztanima.close)
    QtCore.QMetaObject.connectSlotsByName(Yuztanima)
    self.image = None

def retranslateUi(self, Yuztanima):
    _translate = QtCore.QCoreApplication.translate
    Yuztanima.setWindowTitle(_translate("Yuztanima", "Yuz Tanıma Yazılımı"))
    self.startButton.setText(_translate("Yuztanima", "Kamerayı Başlat"))
    self.stopButton.setText(_translate("Yuztanima", "Kamerayı Durdur"))
    self.yuztanimabaslatbutton.setText(_translate("Yuztanima", "Yuz Tanımayı Başlat"))
    self.cikisbutton.setText(_translate("Yuztanima", "Çıkış"))

def start_webcam(self):

    self.capture = cv2.VideoCapture(0)
    self.capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
    self.capture.set(cv2.CAP_PROP_FRAME_WIDTH, 640)

    self.timer = QTimer(self)
    self.timer.timeout.connect(self.update_frame)
    self.timer.start(5)

def update_frame(self):

    ret, self.image ...
(more)
edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant by berak
close date 2018-11-03 11:59:32.373195

Comments

looks like your problem is NOT AT ALL about opencv, but about qt.

(i don't think, we can help you from here)

berak gravatar imageberak ( 2018-11-03 11:56:38 -0600 )edit

(also, please make it a habit of NEVER naming things in your native language. the day will come, when you need help on the internet, and noone will understand your code.)

berak gravatar imageberak ( 2018-11-03 11:58:28 -0600 )edit

(also, take a hint from an old dog, here:

computer-vision is all about number crunching, NOT about gui. in the end, noone will look at it (or use that). your current code is 98% gui and 2% opencv, and it currently neither covers face detection, save face recognition !

focus on things that matter, NOT Qt problems !)

berak gravatar imageberak ( 2018-11-03 12:28:09 -0600 )edit