首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在标签中显示来自QCamera的图像

在标签中显示来自QCamera的图像
EN

Stack Overflow用户
提问于 2015-01-06 21:40:42
回答 2查看 2.1K关注 0票数 0

我正在写一个程序,用来显示两个相邻的摄像头。在Qt中,使用QCamera非常简单。但是我的相机转了90度,所以我也得把相机转到这张图上。

QCamera变量没有命令来旋转它,所以我想在标签中显示它,而不是在取景器中。所以我拿了一张图片,将它翻转并显示在标签中。

代码语言:javascript
复制
QImage img;
QPixmap img_;
img = ui->viewfinder->grab().toImage();
img_ = QPixmap::fromImage(img);
img_ = img_.transformed(QTransform().rotate((90)%360));
QImage img2;
QPixmap img2_;
img2 = ui->viewfinder->grab().toImage();
img2_ = QPixmap::fromImage(img2);
img2_ = img2_.transformed(QTransform().rotate((90)%360));
ui->label->setPixmap(img_);
ui->label_2->setPixmap(img2_);

当我启动程序时,只有两个相邻的黑盒。(在代码中,我删除了它的部分,但相机在取景器中工作正常,所以我认为没有问题)

EN

回答 2

Stack Overflow用户

发布于 2015-11-17 15:46:37

试试这个:img_ = QPixmap::grabWindow(ui->viewfinder->winId(), 0, 0, -1, -1); (作为QPixmap拍摄快照)或img = QPixmap::grabWindow(ui->viewfinder->winId(), 0, 0, -1, -1).toImage(); (作为QImage拍摄快照)

票数 0
EN

Stack Overflow用户

发布于 2015-11-17 20:38:34

您可以使用相机的方向来校正取景器中的图像方向,如Qt文档中所述。链接如下:

http://doc.qt.io/qt-5/cameraoverview.html

下面是文档中的代码:

代码语言:javascript
复制
// Assuming a QImage has been created from the QVideoFrame that needs to be presented
QImage videoFrame;
QCameraInfo cameraInfo(camera); // needed to get the camera sensor position and orientation

// Get the current display orientation
const QScreen *screen = QGuiApplication::primaryScreen();
const int screenAngle = screen->angleBetween(screen->nativeOrientation(), screen->orientation());

int rotation;
if (cameraInfo.position() == QCamera::BackFace) {
    rotation = (cameraInfo.orientation() - screenAngle) % 360;
} else {
    // Front position, compensate the mirror
    rotation = (360 - cameraInfo.orientation() + screenAngle) % 360;
}

// Rotate the frame so it always shows in the correct orientation
videoFrame = videoFrame.transformed(QTransform().rotate(rotation));

看起来你甚至都不明白你在看什么..。粘贴这样的东西到论坛的目的是什么?你读过关于这个的所有描述了吗?这只是代码的一部分-我看到你不理解,但你试着变得聪明:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27799882

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档