私は陽性とJPG形式のネガ画像の別のフォルダを持っている、と私はイメージが、私は次のことをやったが、私はエラーを受け取ることに基づいてSVMを訓練したい:私イメージセットに基づいてopencvでSVMをトレーニングするにはどうすればいいですか?
Mat classes = new Mat();
Mat trainingData = new Mat();
Mat trainingImages = new Mat();
Mat trainingLabels = new Mat();
CvSVM clasificador;
for (File file : new File(path + "positives/").listFiles()) {
Mat img = Highgui.imread(file.getAbsolutePath());
img.reshape(1, 1);
trainingImages.push_back(img);
trainingLabels.push_back(Mat.ones(new Size(1, 1), CvType.CV_32FC1));
}
for (File file : new File(path + "negatives/").listFiles()) {
Mat img = Highgui.imread(file.getAbsolutePath());
img.reshape(1, 1);
trainingImages.push_back(img);
trainingLabels.push_back(Mat.zeros(new Size(1, 1), CvType.CV_32FC1));
}
trainingImages.copyTo(trainingData);
trainingData.convertTo(trainingData, CvType.CV_32FC1);
trainingLabels.copyTo(classes);
CvSVMParams params = new CvSVMParams();
params.set_kernel_type(CvSVM.LINEAR);
clasificador = new CvSVM(trainingData, classes, new Mat(), new Mat(), params);
それを実行しようとしてください:
OpenCV Error: Bad argument (train data must be floating-point matrix) in cvCheckTrainData, file ..\..\..\src\opencv\modules\ml\src\inner_functions.cpp, line 857
Exception in thread "main" CvException [org.opencv.core.CvException: ..\..\..\src\opencv\modules\ml\src\inner_functions.cpp:857: error: (-5) train data must be floating-point matrix in function cvCheckTrainData
]
at org.opencv.ml.CvSVM.CvSVM_1(Native Method)
at org.opencv.ml.CvSVM.<init>(CvSVM.java:80)
私はSVM、任意のアイデアを訓練することはできませんか?ありがとう
私はすでに得segmetsに基づいて、プレートを分類しようとしている、私のコードは、この例に基づいています。https:// githubの.com/MasteringOpenCV/code/blob/master/Chapter5_NumberPlateRecognition/trainSVM.cpp –
CV_64Fを試しましたか?そして、CvSVMに渡される直前の 'trainingData'のタイプが何であるかを確かめてみましたか? – morynicz
ありがとう@morynicz、 'CvType.typeToString(trainingData.type())'は "CV_32FC3"を返します..同じエラーでCV_64Fに変換しようとしました –