QT和OpenCV 显示视频 http://zllxsha.blog.163.com/blog/static/50555091201011892029213/

时间:2022-10-29 00:39:05

【存档】QT和OpenCV 显示视频 (存着) 

2010-12-08 21:20:29|  分类:默认分类 |  标签:|字号订阅

Qt开发的程序一般都要借助qmake生成makefile文件。因此为了加入opencv库就要修改.pro文件,下面是Linux下该文件的配置。(增加的部分)

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/INCLUDEPATH+= . /usr/local/include/opencv
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/LIBS
+= /usr/local/lib/libcv.so \
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/   
    /usr/local/lib/libcvaux.so \
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/   
    /usr/local/lib/libcxcore.so \
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/   
    /usr/local/lib/libhighgui.so \
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/   
    /usr/local/lib/libml.so

Opencv中通过摄像头捕捉到的每帧图像的数据结构是IplImage类型的,要把它显示到Qt窗口中就需要把它转化为QImage类型的图像。
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/#include<QVector>
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/#include
<cstring>
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QImage MyThread::IplImageToQImage(
const IplImage* iplImage,double mini,double maxi)
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/
...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/    uchar
*qImageBuffer= NULL;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/       
int width = iplImage->width;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/
/**//* Note here that OpenCV image is stored so that each lined is
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/32-bits aligned thus
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/* explaining the necessity to "skip" the few last bytes of each
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/line of OpenCV image buffer.
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/
*/

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/       
int widthStep= iplImage->widthStep;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/       
int height = iplImage->height;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/       
switch (iplImage->depth)
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/       
...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
case IPL_DEPTH_8U:
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
if(iplImage->nChannels== 1)
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
/**//* OpenCV image is stored with one byte grey pixel. We convert it
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/            to an 8 bit depth QImage.
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
*/

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/  
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                qImageBuffer
= (uchar *) malloc(width*height*sizeof(uchar));
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                uchar
*QImagePtr = qImageBuffer;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/               
const uchar *iplImagePtr = (const uchar*) iplImage->imageData;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/  
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/               
for(int y= 0; y< height; y++)
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/               
...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                   
// Copy line by line
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/
                        memcpy(QImagePtr, iplImagePtr, width);
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                        QImagePtr
+= width;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                        iplImagePtr
+= widthStep;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                }

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/  
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/            }

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
else if(iplImage->nChannels== 3)
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                   
/**//* OpenCV image is stored with 3 byte color pixels (3 channels).
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                    We convert it to a 32 bit depth QImage.
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                   
*/

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                    qImageBuffer
= (uchar *) malloc(width*height*4*sizeof(uchar));
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                    uchar
*QImagePtr = qImageBuffer;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                   
const uchar *iplImagePtr = (const uchar*) iplImage->imageData;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                   
for(int y= 0; y< height; y++)
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                   
...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                       
for (int x= 0; x< width; x++)
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                       
...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                               
// We cannot help but copy manually.
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/
                                QImagePtr[0]= iplImagePtr[0];
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                                QImagePtr[
1]= iplImagePtr[1];
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                                QImagePtr[
2]= iplImagePtr[2];
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                                QImagePtr[
3]= 0;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/      
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                                QImagePtr
+= 4;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                                iplImagePtr
+= 3;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                        }

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                        iplImagePtr
+= widthStep-3*width;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                    }
   
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/  
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/            }

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
else
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                    qDebug(
"IplImageToQImage: image format is not supported : depth=8U and %d channels ", iplImage->nChannels);
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/            }

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
break;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
case IPL_DEPTH_16U:
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
if(iplImage->nChannels== 1)
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
/**//* OpenCV image is stored with 2 bytes grey pixel. We convert it
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/            to an 8 bit depth QImage.
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
*/

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                    qImageBuffer
= (uchar *) malloc(width*height*sizeof(uchar));
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                    uchar
*QImagePtr = qImageBuffer;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                   
//const uint16_t *iplImagePtr = (const uint16_t *);
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/
           const unsignedint *iplImagePtr= (const unsignedint *)iplImage->imageData;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                   
