在QT中读取视频,进行格式转换。IplImage->Mat->QImage->QPixmap

时间:2020-12-20 23:11:37

  1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
      
      
      
QPixmap* pixmap;
IplImage *imageVideo;
Mat image;
QImage img;
CvCapture* capture = cvCaptureFromeFIle("E:/home.MP4");
FrameRate = (int)cvGetCaptureProprety(capture,CV_CAP_PROP_FPS);//帧率
TotalFrame = (int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_COUNT);//帧数
QString num = QString::num(totalFrame);//显示出帧数
ui->lineEdit->setTex(num);
int imgH = (int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT);
int imgW = (int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH);
pixmap = new QPixmap(imgW,imgH);
cvSetCaptureProperty(capture,CV_CAP_PROP_POS_FRAMES,100);//第100帧开始读取
imageVideo = cvQueryFrame(capture);
image = Mat(imageVideo);
cvtColor(image,image,CV_BGR2RGB);
img = QImage((const unsigned char*)image.data,image.cols,image.rows,
QImage::Format_RGB88);
*pixmap = QPixmap::fromImage(img);

ui->label->setPixmap(*pixmap);