0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【OpenCVSharp】Mat.ForEachByteの使い方Memo

Last updated at Posted at 2021-02-16

すみません。positionがちょっと思ったのと違うみたいです。
以下は失敗してます・・・。

なんだか意外と検索に引っかからなかったので備忘録です。

以下は指定領域のピクセル画素のRGBをジャグ配列に詰めている様子です。

            using (var roiImg = new Mat(img, roi))
            {
                var channels = img.Channels();
                var tempArray = new byte[roi.Width * roi.Height][];
                for(int i=0; i < tempArray.Length; i++)
                {
                    tempArray[i] = new byte[channels];
                }
                unsafe
                {

                    roiImg.ForEachAsByte((pixel, position) =>
                    {
  
                        for (int i = 0; i < channels; i++)
                        {

                            tempArray[position[1] * roi.Height + position[0]][i] = pixel[i];
                        }
                    });
                }

                return tempArray;
            }

positionがどう使うのか良く分からなかったですがとりあえずこれで通りました。
ポインタの指す先がxで1個次にyが入ってる??
pixelはよく使うのはRGBかBGRもしくはグレースケールの1チャンネルでしょうか。
RGBの場合はpixel[0] : R / pixel[1] : G / pixel[2] : Bで、
グレースケールの場合の場合はpixel[0]のみ使う感じですね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?