Skip to content

Instantly share code, notes, and snippets.

@tibaes
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tibaes/4d3dc720175f4b06c07b to your computer and use it in GitHub Desktop.
Save tibaes/4d3dc720175f4b06c07b to your computer and use it in GitHub Desktop.
OpenBR Face and Eyes detection using C++
PKG_CONFIG_PATH := /usr/local/opt/qt5/lib/pkgconfig/:/usr/local/lib/pkgconfig/:/usr/lib/pkgconfig/
export PKG_CONFIG_PATH
SHELL := /bin/bash
CC = g++
CFLAGS=-std=c++11 -Wall -Wno-overloaded-virtual -O2 `pkg-config --cflags opencv Qt5Core Qt5Concurrent`
CXXFLAGS=$(CFLAGS)
LDFLAGS=-lm -lopenbr `pkg-config --libs opencv Qt5Core Qt5Concurrent`
#include <openbr/openbr_plugin.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
int main(int argc, char *argv[]) {
cv::Mat cvin = cv::imread(argv[1], CV_LOAD_IMAGE_COLOR);
int a = 0;
char *b[1];
br::Context::initialize(a, b); // argc, argv
QSharedPointer<br::Transform> transform =
br::Transform::fromAlgorithm("Open+Cascade(FrontalFace)+ASEFEyes");
br::Globals->enrollAll = true;
br::Template q0(cvin);
br::TemplateList querylist;
querylist.push_back(q0);
querylist >> *transform;
cv::imshow("Detector", querylist.front().m());
cv::waitKey();
cv::Mat vis = querylist.front().m();
for (auto query : querylist) {
const QPoint firstEye = query.file.get<QPoint>("First_Eye");
const QPoint secondEye = query.file.get<QPoint>("Second_Eye");
const QRect faceroi = query.file.get<QRect>("FrontalFace");
printf("%s face: (%d, %d, %d, %d)\teyes: (%d, %d) (%d, %d)\n",
qPrintable(query.file.fileName()),
faceroi.x(), faceroi.y(), faceroi.width(), faceroi.height(),
firstEye.x(), firstEye.y(), secondEye.x(), secondEye.y());
cv::Point fe(firstEye.x(), firstEye.y()), se(secondEye.x(), secondEye.y());
cv::circle(vis, fe, 5.0, cv::Scalar(255, 0, 0));
cv::circle(vis, se, 5.0, cv::Scalar(0, 0, 255));
}
cv::imshow("Detector", vis);
cv::waitKey();
br::Context::finalize();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment