1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
%indent
 
* 画像変換 [#ba478ff1]
*** Bitmap ==> Mat [#t35bb635]
- cf: http://www42.atwiki.jp/jfactory/pages/23.html
- cf: http://bicycle.life.coocan.jp/takamints/index.php/doc/opencv/doc/Mat_conversion
- cf: http://imagingsolution.blog107.fc2.com/blog-entry-90.html
 
- BitmapのPixelFormatとcvCreateImageのdepth,channelを対応させる必要あり:
|*Bitmap           |*cvCreateImage|<|
|*PixelFormat      |*depth|lx:*channel|tx:
| Format8bppIndexed|8     |lx:1       |
| Format24bppRgb   |8     |lx:3       |tx:
| Format32bppRgba  |8     |lx:4       |tx:
 
### cpp
    static Mat ToMat(Bitmap^ bitmap) {
        return Mat(ToIpl(bitmap));
    }
    static IplImage* ToIpl(Bitmap^ bitmap) {
        auto format = PixelFormat::Format32bppArgb;
        auto size = cvSize(bitmap->Width, bitmap->Height);
        int depth = 8;
        int channel = 4;
 
        if (bitmap == nullptr) return 0;
        if (bitmap->PixelFormat != format) return 0;
 
        IplImage* ipl = cvCreateImage(size, depth, channel);
 
        BitmapData^ data = bitmap->LockBits(
            Drawing::Rectangle(0, 0, bitmap->Width, bitmap->Height),
            ImageLockMode::ReadWrite,
            format
        );
        memcpy_s(ipl->imageData, ipl->widthStep * ipl->height,
            data->Scan0.ToPointer(), data->Stride * data->Height
        );
        return (ipl);
    }
###
    呪文 一覧 検索 最新 バックアップ リンク元   ヘルプ   最終更新のRSS