4,499
社区成员




for (int i = 0; i < number; i++) {
Mat inMat = imread(files[i].c_str());//读取成mat格式
//imshow("input", inMat);
//waitKey();
Mat temp;
resize(inMat, temp, Size(256, 256));//转换成256*256像素大小的图片
//imshow("input0", temp);
//waitKey();
Mat p = temp.reshape(0, 1);//转换成1行n*n列的行向量
//imshow("input1", p);
//waitKey();
p.convertTo(p, CV_32FC1);//转换格式
int response = (int) Svm->predict(p);//预测结果
if (response == expectValue) {
result++;
cout << "第" << i << "个图片预测成功为" << expectValue << endl;
}
else
{
cout << "第" << i << "个图片预测失败,本应预测为" << expectValue << endl;
cout << "实际预测结果为" << response << endl;
}
}
cout << "所有预测文件中的图片已经预测完毕。" << endl;
cout << "预测图片数量为:" << result << endl;
return true;