OpenCV 播放视频的QT 代码
2013-04-28 22:23
435 查看
http://mobile.51cto.com/symbian-271265.htm/article/1390619.html
// myWidget.h #ifndef MYWIDGET_H #define MYWIDGET_H #include <QtGui\QWidget> #include <QtGui\QPaintEvent> #include <QtGui\QImage> #include <QtCore\QTimer> #include <cv.h> #include <highgui.h> class myWidget : public QWidget { Q_OBJECT public: myWidget(const char *filename,QWidget *parent = 0); ~myWidget(); protected: void paintEvent(QPaintEvent *e); private slots: void nextFrame(); private: CvCapture *capture; IplImage *iplImg; IplImage *frame; QImage *qImg; QTimer *timer; }; #endif
// myWidget.cpp #include "myWidget.h" #include <QtGui\QPainter> #include <QtCore\QPoint> myWidget::myWidget(const char *filename,QWidget *parent /* = 0 */) : QWidget(parent) { capture = cvCaptureFromFile(filename); if (capture) { frame = cvQueryFrame(capture); if (frame) this->resize(frame->width,frame->height); qImg = new QImage(QSize(frame->width,frame->height), QImage::Format_RGB888); iplImg = cvCreateImageHeader(cvSize(frame->width,frame->height), 8,3); iplImg->imageData = (char*)qImg->bits(); timer = new QTimer(this); timer->setInterval(30); connect(timer,SIGNAL(timeout()),this,SLOT(nextFrame())); timer->start(); } } myWidget::~myWidget() { cvReleaseImage(&iplImg); cvReleaseCapture(&capture); delete qImg; delete timer; } void myWidget::paintEvent(QPaintEvent *e) { QPainter painter(this); painter.drawImage(QPoint(0,0),*qImg); } void myWidget::nextFrame() { frame = cvQueryFrame(capture); if (frame) { if (frame->origin == IPL_ORIGIN_TL) { cvCopy(frame,iplImg,0); } else { cvFlip(frame,iplImg,0); } cvCvtColor(iplImg,iplImg,CV_BGR2RGB); this->update(); } }主函数里面调用
int main(int argc,char* argv[]) { QApplication app(argc,argv); char *filename = "test.avi"; myWidget *mw = new myWidget(filename); mw->show(); int re = app.exec(); return re; }
相关文章推荐
- QT5+opencv3.1实现视频播放加实时直方图
- OpenCV Trackbar 实现播放视频代码遇到的问题 cvQueryFrame cvCreateFileCapture cvCreateTrackbar cvSetTrackbarPos
- 使用Qt示例代码实现的视频播放。VS项目
- QT 框架中快速应用OpenCV 基于视频播放
- opencv+QT 视频播放+滚动条
- QT 框架中快速应用OpenCV 基于视频播放
- QT框架中快速应用OpenCV——基于视频播放
- 4412 ARM+OpenCV +QT播放视频
- OpenCV 播放视频的QT
- v4l2采集视频,opencv处理帧数据第一难关:qt的QImage转换为opencv的IplImage 函数代码实现
- Qt环境下利用opencv逐帧播放视频
- QT+ffmpeg 简单视频播放代码及问题记录
- QT OpenCV 播放视频
- opencv x64 vs2010 下打开摄像头录制视频写成avi(代码为转载)
- 各大网站视频自动播放代码(优酷、搜狐、酷6、土豆等)
- OpenCV索引方式播放视频文件
- OpenCV笔记(1)载入图像 视频播放 读取摄像头
- asp.net各种类型视频播放代码(全)
- Qt 调用phonon 在xp下不能播放视频的解决方法(Phonon::createPath: Cannot connect Phonon::MediaObject ( no objectName )...)
- Opencv第二个程序之-------带滚动条AVI视频播放