How to grab video frames directly from QCamera
来源:互联网 发布:军工人工智能概念股300 编辑:程序博客网 时间:2024/05/21 11:45
How to grab video frames directly from QCamera
posted on October 3, 2014 by jacob in Free Software, Programming
I have struggled a lot to simply obtain a continous video stream from QCamera without QtGui as single QImages. After a lot of searching, I finally got to a very short and elegant solution. The Qt documentation is really lacking about this. The obvious (and imo correct) solution would be to use QVideoProbe and connect to the videoFrameProbed signal, but this does only work on a couple of platforms and in very exotic constellations (for example, as of now QCamera only works with with QVideoProbe on Android).
The solution is to subclass QAbstractVideoSurface and override its present-method. This is how it looks like:
#include "cameraframegrabber.h"CameraFrameGrabber::CameraFrameGrabber(QObject *parent) : QAbstractVideoSurface(parent){}QList<QVideoFrame::PixelFormat> CameraFrameGrabber::supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const{ Q_UNUSED(handleType); return QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_ARGB32 << QVideoFrame::Format_ARGB32_Premultiplied << QVideoFrame::Format_RGB32 << QVideoFrame::Format_RGB24 << QVideoFrame::Format_RGB565 << QVideoFrame::Format_RGB555 << QVideoFrame::Format_ARGB8565_Premultiplied << QVideoFrame::Format_BGRA32 << QVideoFrame::Format_BGRA32_Premultiplied << QVideoFrame::Format_BGR32 << QVideoFrame::Format_BGR24 << QVideoFrame::Format_BGR565 << QVideoFrame::Format_BGR555 << QVideoFrame::Format_BGRA5658_Premultiplied << QVideoFrame::Format_AYUV444 << QVideoFrame::Format_AYUV444_Premultiplied << QVideoFrame::Format_YUV444 << QVideoFrame::Format_YUV420P << QVideoFrame::Format_YV12 << QVideoFrame::Format_UYVY << QVideoFrame::Format_YUYV << QVideoFrame::Format_NV12 << QVideoFrame::Format_NV21 << QVideoFrame::Format_IMC1 << QVideoFrame::Format_IMC2 << QVideoFrame::Format_IMC3 << QVideoFrame::Format_IMC4 << QVideoFrame::Format_Y8 << QVideoFrame::Format_Y16 << QVideoFrame::Format_Jpeg << QVideoFrame::Format_CameraRaw << QVideoFrame::Format_AdobeDng;}bool CameraFrameGrabber::present(const QVideoFrame &frame){ if (frame.isValid()) { QVideoFrame cloneFrame(frame); cloneFrame.map(QAbstractVideoBuffer::ReadOnly); const QImage image(cloneFrame.bits(), cloneFrame.width(), cloneFrame.height(), QVideoFrame::imageFormatFromPixelFormat(cloneFrame .pixelFormat())); emit frameAvailable(image); cloneFrame.unmap(); return true; } return false;}
#ifndef CAMERAFRAMEGRABBER_H#define CAMERAFRAMEGRABBER_H// Qt includes#include <QAbstractVideoSurface>#include <QList>class CameraFrameGrabber : public QAbstractVideoSurface{ Q_OBJECTpublic: explicit CameraFrameGrabber(QObject *parent = 0); QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const; bool present(const QVideoFrame &frame);signals: void frameAvailable(QImage frame);public slots:};#endif // CAMERAFRAMEGRABBER_H
This is how you would use it in your Qt application:
_camera = new QCamera();_cameraFrameGrabber = new CameraFrameGrabber();_camera->setViewfinder(_cameraFrameGrabber);connect(_cameraFrameGrabber, SIGNAL(frameAvailable(QImage)), this, SLOT(handleFrame(QImage)));_camera->start();
- How to grab video frames directly from QCamera
- ios学习--How to capture video frames from the camera as images using AV Foundation
- How to capture video frames from the camera as images using AV Foundation
- How to capture video frames from the camera as images using AV Foundation on iOS
- How to compile your own boblight binarys directly from source
- write frames to a video
- How to draw image to screen directly
- How to grab web page in chinese
- How To Grab Someone IP Address ?
- How to identify video formats from command line on Linux
- iPhone Read UIimage (frames) from video with AVFoundation
- 怎样使用java读取网页源码 How To Get URL Content In Java | Reading Directly from a URL
- [Cexpert-004] How to output strings to stdout/stderr directly?
- wiki: How to grab the desktop (screen) with FFmpeg
- A class to grab pictures from your camera
- How to Login Oracle Applications Directly - fndvald.jsp
- How to build mex file directly in Visual Studio 2010?
- How to download streaming audio or video media from the internet using the MMS protocol?
- java数据结构链表,堆栈,队列相关专题分析与扯谈-链表
- Laravel学习笔记(五)---操作数据库--查询构建器(Query Builder)
- 域名解析
- property的默认属性 (2012-01-13 10:39:09)
- cccc L2-018. 多项式A除以B
- How to grab video frames directly from QCamera
- 点击移除样式,再点击新增样式jq代码
- HDU-4849 Wow! Such City!,最短路!
- TensorFlow的异常Reciprocal[T=DT_INT32](Variable_1/read)
- JavaScript算法-排序算法
- java数据结构链表,堆栈,队列相关专题分析与扯谈-堆栈
- zookeeper功能和应用
- RecyclerView加载动画
- java数据结构链表,堆栈,队列等相关专题分析与扯谈-队列