Goal: Adding a solid white line to a black'n'white image.
I'm trying to extract text from an image by cropping it and then adding a solid border with copyMakeBorder(). My problem is that I can't make the border solid. It seems like the copyMakeBorder() uses information from my initial image instead.
This is my code:
void OcvCardReader::cropToAreaWithSolidBorder(Mat image, const Rect2f area) {
//Crop the image.
image = image(area)
//Add the border.
int borderSize = 10;
copyMakeBorder(image, image,
borderSize, borderSize, borderSize, borderSize,
BORDER_CONSTANT, Scalar(255));
}
My input image looks like this:

This is after the crop:

And finally, after adding the border:

Note the black pixels att the bottom left. I had expected a border to be white all around. I also tried to use Scalar(0) to see if it makes any difference. It doesn't.
Curiously, it works well if I convert the image to a 3-channel Mat and then use Scalar(255, 255, 255), but that seems like a detour to me.
So, why does copyMakeBorder() return a border that isn't solid?