Ask Your Question
0

CvMlData read_csv in java

asked 2013-12-27 05:31:10 -0600

DonCossack gravatar image

Hi

I would like to ask how to read the csv file in java environment? As the opencv docs said, we can use CvMldata read_csv(), it is available for both C/C++ and Python. However, I searched on the docs for java, there is not the equivalent.

Any suggestions, if you please?

I would like to add the database for my feature matching algorithm.

Thanks

edit retag flag offensive close merge delete

Comments

"it is available for both C/C++ and Python" - where did you find that ? it does not seem to be wrapped for any scripting. i don't think, you can use it from java.

berak gravatar imageberak ( 2013-12-27 06:05:38 -0600 )edit

Well it seems so..

Do you have any suggestion on the alternative method?

The purpose is to construct a training set database so that I can apply the matching algorithm on the input.

DonCossack gravatar imageDonCossack ( 2013-12-27 07:09:56 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-09-17 14:35:17 -0600

JojoF gravatar image
    File file = new File("infraImage_045_270.csv");
    int rows = 240;
    int cols = 320;
    double buffRes[] = new double[cols*rows]; 
    String line = "";
    int k = 0;
    try (BufferedReader br = new BufferedReader(new FileReader(file))) {
        while ((line = br.readLine()) != null) {
            String[] vpLine = line.split(",");
            for(String s : vpLine) {
                try {
                    buffRes[k] = Double.parseDouble(s);
                }catch(NumberFormatException e) {
                    buffRes[k] = -Double.MAX_VALUE;
                    System.out.println("NAN");
                }
                k++;  
            }
        }
    }
    Mat res = new Mat(rows, cols, 0);
    res.put(0, 0, buffRes);

    HighGui.imshow("Picture", res);
    HighGui.waitKey(0);
    System.exit(0);
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-12-27 05:31:10 -0600

Seen: 371 times

Last updated: Dec 27 '13