for (int y= 0; y< height; y++)
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                   
...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                       
for (int x= 0; x< width; x++)
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                       
...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                       
// We take only the highest part of the 16 bit value. It is
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                       
//similar to dividing by 256.
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/
                           *QImagePtr++= ((*iplImagePtr++)>> 8);
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                        }

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                        iplImagePtr
+= widthStep/sizeof(unsignedint)-width;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                    }

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/            }

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
else
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                    qDebug(
"IplImageToQImage: image format is not supported : depth=16U and %d channels ", iplImage->nChannels);
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/  
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/            }

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
break;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
case IPL_DEPTH_32F:
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/            
if(iplImage->nChannels== 1)
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/            
...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
/**//* OpenCV image is stored with float (4 bytes) grey pixel. We
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/            convert it to an 8 bit depth QImage.
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
*/

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                     qImageBuffer
= (uchar *) malloc(width*height*sizeof(uchar));
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                     uchar
*QImagePtr = qImageBuffer;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                    
const float *iplImagePtr= (constfloat *) iplImage->imageData;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                    
for(int y= 0; y< height; y++)
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                    
...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                        
for(int x= 0; x< width; x++)
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                        
...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                                 uchar p;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                                
float pf = 255* ((*iplImagePtr++)- mini) / (maxi - mini);
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                                
if(pf < 0) p= 0;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                                
else if(pf> 255) p= 255;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                                
else p = (uchar) pf;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/  
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                                
*QImagePtr++= p;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                          }

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                         iplImagePtr
+= widthStep/sizeof(float)-width;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                     }

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/             }

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/            
else
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/            
...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                     qDebug(
"IplImageToQImage: image format is not supported : depth=32F and %d channels ", iplImage->nChannels);
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/             }
   
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/              
break;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/              
case IPL_DEPTH_64F:
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/            
if(iplImage->nChannels== 1)
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/            
...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/               
/**//* OpenCV image is stored with double (8 bytes) grey pixel. We
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                convert it to an 8 bit depth QImage.
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/               
*/

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                    qImageBuffer
= (uchar *) malloc(width*height*sizeof(uchar));
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                    uchar
*QImagePtr = qImageBuffer;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                   
const double *iplImagePtr= (constdouble *) iplImage->imageData;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                   
for(int y= 0; y< height; y++)
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                   
...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                       
for(int x= 0; x< width; x++)
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                       
...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                                uchar p;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                               
double pf = 255* ((*iplImagePtr++)- mini) / (maxi - mini);
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/  
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                               
if(pf < 0) p= 0;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                               
else if(pf> 255) p= 255;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                               
else p = (uchar) pf;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/  
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                               
*QImagePtr++= p;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                        }

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                        iplImagePtr
+= widthStep/sizeof(double)-width;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                    }

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/            }

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
else
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                    qDebug(
"IplImageToQImage: image format is not supported : depth=64F and %d channels ", iplImage->nChannels);
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/            }

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
break;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
default:
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                qDebug(
"IplImageToQImage: image format is not supported : depth=%d and %d channels ", iplImage->depth, iplImage->nChannels);
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/        }

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/        QImage qImage;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/        QVector
<QRgb> vcolorTable;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/       
if(iplImage->nChannels== 1)
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/       
...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
// We should check who is going to destroy this allocation.
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/
            QRgb*colorTable= new QRgb[256];
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
for(int i= 0; i< 256; i++)
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/           
...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                   colorTable[i]
= qRgb(i, i, i);
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/                   vcolorTable[i]
= colorTable[i];
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/            }

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/            qImage
= QImage(qImageBuffer, width, height, QImage::Format_Indexed8).copy();
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/            qImage.setColorTable(vcolorTable);
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/        }

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/       
else
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/       
...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/            qImage
= QImage(qImageBuffer, width, height, QImage::Format_RGB32).copy();
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/        }

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/    free(qImageBuffer);
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/   
return qImage;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/}

于是你可以下面的代码(部分)测试一下:摄像头获取每一帧IplImage*类型的图像,转化为QImage类型的图像,用update()发出一个paintEvent(QPaintEvent*)事件,如此不断更新图像。(IplImageToQImage中的mini和maxi默认初始化为0)

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/void ImageViewer::paintEvent(QPaintEvent *)...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/    QPainter painter(
this);
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/    painter.drawImage(QPoint(
0,0),*image);
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/}

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/
bool ImageViewer::ShowImage()...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/    IplImage
*pImage = NULL;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/    CvCapture
*pCapture = NULL;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/   
if((pCapture = cvCaptureFromCAM(-1))== NULL)...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/        cout
<< "Open camera failed!";
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/       
return false;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/    }

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/   
while((pImage= cvQueryFrame(pCapture))!= NULL)...{
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/        image
= IplImageToQImage(pImage);
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/        update();
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/    }

QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/    cvReleaseImage(
&pImage);
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/    cvReleaseCapture(
&pCapture);
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/   
return true;
QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/}
评论 http://zllxsha.blog.163.com/blog/static/50555091201011892029213/QT和OpenCV 显示视频  http://zllxsha.blog.163.com/blog/static/50555091201011892029213/换一张上一页1...-1-1-1-1-1-1-1...-1下一页