zoukankan      html  css  js  c++  java
  • bmp和opencv格式转换

    IplImage * BmpTOIpl(int width,int height,unsigned char  *pBuffer)
    {
        IPlImage 
    *image =cvCreateImage(cvSize(width,height),8,1);
       image
    ->imageData=pBuffer;
       
    return image;
    }





    CDibPtr IplToDib(IplImage 
    *image)
    {
       CDibPtr m_ptrBitmaps;
       CSize ImageSize;
       ImageSize.cx
    =image->width;
       ImageSize.cy
    =image->height;
       m_ptrBitmaps.Create(ImageSize, 
    8, CDib::TopDown, CDib::Monochrome);
      (unsigned 
    char*) m_ptrBitmaps->GetPixels()=image->ImageData;
      
    return m_ptrBitmaps;
    }
    IplImage* hBitmap2Ipl(HBITMAP hBmp) 

    BITMAP bmp; 

    ::GetObject(hBmp,
    sizeof(BITMAP),&bmp); 

    int nChannels = bmp.bmBitsPixel == 1 ? 1 : bmp.bmBitsPixel/8 ; 
    int depth = bmp.bmBitsPixel == 1 ? IPL_DEPTH_1U : IPL_DEPTH_8U; 

    IplImage
    * img = cvCreateImageHeader( cvSize(bmp.bmWidth, bmp.bmHeight) 
    , depth, nChannels ); 

    img
    ->imageData = 
    (
    char*)malloc(bmp.bmHeight*bmp.bmWidth*nChannels*sizeof(char)); 
    memcpy(img
    ->imageData,(char*)(bmp.bmBits),bmp.bmHeight*bmp.bmWidth*nChannels); 

    return img; 
    }
     


    void createDIB(IplImage* &pict)
    IplImage 
    * Red=cvCreateImage( cvSize(IMAGE_WIDTH,IMAGE_HEIGHT), 
    IPL_DEPTH_8U, 
    1 ); 
    IplImage 
    * Green=cvCreateImage( cvSize(IMAGE_WIDTH,IMAGE_HEIGHT), 
    IPL_DEPTH_8U, 
    1 ); 
    IplImage 
    * Blue=cvCreateImage( cvSize(IMAGE_WIDTH,IMAGE_HEIGHT), 
    IPL_DEPTH_8U, 
    1 ); 
    cvSetImageCOI( pict, 
    3); 
    cvCopy(pict,Red); 
    cvSetImageCOI( pict, 
    2); 
    cvCopy(pict,Green); 
    cvSetImageCOI(pict, 
    1); 
    cvCopy(pict,Blue); 
    //Initialize the BMP display buffer 
    bmi = (BITMAPINFO*)buffer; 
    bmih 
    = &(bmi->bmiHeader); 
    memset( bmih, 
    0sizeof(*bmih)); 
    bmih
    ->biSize = sizeof(BITMAPINFOHEADER); 
    bmih
    ->biWidth = IMAGE_WIDTH; 
    bmih
    ->biHeight = IMAGE_HEIGHT; // -IMAGE_HEIGHT; 
    bmih->biPlanes = 1
    bmih
    ->biCompression = BI_RGB; 
    bmih
    ->biBitCount = 24
    palette 
    = bmi->bmiColors; 
    forint i = 0; i < 256; i++ )
    palette[i].rgbBlue 
    = palette[i].rgbGreen = palette[i].rgbRed = 
    (BYTE)i; 
    palette[i].rgbReserved 
    = 0
    }
     
    cvReleaseImage(
    &Red); 
    cvReleaseImage(
    &Green); 
    cvReleaseImage(
    &Blue); 
    }
  • 相关阅读:
    suse10+samba+ldap搭建pdc备忘
    深入挖掘Windows脚本技术(转自http://www.yuanma.org/data/2006/1212/article_1935.htm)
    Getting Paging working with Mitel Phones
    CentOS4.4+Samba+LDAP备忘
    oracle字符集问题
    Trixbox(Asterisk)+sangoma A101D+PBX
    Some useful vba macros
    (转载)wipe.c and z2.c
    Trixbox2.2+webmeetme2.2
    (转载)hosts.equiv和.rhosts文件
  • 原文地址:https://www.cnblogs.com/wqj1212/p/1006338.html
Copyright © 2011-2022 走看看