CvMLData broken in openCV 2.4 (Bug #1962)
Description
Hi everyone,
in my project I was using CvMLData.read_csv from version 2.31 to parse a .csv file. When I switched to 2.4 precompiled static libraries for Windows x86 included in the last package the CvMLData.get_values methods always return 0. Please note that I tried the same code on the same .csv and while 2.3.1 returns some thousands of rows, with 2.4 just return 0!
The code I used is the following
CvMLData csvReader = CvMLData();
csvReader.read_csv("c:\\sp500.csv");
Mat data = csvReader.get_values();
cout << "Rows " << data.rows << "\n";
getchar();
in attach the sp500.csv to parse which works on 2.3.1 and fails with 2.4
Associated revisions
skip of table header in MLData (#1962)
Revert "skip of table header in MLData (#1962)"
This reverts commit 4d36be8794a56e3ea91fbd9df53e299dc8d951aa.
Conflicts:
modules/ml/include/opencv2/ml/ml.hpp
modules/ml/src/data.cpp
History
Updated by Maria Dimashova almost 13 years ago
Marco, thank you for the report. The problem is that the table stored in your file has a header. We don't support a files with a header in 2.4. Yes, it is wrong that we did not mentioned about this in the documentation, sorry. Even though you got nonzero number of samples (data.rows) with 2.3.1 it also was incorrect beacuse the first line (header) was considered as a sample too. As the header elements are not a numbers, you had to get all the variables are categorical (if you used MLData::get_var_types()), which is also incorrect.
The changes of 2.4, due to which you have a different behavior, are not a problem for the table without a header. So we left them, but added a support of a table header in r8391 for you :) You should update opencv to this revision and set the number of header lines using MLData::set_header_lines_number().
CvMLData csvReader; csvReader.set_header_lines_number(1); csvReader.read_csv("c:/sp500.csv"); cv::Mat data = csvReader.get_values();
The other way to solve your problem with 2.4 is just to remove the header lines from your file manually. And you need not update your opencv in the last case.
- Status changed from Open to Done
- Assignee changed from Vadim Pisarevsky to Maria Dimashova
Updated by Andrey Kamaev almost 13 years ago
- Target version changed from 2.4.3 to 3.0