0

On my raspberry pi when i try to launch my python script.

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5 import uic, QtGui
import numpy as np
import cv2

taker = False

recorder = False

def picture():
    global taker
    taker = True

def recording():
    global recorder
    recorder = True

def stoprecording():
    global recorder
    recorder = False

class opencv(QThread):
    params = pyqtSignal()

    def run(self):
        cap = cv2.VideoCapture(0)
        while (True):
            global taker
            global recorder
            ret, frame = cap.read()
            if taker == True:
                cv2.imwrite('image.jpg', frame)
                taker = False
            # Display the resulting frame
            cv2.imshow('frame', frame)
            if cv2.waitKey(1) & 0xFF == ord('q'):
                break

        cap.release()
        cv2.destroyAllWindows()


class Camera(QWidget):
    def __init__(self):
        super().__init__()
        self.window()

    def window(self):
        self.setGeometry(100, 100, 200, 150)
        self.setWindowTitle("James Strand Camera")
        self.buttons()
        self.show()

    def buttons(self):
        button = QPushButton("Take picture", self)
        button.clicked.connect(self.take)
        self.thread = opencv()
        self.thread.start()

    def take(self):
        picture()

    def record(self):
        recording()
    def stop(self):
        stoprecording()


app = QApplication(sys.argv)
window = Camera()
sys.exit(app.exec())

I get this error message.

(python3:5850): GLib-GObject-WARNING **: 13:30:25.609: cannot register existing type 'GdkDisplayManager' (python3:5850): GLib-CRITICAL **: 13:30:25.610: g_once_init_leave: assertion 'result != 0' failed (python3:5850): GLib-GObject-CRITICAL **: 13:30:25.610: g_object_new_with_properties: assertion 'G_TYPE_IS_OBJECT (object_type)' failed

I also tried the solution.

sudo nano /etc/xdg/qt5ct/qt5ct.conf

Then changing the line.

style=gtk2

To.

style=gtk3

Then saving the config file qt5ct.confg.

Doing this however only solved part of my problem, I Got the cv2 window to open up, But the preview window is completely frozen.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.