Invert colors OpenCV Java Api

后端 未结 3 1250
逝去的感伤
逝去的感伤 2021-01-22 19:41

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.

相关标签:
3条回答
  • 2021-01-22 20:04

    inv() is used to calculate inverse matrix; use bitwise_not instead:

    Core.bitwise_not( image, image );
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-22 20:15

    Just in case:

    Mat invertcolormatrix= new Mat(image.rows(),image.cols(), image.type(), new Scalar(255,255,255));
    
    Core.subtract(invertcolormatrix, image, image);
    
    0 讨论(0)
提交回复
热议问题