我在Qt Quick中有一个简单的项目,需要处理相机的输出。该项目应在Android,Windows和Linux上运行。到目前为止,我已经成功地在Android上连接了相机,但在Linux上却没有。
我的设置如下:
main.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();
}
main.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吗?
答案 0 :(得分: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
希望这会有所帮助!