我正在写一个程序,用来显示两个相邻的摄像头。在Qt中,使用QCamera非常简单。但是我的相机转了90度,所以我也得把相机转到这张图上。
QCamera变量没有命令来旋转它,所以我想在标签中显示它,而不是在取景器中。所以我拿了一张图片,将它翻转并显示在标签中。
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_);当我启动程序时,只有两个相邻的黑盒。(在代码中,我删除了它的部分,但相机在取景器中工作正常,所以我认为没有问题)
发布于 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拍摄快照)
发布于 2015-11-17 20:38:34
您可以使用相机的方向来校正取景器中的图像方向,如Qt文档中所述。链接如下:
http://doc.qt.io/qt-5/cameraoverview.html
下面是文档中的代码:
// 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));看起来你甚至都不明白你在看什么..。粘贴这样的东西到论坛的目的是什么?你读过关于这个的所有描述了吗?这只是代码的一部分-我看到你不理解,但你试着变得聪明:)
https://stackoverflow.com/questions/27799882
复制相似问题