Ask Your Question

Revision history [back]

ColorDetecting with opencv 3.4.1

I can't find where is the error ! My code :

public static void main(String[] args) {
    System.load("C:\\Users\\MustaProd\\Desktop\\opencv\\build\\java\\x64\\opencv_java341.dll");

    Mat img;
    img = imread("../feu/feu.png",1);

    Mat outRED = new Mat();
    Mat outOrange = new Mat();
    Mat outGREEN = new Mat();

    //BGR

    //obtenir RED
    Scalar redDebut = new Scalar(28,28,112);
    Scalar redFin = new Scalar(28,28,112);
    inRange(img,redDebut,redFin,outRED);

    //obtenir Orange
    inRange(img,new Scalar(0,85,204),new Scalar(206,231,247),outOrange);

    //obtenir GREEN
    inRange(img,new Scalar(0,128,0),new Scalar(93,236,178),outGREEN);


    int r = Core.countNonZero(outRED);
    int o = Core.countNonZero(outOrange);
    int g = Core.countNonZero(outGREEN);

    if(r>o && r>g) {
        System.out.println("Feu rouge!!!");
    }
    else if(o>g && o>r){
        System.out.println("Feu Orange!!!");
    }
    else {
        System.out.println("Feu Vert");
    }


}

output :

Exception in thread "main" java.lang.Exception: unknown exception
at org.opencv.core.Core.inRange_0(Native Method)
at org.opencv.core.Core.inRange(Core.java:1531)
at sample.Main.main(Main.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

Process finished with exit code 1