amin这个例子,使用了比较复杂高阶的qml技巧,但是也有局限性。下面分3个部分,分别是界面部分,算法部分和扩展部分,简单地对这个问题进行理解。
视频地址 :https://files.cnblogs.com/files/jsxyhelu/amin%E4%BE%8B%E5%AD%90%E8%A7%86%E9%A2%91.zip
standardButtons
}
messageDialog.close()
}
}
}
anchors.rightMargin
anchors.bottomMargin
anchors.leftMargin
anchors.topMargin
anchors.fill: parent
//TabBar和swipview要对应起来
onCurrentIndexChanged:
{
tabBar.setCurrentIndex(swipeView.currentIndex)
}
//视频预览
Page
{……
padding
Text
{
id: helpText
wrapMode: Text.Wrap
anchors.left: parent.left
anchors.right: parent.right
text: "由衷感谢:<a href=\"http://amin-ahmadi.com/quick-camera-cv/\">http://amin-ahmadi.com/quick-camera-cv</a>" +
"给本程序很多借鉴" +
"<br>" +
"<br>" +
"作者博客:" +
"<br>" +
"<a href=\"jsxyhelu.cnblogs.com\">jsxyhelu.cnblogs.com</a>" +
"<br>" +
"<a href=\"jsxyhelu.cnblogs.com\"><img src=\"http://images2015.cnblogs.com/blog/508489/201607/508489-20160731065441684-483128601.png\" alt=\"欢迎访问!\"></a>"+
"<br>" +
"<b>版权</b>" +
"本程序使用 <a href=\"http://qt.io/\">Qt Framework</a> 作为GUI" +
"<br>" +
"同时使用 <a href=\"http://opencv.org/\">OpenCV</a> 做图像处理算法." +
"<br>" +
"程序采用ICO来自<a href=\"http://flaticon.com/\">Flat Icon</a>."
onLinkActivated:
{
Qt.openUrlExternally(link);
}
}
{
id: cameraCombo
Layout.fillWidth: true
Layout.fillHeight: true
model: QtMultimedia.availableCameras
textRole: "displayName"
delegate: ItemDelegate
{
text: modelData.displayName
}
onCurrentIndexChanged:
{
camera.stop()
camera.deviceId = model[currentIndex].deviceId
camera.start()
}
}
void QCvImageProcessor::setCamera(QVariant v)
{
QObject *o = qvariant_cast<QObject *>(v);
camera = qvariant_cast<QCamera *>(o->property("mediaObject"));
camera->setCaptureMode(QCamera::CaptureStillImage);
imageCapture = new QCameraImageCapture(camera);
camera->focus()->setFocusMode(QCameraFocus::ContinuousFocus);
camera->focus()->setFocusPointMode(QCameraFocus::FocusPointAuto);
//直接在这里设置动作级联
connect(imageCapture, &QCameraImageCapture::imageSaved, [this](int id, const QString &fileName)
{
Q_UNUSED(id);
processSavedImage(fileName);
});
}
void QCvImageProcessor::capture()
{
if(imageCapture->isReadyForCapture())
{
//注意这里获得一个可用的图片地址的方法
imageCapture->capture(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation));
}
else
{
emit errorOccured("Camera is not ready to capture.");
}
}