簡體   English   中英

嘗試顯示攝像機視頻供稿時出現細分錯誤。 PyQt5

[英]Segmentation fault trying to show camera video feed. PyQt5

我正在使用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?)

在退出之前,您是否嘗試過卸載相機? 分段錯誤是由於嘗試讀取或寫入非法內存位置而引起的。

卸載將釋放分配給cam對象的所有資源。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM