Resizing a constant Video stream from OpenCV to PyQt5 with QPainter in a QWidget using a Raspberry Pi
-
What is the use of
self.obj
?if self.caminfo.isNull() != self.caminfo.defaultCamera():
You are comparing a boolean with a QCameraInfo object.Then you are replace your current
cam
object with a new so your capture mode related code is useless.You should start by just translating the QCameraViewfinder example to python.
-
@SGaist Ok i did translate the example to python and it actually did alot. Now a window with the camera feed pops up. Unfortunatly its not very consistent since sometimes the ol' Segmentation fault error still shows and then no window opens. I think thats very strange.
Also when the camera feed opens the terminal output is:** (python3:1197): WARNING **: Error retrieving accessibility bus address: org.freedesktop.DBus.Error.ServiceUnknown: The name org.a11y.Bus was not provided by any .service files Venus USB2.0 Camera [<PyQt5.QtMultimedia.QCameraInfo object at 0x72fafa30>] Capturemode supported QWidget::paintEngine: Should no longer be called QWidget::paintEngine: Should no longer be called
Whats up with QWidget::paintEngine: Should no longer be called?
Do you know how i could add buttons to this window? Do i guess i need layers and a MainWindow, but where should i look for more information?
As always here is my code:import sys from PyQt5 import QtCore , QtWidgets, QtGui, QtMultimedia, QtMultimediaWidgets from PyQt5.QtCore import QObject, pyqtSignal from PyQt5.QtWidgets import QApplication from PyQt5.QtMultimedia import QCamera, QCameraInfo, QMediaObject, QCameraViewfinderSettings, QCameraImageCapture from PyQt5.QtMultimediaWidgets import QCameraViewfinder class Camera(QObject): def __init__(self, parent = QObject()): super(Camera, self).__init__(parent) self.cam = QCamera() self.caminfo = QCameraInfo(self.cam) self.camvfind = QCameraViewfinder() self.camvfindset = QCameraViewfinderSettings() self.cammode = self.cam.CaptureMode(1) self.camimgcap = QCameraImageCapture(self.cam) def iniCamera(self): print(self.caminfo.description()) print(self.caminfo.availableCameras()) if self.cam.isCaptureModeSupported(self.cammode): print("Capturemode supported") def startVid(self): self.camvfind.show() self.cam.setViewfinder(self.camvfind) self.cam.load() self.camvfindset.setResolution(1280,720) #print(self.cam.supportedViewfinderFrameRateRanges(self.camvfind)) self.camvfindset.setMinimumFrameRate(15) self.cam.setCaptureMode(self.cammode) self.cam.start() #self.cam.unload() if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) cam = Camera() cam.iniCamera() cam.startVid() del cam sys.exit(app.exec_())
-
Why are you calling
del cam
just beforesys.exit(app.exec_())
? -
Don't delete objects while you are using them ;)
Can you get a stack trace of the crash ?
-
Ok, it seems like its not possible to catch a Segmentation fault error with stack trace. I used "gdb" to get some information about the error. Here is the output:
(gdb) run qt.py Starting program: /usr/bin/python3 qt.py [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1". [New Thread 0x720a7470 (LWP 20003)] [New Thread 0x716ff470 (LWP 20004)] ** (python3:19975): WARNING **: Error retrieving accessibility bus address: org.freedesktop.DBus.Error.ServiceUnknown: The name org.a11y.Bus was not provided by any .service files [New Thread 0x6ff00470 (LWP 20007)] [New Thread 0x6f5ff470 (LWP 20008)] [New Thread 0x6e6ab470 (LWP 20022)] [Thread 0x6e6ab470 (LWP 20022) exited] [New Thread 0x6e6ab470 (LWP 20023)] [Thread 0x6e6ab470 (LWP 20023) exited] Venus USB2.0 Camera [<PyQt5.QtMultimedia.QCameraInfo object at 0x72fde030>] Capturemode supported Thread 1 "python3" received signal SIGSEGV, Segmentation fault. 0x7344b620 in platform_get_handle () from /opt/vc/lib/libEGL.so
I read many threads about this problem and it could be that i run out of memory. Since Geany-Output is:
Segmentation fault ------------------ (program exited with code: 139) Press return to continue
and code :139 means "attempt to access a virtual address which is not in your address space"
EDIT: the problem could also occur because some of the modules are written in C++. I read that some problems can happen because of this
here is more output of gdb that "should" give more info
(gdb) bt #0 0x733d4620 in platform_get_handle () from /opt/vc/lib/libEGL.so #1 0x733c9f2c in eglCreateWindowSurface () from /opt/vc/lib/libEGL.so #2 0x722e7004 in ?? () from /usr/lib/arm-linux-gnueabihf/qt5/plugins/xcbglintegrations/libqxcb-egl-integration.so Backtrace stopped: previous frame identical to this frame (corrupt stack?)
-
Ok, well i can give you some more info. It seems that the Segmentation fault is because of this line
self.camvfind.show()
or the line after that. I just tested this with putting print("1") after every line and looking how many lines of 1s get printed.Also someone from stackoverflow wrote this :"Most likely there is a race condition in some of the modules you load and someone accesses memory before someone else has set it up. It looks like the program is looking for a handle in libEGL and that function is triggering the segfault."
This person also suggested that i look at the memory load of the program but it doesnt seem to matter because the memory load is sometimes high and it works and sometimes its lower and it doesnt work -
Do you have several versions of Qt installed on your device ?
-
I have qt5 and qt4 but i deinstalled qt4 and some folders are still left. They are in: /usr/lib/arm-linux-gnueabihf/qt4
/usr/share/qt4
Also output ofqmake --version
is :QMake version 3.0 Using Qt version 5.7.1 in /usr/lib/arm-linux-gnueabihf
-
How did you install PyQt ?
-
I tried to install PyQt from source but it always gave me an error so i just used sudo apt-get install pyqt5-dev/pyqt5-dev-tools/python3-pyqt5.qtmultimedia.
I also wrote my question with Segmentation Fault on other forums and someone said: "There is a buffer overflow happening in the eglCreateWindowSurface function". To be honest i dont know exactly what to do with this or how this would help me with my problem. The eglCreateWindowSurface function has something with openGl to do, maybe there is a problem with it? You got an idea? -
Do you have the latest version of Raspbian running ?
-
Yeah i feel like i do sudo apt-get update && upgrade at least once a day. I just checked about SIP and i compiled it from source but i cant remember if i actually used the command make and make install. Does that mean i have to reinstall pyqt5 again? I guess i just open a new thread. Thanks for all the help @SGaist