基于QT的视频采集

-
基于qt的视频采集,主要是将服务端的设备虚拟化,供客户端调用。使用TCP/IP协议传输,使用V4L2实现视频采集。
3KB
基于qt的视频采集与显示
2013-02-19基于qt的视频采集与显示,通过对v4l2编程可以很好的掌握怎样来控制视频
qt视频采集传输?_course
2010-10-22各位高手,我想做在VC++6.0下的用VFW技术的视频采集传输(h.263编码解码),请问有源代码或相关参考吗?
如何用QT把采集到的视频显示出来? _course
2019-09-19谢谢各位最近在做摄像头的图像采集。图像采集后不知道怎么用QT显示出来。
在arm上利用Qt采集视频图像,能够保存采集的视频图像_course
2019-08-16我使用的是usb免驱摄像头,现在已经实现实时显示图像,并能够拍照保存,但无法实现保存视频。 以下是本程序的相关代码 # main.cpp ``` #include "camera.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); camera w; w.show(); return a.exec(); } ``` # camera.cpp ``` #include "camera.h" #include "ui_camera.h" #include <QDate> #include <QTime> void yuv422to420p(char *yuv422buf, char *yuv420pbuf, int width, int height) { char *src, *dest, *dest2; int i, j; src = yuv422buf; dest = yuv420pbuf; for (i = 0; i < width * height * 2; i++) { if (i % 2 != 0) { continue; } *dest++ = *(src + i); } src = yuv422buf; dest = yuv420pbuf + width * height; dest2 = dest + (width * height) / 4; for (i = 0; i < height; i += 2) { for (j = 1; j < width * 2; j += 4) { *dest++ = *(src + i * width * 2 + j); *dest2++ = *(src + i * width * 2 + j + 2); } } } /* yuv格式转换为rgb格式的算法处理函数 */ int convert_yuv_to_rgb_pixel(int y, int u, int v) { unsigned int pixel32 = 0; unsigned char *pixel = (unsigned char *)&pixel32; int r, g, b; r = y + (1.370705 * (v-128)); g = y - (0.698001 * (v-128)) - (0.337633 * (u-128)); b = y + (1.732446 * (u-128)); if(r > 255) r = 255; if(g > 255) g = 255; if(b > 255) b = 255; if(r < 0) r = 0; if(g < 0) g = 0; if(b < 0) b = 0; pixel[0] = r ; pixel[1] = g ; pixel[2] = b ; return pixel32; } /* yuv格式转换为rgb格式 */ int convert_yuv_to_rgb_buffer(unsigned char *yuv, unsigned char *rgb, unsigned int width, unsigned int height) { unsigned int in, out = 0; unsigned int pixel_16; unsigned char pixel_24[3]; unsigned int pixel32; int y0, u, y1, v; for(in = 0; in < width * height * 2; in += 4) { pixel_16 = yuv[in + 3] << 24 | yuv[in + 2] << 16 | yuv[in + 1] << 8 | yuv[in + 0]; y0 = (pixel_16 & 0x000000ff); u = (pixel_16 & 0x0000ff00) >> 8; y1 = (pixel_16 & 0x00ff0000) >> 16; v = (pixel_16 & 0xff000000) >> 24; pixel32 = convert_yuv_to_rgb_pixel(y0, u, v); pixel_24[0] = (pixel32 & 0x000000ff); pixel_24[1] = (pixel32 & 0x0000ff00) >> 8; pixel_24[2] = (pixel32 & 0x00ff0000) >> 16; rgb[out++] = pixel_24[0]; rgb[out++] = pixel_24[1]; rgb[out++] = pixel_24[2]; pixel32 = convert_yuv_to_rgb_pixel(y1, u, v); pixel_24[0] = (pixel32 & 0x000000ff); pixel_24[1] = (pixel32 & 0x0000ff00) >> 8; pixel_24[2] = (pixel32 & 0x00ff0000) >> 16; rgb[out++] = pixel_24[0]; rgb[out++] = pixel_24[1]; rgb[out++] = pixel_24[2]; } return 0; } int camera::camera_init() { int ret=0,i=0,count=0; struct v4l2_capability cap; //视频设备的功能,对应命令VIDIOC_QUERYCAP struct v4l2_fmtdesc fmtdesc; //视频格式描述符类型 struct v4l2_format format; //帧的格式,如宽度,高度等,对应命令VIDIOC_G_FMT、VIDIOC_S_FMT等 struct v4l2_requestbuffers reqbuf; //向驱动申请帧缓冲请求,包含申请的个数,对应命令VIDIOC_REQBUFS struct v4l2_buffer buf; //驱动中的一帧图像缓存,对应命令VIDIOC_QUERYBUF fmtdesc.index = 0; fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; //传输流类型 ret = ::ioctl(fd, VIDIOC_G_FMT, &format); //'VIDIOC_G_FMT'——读取当前驱动的视频捕获格式 if(ret < 0){ perror("VIDIOC_G_FMT"); exit(1); } printf("width:%d\n", format.fmt.pix.width); printf("height:%d\n", format.fmt.pix.height); printf("pixelformat:%x\n", format.fmt.pix.pixelformat); printf("field:%x\n", format.fmt.pix.field); printf("bytesperline:%d\n", format.fmt.pix.bytesperline); printf("sizeimage:%d\n", format.fmt.pix.sizeimage); printf("colorspace:%d\n", format.fmt.pix.colorspace); format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; format.fmt.pix.width = 640; format.fmt.pix.height = 480; format.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; ret = ::ioctl(fd, VIDIOC_S_FMT, &format); if(ret < 0){ fprintf(stderr, "Not support jepg"); perror("VIDIOC_S_FMT"); exit(1); } reqbuf.count = 3; reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; reqbuf.memory = V4L2_MEMORY_MMAP; ret = ::ioctl(fd, VIDIOC_REQBUFS, &reqbuf); if(ret < 0){ perror("VIDIOC_REQBUFS"); exit(1); } bufinf = (struct bufinfor *)calloc(reqbuf.count, sizeof(struct bufinfor)); if(!bufinf){ perror("calloc"); exit(1); } for(count = 0; count < reqbuf.count; count++){ buf.index = count; buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; ret = ::ioctl(fd, VIDIOC_QUERYBUF, &buf); if(ret < 0){ perror("VIDIOC_REQBUFS"); exit(1); } bufinf[buf.index].length = buf.length; bufinf[buf.index].start = mmap(NULL, buf.length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, buf.m.offset); if(!(bufinf[buf.index].start)){ perror("mmap"); exit(1); } } for(i = 0; i < reqbuf.count; i++){ buf.index = i; buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; ret = ::ioctl(fd, VIDIOC_QBUF, &buf); if(ret < 0){ perror("VIDIOC_QBUF"); exit(1); } } enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; ret = ::ioctl(fd, VIDIOC_STREAMON, &type); if(ret < 0){ perror("VIDIOC_STREAMON"); exit(1); } return 0; } camera::camera(QWidget *parent) : QMainWindow(parent), ui(new Ui::camera) { char devname[32]; int i=0; int ret; struct v4l2_capability cap; ui->setupUi(this); while(i < 100) { sprintf(devname,"/dev/video%d",i++); fd = ::open(devname,O_RDWR); if(fd < 0) { continue; } ui->comboBox->addItem(QWidget::tr(devname)); ::close(fd); } } camera::~camera() { free(bufinf); ::close(fd); delete ui; } void camera::moveEvent(QMoveEvent *) { this->move(QPoint(0,0)); } void camera::resizeEvent(QResizeEvent *) { this->showMaximized(); } void camera::on_pushButton_2_clicked() { take_photo(); } static bool take = 0; void camera::show_() { int ret; unsigned char *rgb=new unsigned char [640 * 480 *3]; struct v4l2_buffer buf; fd_set readset; FD_ZERO(&readset); FD_SET(fd, &readset); ret = select(fd + 1, &readset, NULL, NULL, NULL); if(ret < 0){ perror("select"); exit(1); } buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; ret = ioctl(fd, VIDIOC_DQBUF, &buf); if(ret < 0){ perror("VIDIOC_DQBUF"); exit(1); } convert_yuv_to_rgb_buffer((unsigned char *)bufinf[buf.index].start,rgb,640,480); ret = ioctl(fd, VIDIOC_QBUF, &buf); if(ret < 0){ perror("VIDIOC_QBUF"); exit(1); } QImage *mage = new QImage(rgb,640,480,QImage::Format_RGB888); if (take == 1) { mage->save(tr("%1.jpg").arg("/mnt/Photo/Photo_2019.04.15/IMG" + QDate::currentDate().toString("yyyyMMdd") + QTime::currentTime().toString("hhmmss")),"JPG"); // mage->save(tr("%1.jpg").arg("/home/root/Photo/IMG" + QDate::currentDate().toString("yyyyMMdd") + QTime::currentTime().toString("hhmmss")),"JPG"); take = 0; } QImage resultimg=mage->scaled(ui->label->size(),Qt::KeepAspectRatio,Qt::SmoothTransformation); ui->label->setPixmap(QPixmap::fromImage(resultimg)); delete mage; delete rgb; } void camera::take_photo() { take = 1; } void camera::on_comboBox_activated(const QString &arg1) { QString text=ui->comboBox->currentText(); QByteArray devtext=text.toLatin1(); char *devname=devtext.data(); int ret; struct v4l2_capability cap; fd = ::open(devname, O_RDWR); if(fd < 0) { perror("open error"); } camera::camera_init(); QTimer *timer; timer=new QTimer(); timer->setInterval(10); connect(timer,SIGNAL(timeout()),this,SLOT(show_())); timer->start(10); camera_flag=1; } void camera::on_pushButton_clicked() { close(); } ``` # camera.h ``` #ifndef CAMERA_H #define CAMERA_H #include <QMainWindow> #include <QTimer> #include <QImage> #include <QPixmap> #include <QDebug> #include <QStringList> #include <QByteArray> #include <QComboBox> extern "C"{ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/mman.h> #include <sys/types.h> #include <fcntl.h> #include <sys/ioctl.h> #include <string.h> #include <time.h> #include <sys/select.h> #include <sys/time.h> #include <sys/types.h> #include <unistd.h> #include <jpeglib.h> #include <linux/videodev2.h> } namespace Ui { class camera; } struct bufinfor{ void *start; unsigned int length; }; class camera : public QMainWindow { Q_OBJECT public: explicit camera(QWidget *parent = 0); ~camera(); protected: void moveEvent(QMoveEvent *); void resizeEvent(QResizeEvent *); private slots: int camera_init(void); void on_pushButton_2_clicked(); void show_(); void take_photo(); void on_comboBox_activated(const QString &arg1); void on_pushButton_clicked(); private: Ui::camera *ui; int fd; int camera_flag; struct bufinfor *bufinf; }; #endif // CAMERA_H ``` usbcamera.pro ``` #------------------------------------------------- # # Project created by QtCreator 2019-08-02T09:08:26 # #------------------------------------------------- QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = usbcamera TEMPLATE = app LIBS += -L. -ljpeg SOURCES += main.cpp\ camera.cpp HEADERS += camera.h FORMS += camera.ui ``` 程序界面如下   求助大神该怎么保存拍摄的视频 非常感谢
34KB
QT视频采集例子
2011-11-09用QT写的基于v4l的视频采集代码,包括YUV转BMP格式代码
2.19MB
qt视频采集(windows+linux2.4)
2013-02-26代码可以在windows下和linux下采集摄像头视频并显示,功能简单,主要可以学习采集显示步骤。特别说明,使用的是v4l不是v4l2
linux下使用Qt进行视频采集与录制问题_course
2011-09-29最近在做linux下的视频采集项目,使用Qt来开发 目前已成功调用v4l2采集到了摄像头捕获的图像,但摄像头支持的视频格式是YUYV的,采集到的图像不能直接保存为jpg格式的图片。 现在想把采集到的图
38KB
QT视频采集程序
2014-08-29非常流畅的Qt视频采集,本地显示程序。切移植后依然流畅。
317KB
QT中采用RTP采集和传输视频
2016-07-06QT下RTP开发的实例,供大家参考学习
388KB
基于QT的QCamera实现摄像头视频采集并显示
2019-08-01基于QT自带的QCamera实现摄像头视频采集,并实现摄像头图像的刷新显示。
21KB
基于qt的多线程视频采集与传输
2012-10-08将服务端的设备虚拟化,供客户端调用。使用TCP/IP协议传输,使用V4L2实现视频采集。
3.63MB
qt+opencv的视频采集 与保存
2017-05-07使用qt最为主线程的显示框架,在子线程中使用opencv进行图像采集和图像的保存
做一个v4l2+qt视频采集系统,实现远程监控,具体步骤该怎么去做_course
2016-06-14最近需要做一个课设,就是用v4l2+qt做一个视频采集系统,可以实现远程监控的。 我安装了oracle vitual box以及centos7 只是对v4l2和qt有了一个基础的了解,但是还是不知道如何下手去做,请做过类似任务的大神给提提意见跟一些想法! csdn里好多大神给的v4l2视频采集的代码之类的,现在的问题就是这些代码放到哪儿?是用qt creator创建工程,然后将代码添进去吗?
-
学院
python数据分析基础
python数据分析基础
-
下载
webots_ros2.zip
webots_ros2.zip
-
博客
2021-01-21
2021-01-21
-
学院
ProBuilder快速原型开发技术
ProBuilder快速原型开发技术
-
下载
基于 C# 的 GIS 近海环境管理系统
基于 C# 的 GIS 近海环境管理系统
-
下载
考研-2009-2021年计算机408真题及答案 资料整理不易
考研-2009-2021年计算机408真题及答案 资料整理不易
-
学院
Unity游戏开发之数字华容道
Unity游戏开发之数字华容道
-
博客
Java 递归实现迷宫回溯问题
Java 递归实现迷宫回溯问题
-
学院
第3章 入门程序、常量、变量
第3章 入门程序、常量、变量
-
学院
Excel高级图表技巧
Excel高级图表技巧
-
学院
阿里云云计算ACP考试必备教程
阿里云云计算ACP考试必备教程
-
学院
转行做IT-第6章 IDEA、方法
转行做IT-第6章 IDEA、方法
-
下载
321同济大学数学系《工程数学—线性代数》(第6版)笔记和课后习题(含考研真题)详解.pdf
321同济大学数学系《工程数学—线性代数》(第6版)笔记和课后习题(含考研真题)详解.pdf
-
下载
cuda10.0和cudnn10.0
cuda10.0和cudnn10.0
-
博客
项目第三天
项目第三天
-
博客
soul源码学习(六)-websocket数据同步
soul源码学习(六)-websocket数据同步
-
下载
matlab产生正弦波及.mif文件的程序-其它文档类资源
matlab产生正弦波及.mif文件的程序-其它文档类资源
-
博客
浅谈踢人下线的设计思路!(附代码实现方案)
浅谈踢人下线的设计思路!(附代码实现方案)
-
学院
【数据分析-随到随学】量化交易策略模型
【数据分析-随到随学】量化交易策略模型
-
博客
HUD1513.
HUD1513.
-
学院
Java星选一卡通
Java星选一卡通
-
博客
java第六章-for循环
java第六章-for循环
-
博客
Cortex-M3处理器位操作技术——“位带”
Cortex-M3处理器位操作技术——“位带”
-
博客
iOS 中的堆与栈
iOS 中的堆与栈
-
学院
【数据分析-随到随学】机器学习模型及应用
【数据分析-随到随学】机器学习模型及应用
-
下载
在指定的窗口输入文本-要加载精易模块.e
在指定的窗口输入文本-要加载精易模块.e
-
学院
Kotlin协程极简入门与解密
Kotlin协程极简入门与解密
-
博客
2021-01-21
2021-01-21
-
博客
ArrayList实现类
ArrayList实现类
-
学院
前端架构师-速成
前端架构师-速成