【问题标题】:Using Camera on Linux Desktop in Qt Quick在 Qt Quick 中使用 Linux 桌面上的相机
【发布时间】:2019-05-12 16:45:40
【问题描述】:

我在 Qt Quick 中有一个简单的项目,我需要在其中处理来自相机的输出。该项目应在 Android、Windows 和 Linux 上运行。到目前为止,我在 Android 上成功连接到相机,但在 Linux 上却没有。

我的设置如下:

ma​​in.cpp

#include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;

    return app.exec();
}

ma​​in.qml

import QtQuick 2.9
import QtQuick.Controls 2.2
import QtMultimedia 5.9

ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("EyeGaze")

    SwipeView {
        id: swipeView
        anchors.fill: parent
        currentIndex: tabBar.currentIndex

        CameraViewForm {}

        AboutForm {}
    }

    footer: TabBar {
        id: tabBar
        currentIndex: swipeView.currentIndex

        TabButton {
            text: qsTr("Main")
        }
        TabButton {
            text: qsTr("About")
        }
    }
}

CameraViewForm.qml

import QtQuick 2.9
import QtQuick.Controls 2.2
import QtMultimedia 5.9

Page {
    width: 600
    height: 400

    header: Label {
        text: qsTr("Camera View")
        horizontalAlignment: Text.AlignHCenter
        font.pixelSize: Qt.application.font.pixelSize * 2
        padding: 10
    }

    Camera {
           id: camera
           position: Camera.FrontFace
       }

       VideoOutput {
           source: camera
           anchors.fill: parent
           focus: visible // to receive focus and capture key events when visible
       }
}

我收到CameraBin error: "Could not read from resource." 和相机视图中的空白屏幕。

我尝试通过 C++ 代码检查摄像头可用性(使用 QCameraInfo::availableCameras()),我发现我的笔记本电脑确实有一个位于 /dev/video0 的网络摄像头,程序似乎可以访问该摄像头。

我是否错误地访问了相机?我应该用 C++ 代码而不是 QML 来做吗?

【问题讨论】:

    标签: android qt camera qml qtmultimedia


    【解决方案1】:

    实际上,您的代码应该可以工作(至少它可以在我这边工作)。这里有一些提示。

    首先,检查是否有任何东西正在使用您的网络摄像头:

    lsof /dev/video0
    

    fuser /dev/video0
    

    如果没有输出——很好,继续。否则,请检查您的网络摄像头发生了什么以及实际使用它的人。


    检查网络摄像头的权限是什么:

    ls -la /dev/video0
    

    可能是这样的:

    crw-rw----+ 1 root video 81, 0 тра 10 13:38 /dev/video0
    

    检查您的用户是否在video组中,否则,添加它

    adduser YOUR_USER video
    

    希望这会有所帮助!

    【讨论】:

    • 非常感谢您的帮助!我刚刚发现问题是我的网络摄像头的驱动程序不小心被卸载了,但我仍然将您的答案标记为正确的答案,因为我相信它可能会对遇到此问题的其他人有所帮助。
    • @DmitryOrlov 太好了,你已经想通了。因为,它看起来不像 Qt/QML 问题。祝你好运!
    猜你喜欢
    • 2011-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多