刚接触OpenBR不久,也试图翻译了一部分openbr官方的文档,总算对openbr有一个大概的认识,下面给一个官方的c++版本的例子——人脸识别。本例程用于比较两张脸的相似程度。程序中给定两幅图像,其中用一副图像分别与另外一个图像和本身进行比较,得到相似度得分。
#include <openbr/openbr_plugin.h> //引入openbr c++ plugin头文件
//功能函数,用于输出templete中的数据
static void printTemplate(const br::Template &t)
{
const QPoint firstEye = t.file.get<QPoint>("Affine_0");
const QPoint secondEye = t.file.get<QPoint>("Affine_1");
printf("%s eyes: (%d, %d) (%d, %d)\n", qPrintable(t.file.fileName()), firstEye.x(), firstEye.y(), secondEye.x(), secondEye.y());
}
int main(int argc, char *argv[])
{
br::Context::initialize(argc, argv); //openbr初始化函数,必须
//transform 算法参数,这里为FaceRecognition 人脸识别
QSharedPointer<br::Transform> transform = br::Transform::fromAlgorithm("FaceRecognition");
QSharedPointer<br::Distance> distance = br::Distance::fromAlgorithm("FaceRecognition");
// 初始化templates
br::Template queryA("../data/MEDS/img/S354-01-t10_01.jpg");
br::Template queryB("../data/MEDS/img/S382-08-t10_01.jpg");
br::Template target("../data/MEDS/img/S354-02-t10_01.jpg");
// Enroll templates
queryA >> *transform;
queryB >> *transform;
target >> *transform;
printTemplate(queryA);
printTemplate(queryB);
printTemplate(target);
// 比较templates
float comparisonA = distance->compare(target, queryA);
float comparisonB = distance->compare(target, queryB);
// Scores range from 0 to 1 and represent match probability
printf("Genuine match score: %.3f\n", comparisonA);
printf("Impostor match score: %.3f\n", comparisonB);
br::Context::finalize();
return 0;
}