分段故障试图显示摄像机视频输入。 PyQt5

时间:2017-11-22 12:15:16

标签: python debugging pyqt raspberry-pi

我正在使用Raspbian开发Raspberry Pi 3 V1.2。我的问题是,有时我的代码工作(一个窗口打开并显示相机提要),有时它没有(错误是分段错误)。我从来没有经历过那些代码有时只能起作用。我知道当编译器处于startVid函数时会发生错误。有人有想法吗?非常感谢您的帮助。

这是我的代码:

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()


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)

    cam = Camera()

    cam.iniCamera()

    cam.startVid()


    sys.exit(app.exec_())

我使用gbd来了解有关错误的更多信息。这是输出:

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

这里输出命令(gdb)bt:

(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?)

1 个答案:

答案 0 :(得分:0)

在退出之前,您是否尝试卸下相机?尝试读取或写入非法内存位置会导致分段错误。

卸载将释放分配给cam对象的所有资源。