How to get a Frame image from qcamera ?
-
i'm want to grab a frame from QCamera in Android
i have get the frame successfully
but the Object is QVideoFrame
and the pixmap format is BGR32
also,even, the map() function in Android will always return false
so ,i have no idea to convert it to QImage
anyone can help me ?
thx very much -
For THIS specific case, you can convert from QVideoFrame to QImage with:
@
QImage out(videoFrame.size(), QImage::Format_RGB888);quint32 *inp = videoFrame.bits();
quint32 *outp = out.bits();int max = videoFrame.width() * videoFrame.height();
for (int i = 0; i < max; i++) {
int r = (inp[i] >> 8) & 0xff;
int g = (inp[i] >> 16) & 0xff;
int b = (inp[i] >> 24) & 0xff;outp[i] = qRgb(r, g, b);
}
@For other pixel formats you must adapt the code for the specific pixel layout.
-
thank you
i have tried your code
but the videoFrame.bits() function return a NULL value
how to do about this?
[quote author="hipersayan_x" date="1413179030"]For THIS specific case, you can convert from QVideoFrame to QImage with:
@
QImage out(videoFrame.size(), QImage::Format_RGB888);quint32 *inp = videoFrame.bits();
quint32 *outp = out.bits();int max = videoFrame.width() * videoFrame.height();
for (int i = 0; i < max; i++) {
int r = (inp[i] >> 8) & 0xff;
int g = (inp[i] >> 16) & 0xff;
int b = (inp[i] >> 24) & 0xff;outp[i] = qRgb(r, g, b);
}
@For other pixel formats you must adapt the code for the specific pixel layout.
[/quote] -
Ups, a little error, where it says:
@QImage out(videoFrame.size(), QImage::Format_RGB888);@
must be:
@QImage out(videoFrame.size(), QImage::Format_RGB32);@
[quote author="Mr Aloof" date="1413181295"]thank you
i have tried your code
but the videoFrame.bits() function return a NULL value
how to do about this?
[/quote]What is the code you are using for capturing the frames? Does videoFrame.size() returns a valid value?
-
videoFrame.size() is return a correct value
but the videoFrame.bits() return a '0'this is my code
@bool QSGVideoItemSurface::present(const QVideoFrame &frame)
{
if (!frame.isValid()) {
qWarning() << Q_FUNC_INFO << "I'm getting bad frames here...";
return false;
}m_backend->present(frame); QVideoFrame cloneFrame(frame); if(cloneFrame.map(QAbstractVideoBuffer::ReadOnly)); //{ QVideoFrame::PixelFormat v_f=cloneFrame.pixelFormat(); QImage::Format i_f=QVideoFrame::imageFormatFromPixelFormat(v_f); int xx=cloneFrame.mappedBytes(); qDebug()<<"xx "<<xx; QImage img(cloneFrame.bits(), cloneFrame.width(), cloneFrame.height(), cloneFrame.bytesPerLine(), QImage::Format_RGB32); QZXing zxing; QString qr_ct=zxing.decodeImage(img); qDebug()<<"QR : "<<qr_ct<<" "<<cloneFrame.width()<<" "<<cloneFrame.height(); //} //qDebug()<<"frame get here"; return true;
}
@
[quote author="hipersayan_x" date="1413207765"]Ups, a little error, where it says:@QImage out(videoFrame.size(), QImage::Format_RGB888);@
must be:
@QImage out(videoFrame.size(), QImage::Format_RGB32);@
[quote author="Mr Aloof" date="1413181295"]thank you
i have tried your code
but the videoFrame.bits() function return a NULL value
how to do about this?
[/quote]What is the code you are using for capturing the frames? Does videoFrame.size() returns a valid value?
[/quote][quote author="hipersayan_x" date="1413207765"]Ups, a little error, where it says:
@QImage out(videoFrame.size(), QImage::Format_RGB888);@
must be:
@QImage out(videoFrame.size(), QImage::Format_RGB32);@
[quote author="Mr Aloof" date="1413181295"]thank you
i have tried your code
but the videoFrame.bits() function return a NULL value
how to do about this?
[/quote]What is the code you are using for capturing the frames? Does videoFrame.size() returns a valid value?
[/quote] -
-How did you implemented the video surface? Did you specified which format do you want to receive?-
Are you "unmapping":http://qt-project.org/doc/qt-5/qvideoframe.html#unmap the frame after using it?