すみません。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]のみ使う感じですね。