Bitwise_and fails on smaller starting Mats

Hi,
I’m having trouble with bitwise_and, I’m getting some strange artefacts in the output image from the following code:

// remove the green background from the piece so we can overlay pieces without overlap
Mat transparentPieceMat = new Mat(piece.pieceMat.rows(), piece.pieceMat.cols(), CvType.CV_8UC4);
Imgproc.cvtColor(piece.pieceMat, piece.pieceMat, Imgproc.COLOR_BGR2BGRA);

Core.bitwise_and(piece.pieceMat, piece.pieceMat, transparentPieceMat, piece.pieceChromaMat);

I’m getting results like the following:


As you can see, smaller images, like the one along the top, do not work, they have this strange artefact left behind after the operation, whereas larger images, like the one below, work perfectly fine.

Both of these images undergo exactly the same processes, the only difference being that one of them is rotated more than another, giving it a larger image size.

What could be going wrong here? Cheers.

MRE required. none of these variables mean anything to me. I prefer MREs in python because that doesn’t require an IDE or a build system or any of that excrement. if you’re dealing with C#, be prepared for some friction. C# is not officially supported by OpenCV. primary support should be given by whatever project gives you the bindings.

think about what you’re doing. think about which arguments you’re passing. think about what a “mask” does.

you put your question in the python subforum. that’s not python code. best leave it uncategorized.

undeclared crosspost:

https://stackoverflow.com/questions/74338880/opencvc-artefacts-with-bitwise-and-with-small-images

Okay this is definitely a bug with the C# port, I’ve just compiled my app for Android to test and it’s working perfectly fine. I’ll file a bug report.

not necessarily. that could just be uninitialized memory (you did not initialize it to a specific value), and those pixels aren’t touched by the API call because you specify a mask argument.