Commit 5ed4a219 authored by Thiago Santini's avatar Thiago Santini

YUV support improvements

parent 22897a30
......@@ -92,11 +92,12 @@ QCameraViewfinderSettings Camera::getViewfinderSettings(const QCameraInfo camera
} else {
// Unknown; recommend to maximize fps and minimize resolution
recommended = camera->viewfinderSettings();
foreach (const QCameraViewfinderSettings &setting, camera->supportedViewfinderSettings()) {
foreach (const QCameraViewfinderSettings &setting, camera->supportedViewfinderSettings()) {
if ( setting.pixelFormat() == QVideoFrame::Format_RGB32
|| setting.pixelFormat() == QVideoFrame::Format_RGB24
|| setting.pixelFormat() == QVideoFrame::Format_YUYV
|| setting.pixelFormat() == QVideoFrame::Format_Jpeg ) {
|| setting.pixelFormat() == QVideoFrame::Format_UYVY
|| setting.pixelFormat() == QVideoFrame::Format_Jpeg ) {
if (recommended.isNull())
recommended = setting;
......
......@@ -3,7 +3,7 @@
using namespace cv;
DataRecorder::DataRecorder(QString id, QString header, QObject *parent)
: id(id),
: id(id.replace("Widget", "").replace(" ", "")),
header(header),
videoWriter(NULL),
dataFile(NULL),
......
......@@ -41,8 +41,8 @@ QList<QVideoFrame::PixelFormat> FrameGrabber::supportedPixelFormats(QAbstractVid
return QList<QVideoFrame::PixelFormat>()
<< QVideoFrame::Format_Jpeg
<< QVideoFrame::Format_RGB32
<< QVideoFrame::Format_YUYV
<< QVideoFrame::Format_RGB24;
<< QVideoFrame::Format_YUYV
<< QVideoFrame::Format_RGB24;
//<< QVideoFrame::Format_ARGB32_Premultiplied
//<< QVideoFrame::Format_RGB565
//<< QVideoFrame::Format_RGB555
......@@ -83,7 +83,7 @@ bool FrameGrabber::present(const QVideoFrame &frame)
* we must copy the data
*
*/
Timestamp t = gTimer.elapsed();
Timestamp t = gTimer.elapsed();
QVariant ft = frame.metaData("timestamp");
if (ft.isValid() ) {
......@@ -102,7 +102,7 @@ bool FrameGrabber::present(const QVideoFrame &frame)
QVideoFrame copy(frame);
Mat cvFrame;
copy.map(QAbstractVideoBuffer::ReadOnly);
copy.map(QAbstractVideoBuffer::ReadOnly);
bool success = false;
switch (frame.pixelFormat()) {
case QVideoFrame::Format_Jpeg:
......@@ -112,10 +112,10 @@ bool FrameGrabber::present(const QVideoFrame &frame)
success = rgb32_2bmp(copy, cvFrame);
break;
case QVideoFrame::Format_YUYV:
success = yuyv_2bmp(copy, cvFrame);
break;
default:
qDebug() << "Unknown pixel format:" << frame.pixelFormat();
success = yuyv_2bmp(copy, cvFrame);
break;
default:
qWarning() << "Unknown pixel format:" << frame.pixelFormat();
break;
}
copy.unmap();
......@@ -196,26 +196,12 @@ bool FrameGrabber::rgb32_2bmp(const QVideoFrame &in, cv::Mat &cvFrame)
bool FrameGrabber::yuyv_2bmp(const QVideoFrame &in, cv::Mat &cvFrame)
{
// TODO: can we optimize this?
cvFrame = Mat(abs(in.height()), abs(in.width()), CV_8UC3);
const unsigned char *pyuv = in.bits();
unsigned char *pbgr = cvFrame.data;
for(int i = 0; i < in.mappedBytes(); i += 4) {
int b = (0x7179 * ((pyuv)[1] - 0x80)) >> 0xE;
int g = (-0x1604 * ((pyuv)[1] - 0x80) - 0x2DB2 * ((pyuv)[3] - 0x80)) >> 0xE;
int r = (0x59CB * ((pyuv)[3] - 0x80)) >> 0xE;
(pbgr)[0] = (*(pyuv) + b);
(pbgr)[1] = (*(pyuv) + g);
(pbgr)[2] = (*(pyuv) + r);
(pbgr)[3] = ((pyuv)[2] + b);
(pbgr)[4] = ((pyuv)[2] + g);
(pbgr)[5] = ((pyuv)[2] + r);
pbgr += 6;
pyuv += 4;
}
if (code != CV_8UC3)
cvtColor(cvFrame, cvFrame, CV_BGR2GRAY);
Mat yuyv = Mat(abs(in.height()), abs(in.width()), CV_8UC2, (void*) in.bits());
if (code == CV_8UC3)
cvtColor(yuyv, cvFrame, CV_YUV2BGR_YUYV);
else
cvtColor(yuyv, cvFrame, CV_YUV2GRAY_YUYV);
return true;
}
//TODO: add support for other frame formats
......@@ -81,9 +81,9 @@ public:
gazeEstimationMethod("POLY_X_Y_XY_XX_YY_XYY_YXX_XXYY"),
visualize(true),
visualizationTimeS(5),
minCentralAreaCoverage(0.8f),
minPeriphericAreaCoverage(0.1f),
maxReprojectionError(4.f)
minCentralAreaCoverage(0.0f),
minPeriphericAreaCoverage(0.0f),
maxReprojectionError(10.0f)
{}
/*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment