Invert colors OpenCV Java Api

10,689

Solution 1

inv() method will try to take inverse of the matrix that's why it is failing (most probably your image matrix is not invertible).

You can subtract two images from each other, so you can create an image with all values are 255 and then extract original one from it, if that is what you mean by invert the colors.

Solution 2

Just in case:

Mat invertcolormatrix= new Mat(image.rows(),image.cols(), image.type(), new Scalar(255,255,255));

Core.subtract(invertcolormatrix, image, image);
Share:
10,689
Rui d'Orey
Author by

Rui d'Orey

Updated on June 04, 2022

Comments

  • Rui d'Orey
    Rui d'Orey almost 2 years

    How do I invert the colors of an image stored in Mat image in the Java API of OpenCV? Using image.inv() gets me an error.