将IplImage转换为位图的错误头文件



我是OpenCV的新手,目前正在使用Windows窗体应用程序(Visual c++ 2008)显示图像。教程指导我独立制作头文件(称为cvToBitmap.h),然后将其应用于项目中头文件的stdafx.h。头文件的功能是将IplImage格式的图像转换为位图格式。但是,当我编译程序时,在头程序中出现了50个程序错误。

下面是cvToBitmap.h源程序

#ifndef _CVTOBITMAP_H_
#define _CVTOBITMAP_H_
static void FillBitmapInfo (BITMAPINFO* bmi, int 
    width, int height, int bpp, int origin)
{
    assert ((bmi&&width>=0)&&(height>=0)&&((bpp==8)
        ||(bpp==24)||(bpp==32)));
    BITMAPINFOHEADER* bmih=&(bmi->bmiHeader);
    memset(bmih,0,sizeof(*bmih));
    bmih->biSize=sizeof(BITMAPINFOHEADER);
    bmih->biWidth=width;
    bmih->biHeight=origin?abs(height):-abs(height);
    bmih->biPlanes=1;
    bmih->biBitCount=(unsigned short)bpp;
    bmih->biCompression=BI_RGB;
    if(bpp==8){
        RGBQUAD* palatte = bmi->bmiColors;
        for(int i=0;i<256;i++){
            palette[i].rgbBlue=palette[i].rgbGreen=palette[i].rgbRed=(BYTE)i;
            palette[i].rgbReserved=0;
        }
    }
}
System::Drawing::Bitmap^ IplImageToBitmap(IplImage* src){
    SIZE size = (0,0);
    int channels=0;
    void* dst_ptr=0;
    const int channels0=3;
    int origin=0;
    CvMat stub,dst,*image;
    bool changed_size=false;
    HDC hdc=CreateCompatibleDC(0);
    if(CV_IS_IMAGE_HDR(src))
        origin=src->origin;
    image=cvGetMat(src,&stub);
    uchar buffer(sizeof(BITMAPINFO*)buffer;
    size.cx=src->width;
    size.cy=src->height;
    channels=channels0;
    FillBitmapInfo(binfo,size.cx,size.cy,channels*8,1);
    HBITMAP hBitmap=reateDIBSection(hdc, binfo,DIB_RGB_COLORS, &dst_ptr,0,0);
    if (hBitmap==NULL)
        return nullptr;
    cvInitMatHeader(&dst, size.cy,size.cx,CV_8UC3, dst_ptr, (size.cx*channels+3)&-4);
    cvConvertImage(image, &ddst, origin=0 ? CV_CVTIMG:0);
    System::Drawing::Bitmap^ bmpImage=
        System::Drawing::Image::FromHbitmap(
        System::IntPtr(hBitmap));
    DeleteObject(hBitmap);
    DeleteDC(hdc);
    return bmpImage;
}
#endif 
下面是错误信息
1>C:opencvbuildincludecvToBitmap.h(6) : error C2065: 'BITMAPINFO' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(6) : error C2065: 'bmi' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(7) : error C2062: type 'int' unexpected
1>C:opencvbuildincludecvToBitmap.h(8) : error C2143: syntax error : missing ';' before '{'
1>C:opencvbuildincludecvToBitmap.h(8) : error C2447: '{' : missing function header (old-style formal list?)
1>C:opencvbuildincludecvToBitmap.h(29) : error C2065: 'SIZE' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(29) : error C2146: syntax error : missing ';' before identifier 'size'
1>C:opencvbuildincludecvToBitmap.h(29) : error C2065: 'size' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(37) : error C2065: 'HDC' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(37) : error C2146: syntax error : missing ';' before identifier 'hdc'
1>C:opencvbuildincludecvToBitmap.h(37) : error C2065: 'hdc' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(37) : error C3861: 'CreateCompatibleDC': identifier not found
1>C:opencvbuildincludecvToBitmap.h(41) : error C2065: 'BITMAPINFO' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(41) : error C2059: syntax error : ')'
1>C:opencvbuildincludecvToBitmap.h(42) : error C2065: 'size' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(42) : error C2228: left of '.cx' must have class/struct/union
1>        type is ''unknown-type''
1>C:opencvbuildincludecvToBitmap.h(43) : error C2065: 'size' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(43) : error C2228: left of '.cy' must have class/struct/union
1>        type is ''unknown-type''
1>C:opencvbuildincludecvToBitmap.h(45) : error C2065: 'binfo' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(45) : error C2065: 'size' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(45) : error C2228: left of '.cx' must have class/struct/union
1>        type is ''unknown-type''
1>C:opencvbuildincludecvToBitmap.h(45) : error C2065: 'size' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(45) : error C2228: left of '.cy' must have class/struct/union
1>        type is ''unknown-type''
1>C:opencvbuildincludecvToBitmap.h(45) : error C3861: 'FillBitmapInfo': identifier not found
1>C:opencvbuildincludecvToBitmap.h(46) : error C2065: 'HBITMAP' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(46) : error C2146: syntax error : missing ';' before identifier 'hBitmap'
1>C:opencvbuildincludecvToBitmap.h(46) : error C2065: 'hBitmap' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(46) : error C2065: 'hdc' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(46) : error C2065: 'binfo' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(46) : error C2065: 'DIB_RGB_COLORS' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(46) : error C3861: 'reateDIBSection': identifier not found
1>C:opencvbuildincludecvToBitmap.h(47) : error C2065: 'hBitmap' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(49) : error C2065: 'size' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(49) : error C2228: left of '.cy' must have class/struct/union
1>        type is ''unknown-type''
1>C:opencvbuildincludecvToBitmap.h(49) : error C2065: 'size' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(49) : error C2228: left of '.cx' must have class/struct/union
1>        type is ''unknown-type''
1>C:opencvbuildincludecvToBitmap.h(49) : error C2065: 'size' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(49) : error C2228: left of '.cx' must have class/struct/union
1>        type is ''unknown-type''
1>C:opencvbuildincludecvToBitmap.h(50) : error C2065: 'ddst' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(50) : error C2065: 'CV_CVTIMG' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(51) : error C2065: 'bmpImage' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(51) : error C2275: 'System::Drawing::Bitmap' : illegal use of this type as an expression
1>C:opencvbuildincludecvToBitmap.h(53) : error C2065: 'hBitmap' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(54) : error C2065: 'hBitmap' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(54) : error C3861: 'DeleteObject': identifier not found
1>C:opencvbuildincludecvToBitmap.h(55) : error C2065: 'hdc' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(55) : error C3861: 'DeleteDC': identifier not found
1>C:opencvbuildincludecvToBitmap.h(56) : error C2065: 'bmpImage' : undeclared identifier
1>C:opencvbuildincludecvToBitmap.h(57) : error C2143: syntax error : missing ')' before '}'
1>C:opencvbuildincludecvToBitmap.h(57) : error C2143: syntax error : missing ';' before ')'
    1>TampilForm - 50 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
我不知道,缺失的部分是什么。请帮助. .谢谢. .

您应该包含BITMAPINFO结构的头文件-将#include <windows.h>添加到您的头文件

相关内容

  • 没有找到相关文章