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 ...@@ -92,11 +92,12 @@ QCameraViewfinderSettings Camera::getViewfinderSettings(const QCameraInfo camera
} else { } else {
// Unknown; recommend to maximize fps and minimize resolution // Unknown; recommend to maximize fps and minimize resolution
recommended = camera->viewfinderSettings(); recommended = camera->viewfinderSettings();
foreach (const QCameraViewfinderSettings &setting, camera->supportedViewfinderSettings()) { foreach (const QCameraViewfinderSettings &setting, camera->supportedViewfinderSettings()) {
if ( setting.pixelFormat() == QVideoFrame::Format_RGB32 if ( setting.pixelFormat() == QVideoFrame::Format_RGB32
|| setting.pixelFormat() == QVideoFrame::Format_RGB24 || setting.pixelFormat() == QVideoFrame::Format_RGB24
|| setting.pixelFormat() == QVideoFrame::Format_YUYV || setting.pixelFormat() == QVideoFrame::Format_YUYV
|| setting.pixelFormat() == QVideoFrame::Format_Jpeg ) { || setting.pixelFormat() == QVideoFrame::Format_UYVY
|| setting.pixelFormat() == QVideoFrame::Format_Jpeg ) {
if (recommended.isNull()) if (recommended.isNull())
recommended = setting; recommended = setting;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
using namespace cv; using namespace cv;
DataRecorder::DataRecorder(QString id, QString header, QObject *parent) DataRecorder::DataRecorder(QString id, QString header, QObject *parent)
: id(id), : id(id.replace("Widget", "").replace(" ", "")),
header(header), header(header),
videoWriter(NULL), videoWriter(NULL),
dataFile(NULL), dataFile(NULL),
......
...@@ -41,8 +41,8 @@ QList<QVideoFrame::PixelFormat> FrameGrabber::supportedPixelFormats(QAbstractVid ...@@ -41,8 +41,8 @@ QList<QVideoFrame::PixelFormat> FrameGrabber::supportedPixelFormats(QAbstractVid
return QList<QVideoFrame::PixelFormat>() return QList<QVideoFrame::PixelFormat>()
<< QVideoFrame::Format_Jpeg << QVideoFrame::Format_Jpeg
<< QVideoFrame::Format_RGB32 << QVideoFrame::Format_RGB32
<< QVideoFrame::Format_YUYV << QVideoFrame::Format_YUYV
<< QVideoFrame::Format_RGB24; << QVideoFrame::Format_RGB24;
//<< QVideoFrame::Format_ARGB32_Premultiplied //<< QVideoFrame::Format_ARGB32_Premultiplied
//<< QVideoFrame::Format_RGB565 //<< QVideoFrame::Format_RGB565
//<< QVideoFrame::Format_RGB555 //<< QVideoFrame::Format_RGB555
...@@ -83,7 +83,7 @@ bool FrameGrabber::present(const QVideoFrame &frame) ...@@ -83,7 +83,7 @@ bool FrameGrabber::present(const QVideoFrame &frame)
* we must copy the data * we must copy the data
* *
*/ */
Timestamp t = gTimer.elapsed(); Timestamp t = gTimer.elapsed();
QVariant ft = frame.metaData("timestamp"); QVariant ft = frame.metaData("timestamp");
if (ft.isValid() ) { if (ft.isValid() ) {
...@@ -102,7 +102,7 @@ bool FrameGrabber::present(const QVideoFrame &frame) ...@@ -102,7 +102,7 @@ bool FrameGrabber::present(const QVideoFrame &frame)
QVideoFrame copy(frame); QVideoFrame copy(frame);
Mat cvFrame; Mat cvFrame;
copy.map(QAbstractVideoBuffer::ReadOnly); copy.map(QAbstractVideoBuffer::ReadOnly);
bool success = false; bool success = false;
switch (frame.pixelFormat()) { switch (frame.pixelFormat()) {
case QVideoFrame::Format_Jpeg: case QVideoFrame::Format_Jpeg:
...@@ -112,10 +112,10 @@ bool FrameGrabber::present(const QVideoFrame &frame) ...@@ -112,10 +112,10 @@ bool FrameGrabber::present(const QVideoFrame &frame)
success = rgb32_2bmp(copy, cvFrame); success = rgb32_2bmp(copy, cvFrame);
break; break;
case QVideoFrame::Format_YUYV: case QVideoFrame::Format_YUYV:
success = yuyv_2bmp(copy, cvFrame); success = yuyv_2bmp(copy, cvFrame);
break; break;
default: default:
qDebug() << "Unknown pixel format:" << frame.pixelFormat(); qWarning() << "Unknown pixel format:" << frame.pixelFormat();
break; break;
} }
copy.unmap(); copy.unmap();
...@@ -196,26 +196,12 @@ bool FrameGrabber::rgb32_2bmp(const QVideoFrame &in, cv::Mat &cvFrame) ...@@ -196,26 +196,12 @@ bool FrameGrabber::rgb32_2bmp(const QVideoFrame &in, cv::Mat &cvFrame)
bool FrameGrabber::yuyv_2bmp(const QVideoFrame &in, cv::Mat &cvFrame) bool FrameGrabber::yuyv_2bmp(const QVideoFrame &in, cv::Mat &cvFrame)
{ {
// TODO: can we optimize this? Mat yuyv = Mat(abs(in.height()), abs(in.width()), CV_8UC2, (void*) in.bits());
cvFrame = Mat(abs(in.height()), abs(in.width()), CV_8UC3); if (code == CV_8UC3)
const unsigned char *pyuv = in.bits(); cvtColor(yuyv, cvFrame, CV_YUV2BGR_YUYV);
unsigned char *pbgr = cvFrame.data; else
for(int i = 0; i < in.mappedBytes(); i += 4) { cvtColor(yuyv, cvFrame, CV_YUV2GRAY_YUYV);
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);
return true; return true;
} }
//TODO: add support for other frame formats //TODO: add support for other frame formats
...@@ -81,9 +81,9 @@ public: ...@@ -81,9 +81,9 @@ public:
gazeEstimationMethod("POLY_X_Y_XY_XX_YY_XYY_YXX_XXYY"), gazeEstimationMethod("POLY_X_Y_XY_XX_YY_XYY_YXX_XXYY"),
visualize(true), visualize(true),
visualizationTimeS(5), visualizationTimeS(5),
minCentralAreaCoverage(0.8f), minCentralAreaCoverage(0.0f),
minPeriphericAreaCoverage(0.1f), minPeriphericAreaCoverage(0.0f),
maxReprojectionError(4.f) 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