I'm using the EmguCV 3.0.0 wrapper to the OpenCV 3.0 library. I'm using the Mat
class in a few places. Here's an example of a single channel, 8x8 image made of double
values:
Mat image = new Mat(8, 8, DepthType.Cv64F, 1);
The Image<>
class provides reasonable means for getting and setting pixel values, and the method is identical for the Matrix<>
class, but it doesn't seem as obvious for the Mat
class. The only way I've figured out how to set individual pixel is using a mask:
// set two pixel values, (0,0) to 9.0, (2, 3) to 42.0
Matrix<byte> mask = new Matrix<byte>(8,8);
mask.Data[0, 0] = 1;
image.SetTo(new MCvScalar(9.0), mask);
mask = new Matrix<byte>(8,8);
mask.Data[2, 3] = 1;
image.SetTo(new MCvScalar(42.0), mask);
This is feels like it should be two lines, not six, so I feel like I'm missing something. Things get even more complicated when the Mat
is more than one channel, because Matrix<>
is only 2D, so the mask must be used to set the pixel on each channel.
I cannot afford the time or memory to set pixels this way. How can I set pixels with a single method call?