2014-07-07 00:19:45 +08:00
|
|
|
/*
|
|
|
|
Copyright (C) 2014 by Project Tox <https://tox.im>
|
|
|
|
|
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
|
|
|
This program is libre software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the COPYING file for more details.
|
|
|
|
*/
|
|
|
|
|
2014-06-29 04:24:26 +08:00
|
|
|
#include "selfcamview.h"
|
|
|
|
#include <QActionGroup>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QCloseEvent>
|
|
|
|
#include <QShowEvent>
|
2014-06-30 05:41:47 +08:00
|
|
|
#include <QVideoFrame>
|
2014-06-29 04:24:26 +08:00
|
|
|
|
2014-06-30 05:41:47 +08:00
|
|
|
#include "videosurface.h"
|
|
|
|
#include "widget.h"
|
|
|
|
|
2014-08-29 19:40:37 +08:00
|
|
|
using namespace cv;
|
|
|
|
|
2014-06-30 05:41:47 +08:00
|
|
|
SelfCamView::SelfCamView(Camera* Cam, QWidget* parent)
|
|
|
|
: QWidget(parent), displayLabel{new QLabel},
|
|
|
|
mainLayout{new QHBoxLayout()}, cam(Cam)
|
2014-06-29 04:24:26 +08:00
|
|
|
{
|
|
|
|
setLayout(mainLayout);
|
2014-07-04 04:11:26 +08:00
|
|
|
setWindowTitle(SelfCamView::tr("Tox video test","Title of the window to test the video/webcam"));
|
2014-06-29 04:24:26 +08:00
|
|
|
setMinimumSize(320,240);
|
|
|
|
|
2014-06-30 20:49:42 +08:00
|
|
|
updateDisplayTimer.setInterval(5);
|
2014-06-30 05:41:47 +08:00
|
|
|
updateDisplayTimer.setSingleShot(false);
|
2014-06-29 04:24:26 +08:00
|
|
|
|
2014-06-30 05:41:47 +08:00
|
|
|
displayLabel->setScaledContents(true);
|
2014-06-29 04:24:26 +08:00
|
|
|
|
2014-06-30 05:41:47 +08:00
|
|
|
mainLayout->addWidget(displayLabel);
|
2014-06-29 04:24:26 +08:00
|
|
|
|
2014-06-30 05:41:47 +08:00
|
|
|
connect(&updateDisplayTimer, SIGNAL(timeout()), this, SLOT(updateDisplay()));
|
2014-06-29 04:24:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SelfCamView::~SelfCamView()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelfCamView::closeEvent(QCloseEvent* event)
|
|
|
|
{
|
2014-06-30 05:41:47 +08:00
|
|
|
cam->unsuscribe();
|
|
|
|
updateDisplayTimer.stop();
|
2014-06-29 04:24:26 +08:00
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelfCamView::showEvent(QShowEvent* event)
|
|
|
|
{
|
2014-06-30 05:41:47 +08:00
|
|
|
cam->suscribe();
|
|
|
|
updateDisplayTimer.start();
|
2014-06-29 04:24:26 +08:00
|
|
|
event->accept();
|
|
|
|
}
|
2014-06-30 05:41:47 +08:00
|
|
|
|
2014-08-29 19:40:37 +08:00
|
|
|
QImage Mat2QImage(const cv::Mat3b &src) {
|
|
|
|
QImage dest(src.cols, src.rows, QImage::Format_ARGB32);
|
|
|
|
for (int y = 0; y < src.rows; ++y) {
|
|
|
|
const cv::Vec3b *srcrow = src[y];
|
|
|
|
QRgb *destrow = (QRgb*)dest.scanLine(y);
|
|
|
|
for (int x = 0; x < src.cols; ++x) {
|
|
|
|
destrow[x] = qRgba(srcrow[x][2], srcrow[x][1], srcrow[x][0], 255);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
2014-06-30 05:41:47 +08:00
|
|
|
void SelfCamView::updateDisplay()
|
|
|
|
{
|
2014-08-29 19:40:37 +08:00
|
|
|
Mat frame = cam->getLastFrame();
|
|
|
|
|
|
|
|
displayLabel->setPixmap(QPixmap::fromImage(Mat2QImage(frame)));
|
2014-06-30 05:41:47 +08:00
|
|
|
}
|
|
|
|
|