Ask Your Question
0

ColorDetecting with opencv 3.4.1

asked 2018-04-18 20:59:52 -0600

Mus gravatar image

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

edit retag flag offensive close merge delete

Comments

Can you check img size ?

LBerger gravatar imageLBerger ( 2018-04-19 01:18:46 -0600 )edit
1

please check for img.empty() after imread()

berak gravatar imageberak ( 2018-04-19 02:49:04 -0600 )edit
1

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-04-19 03:23:33 -0600

always, but really always, start with absolute paths, instead of relative ones. You would be amazed for how many people that would solve their issues. Keep in mind that different IDE's use different execution locations, and thus relative paths could simply be wrong, resulting in an image that does not exist, hence all the subsequent issues.

edit flag offensive delete link more

Comments

1

I runs well after using the absolute path! Thanks! :D

Mus gravatar imageMus ( 2018-05-08 14:32:45 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-04-18 20:59:52 -0600

Seen: 253 times

Last updated: Apr 18 '18