Opencv中取得的视频数据流IplImage转为BMP

在opencv中文网站上使用的开源库取得的视频数据流是指向IplImage结构的指针,试了几USB摄像头取下来的数据都是24b的,所以转为BMP图片直接简单的方法

代码如下:

typedef struct VideoDataDibStruct
{
 DWORD height;
 DWORD width;
 DWORD lineBytes;
 DWORD lineBytes24;
 DWORD totalSize;
 BYTE pData[1024*225];

}VIDEODATADIB;

bool IplImage2Bmp(IplImage *img, VIDEODATADIB *bmpData)
{
 DWORD height = img->height;
 DWORD width = img->width;
 DWORD lineBytes = (width*8+31)/32*4;
 DWORD lineBytes24 = (width*24+31)/32*4;

 bmpData->height = height;
 bmpData->width = width;
 bmpData->lineBytes = lineBytes;
 bmpData->lineBytes24 = lineBytes24;
 bmpData->totalSize = height*lineBytes24;

 WORD bitCount;
 if(img->nChannels == 1)
 {
  bitCount = 8;
 }
 else if(img->nChannels == 3)
 {
  bitCount = 24;
 }
 else
 {
  return false;
 }

 if(bitCount==8)
 {
  

你可能感兴趣的:(C/C++/C#)