面部识别OPENCV置信度负值
Face recognition Opencv confidence negative value
我正在从事面部识别项目,并且我遵循了OpenCV网站的教程,并且我使用了相同的数据集,但是当我测试程序时,我会有奇怪的结果(信心值)它给了我很大的值(((置信度=621034879。)在测试同一数据集样品时,它也给了我负面的信心。为什么信心具有如此大的价值并具有负值???这是我的代码:
#include "opencv2/core/core.hpp"
#include "opencv2/contrib/contrib.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
using namespace cv;
using namespace std;
static void read_csv(const string& filename, vector<Mat>& images, vector<int>& labels, char separator = ';') {
std::ifstream file(filename.c_str(), ifstream::in);
if (!file) {
string error_message = "No valid input file was given, please check the given filename.";
CV_Error(CV_StsBadArg, error_message);
}
string line, path, classlabel;
while (getline(file, line)) {
stringstream liness(line);
getline(liness, path, separator);
getline(liness, classlabel);
if (!path.empty() && !classlabel.empty()) {
images.push_back(imread(path, 0));
labels.push_back(atoi(classlabel.c_str()));
}
}
}
int main(int argc, const char *argv[]) {
// Check for valid command line arguments, print usage
// if no arguments were given.
// Get the path to your CSV.
string fn_csv = "C:/Users/ASUS/Documents/Visual Studio 2013/Projects/Car_Detection/a.txt";
// These vectors hold the images and corresponding labels.
vector<Mat> images;
vector<int> labels;
// Read in the data. This can fail if no valid
// input filename is given.
try {
read_csv(fn_csv, images, labels);
}
catch (cv::Exception& e) {
cerr << "Error opening file "" << fn_csv << "". Reason: " << e.msg << endl;
// nothing more we can do
exit(1);
}
// Quit if there are not enough images for this demo.
if (images.size() <= 1) {
string error_message = "This demo needs at least 2 images to work. Please add more images to your data set!";
CV_Error(CV_StsError, error_message);
}
// Get the height from the first image. We'll need this
// later in code to reshape the images to their original
// size:
int height = images[0].rows;
Mat testSample = images[images.size() - 1];
int testLabel = labels[labels.size() - 10];
images.pop_back();
labels.pop_back();
Ptr<FaceRecognizer> model = createEigenFaceRecognizer();
model->train(images, labels);
// The following line predicts the label of a given
// test image:
int predictedLabel = model->predict(testSample);
double confidence = 0.0;
model->predict(testSample, predictedLabel, confidence);
//
string result_message = format("Label = %d / confidence = %d.", predictedLabel, confidence);
cout << result_message << endl;
return 0;
}
这个很简单。您将confidence
(即double
)施放为int
,通过使用格式字符串中的%d
。您想要的是使用%f
(可能带有修饰符以限制小数点。
string result_message = format("Label = %d / confidence = %.2f.", predictedLabel, confidence);
相关文章:
- 什么是用面部识别器opencv训练面孔以获得最佳效果的最佳方法
- OPENCV错误在XCode 8中加载Fisher面部识别器时
- OpenCV SVM 分类器图像识别
- 面部识别OPENCV置信度负值
- OpenCV 3的面部识别
- OpenCV 用于识别训练视频集中的对象,然后针对另一个视频对其进行测试
- OpenCV 错误 5772.人脸识别
- 我在哪里可以找到完整的img包,用于训练opencv人脸识别系统?
- OpenCv:车牌识别
- 构建时OPENCV流量信号识别错误
- 识别多个面(特征面opencv)
- 人脸识别器OpenCV
- 在使用和执行OpenCV的人脸识别时需要帮助
- 用opencv识别点的正方形
- 使用OpenCV的ASL手势识别
- 物体手势识别.OpenCV C++
- OpenCV错误:cvGetMat中有错误的标志(参数或结构字段)(无法识别或不支持的数组类型)
- 使用opencv c++识别图像中的不同颜色
- 在OpenCV C++中训练支持向量机进行车牌识别
- 视觉C++无法识别 OpenCV 变量