%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|*channel|tx:
| Format8bppIndexed|8     |1       |
| Format24bppRgb   |8     |3       |tx:
| Format32bppRgba  |8     |4       |tx:
|*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