28#include <boost/filesystem.hpp>
37 std::string facesxml = CopyFileFromAssetToSD(
"btdata/lbpcascade_frontalface.xml",
"lbpcascade_frontalface.xml",
"btdata");
43 mFaceClassifier.load(facesxml);
49 mFaceClassifier.load(
"plugins/btdata/lbpcascade_frontalface.xml");
56 catch(std::exception&)
58 MMechostr(MSKRUNTIME,
"BitmapToolkit Error : Could not load training data for face detector");
72std::vector<cv::Rect> ArFaceDetector::DetectFaces(
const cv::Mat input, std::vector<ArMarker*> faceMarkers, aruco::CameraParameters camParam,
bool reversedBitmap)
74 std::vector<cv::Rect> outVector;
75 std::vector<cv::Rect> objList;
77 if (mFaceClassifier.empty())
80 mFaceClassifier.detectMultiScale(input, objList, 1.2, 4, cv::CASCADE_SCALE_IMAGE|cv::CASCADE_FIND_BIGGEST_OBJECT, cv::Size(30, 30));
82 for (
unsigned int i = 0; i< objList.size(); i++)
84 cv::Mat objROI = input(objList[i]);
85 cv::Rect objRect = objList[i];
89 cv::Rect tRect = objRect;
94 for (
unsigned int j = 0; j < faceMarkers.size() && !tracked; j++)
99 std::vector<cv::Point2f> coords = faceMarkers[j]->GetCorners();
100 if (coords.size() == 4)
102 for (
unsigned k = 0; k < coords.size() && !tracked; k++)
104 if (tRect.contains(coords[k]))
112 nRect.x = (int)coords[0].x;
113 nRect.y = (int)coords[0].y;
114 nRect.width = (int)coords[2].x - (
int)coords[0].x;
115 nRect.height = (int)coords[2].y - (
int)coords[0].y;
117 std::vector<cv::Point2f> lrect;
118 lrect.push_back(cv::Point2f((
float)objRect.x, (float)objRect.y));
119 lrect.push_back(cv::Point2f((
float)objRect.x + objRect.width, (float)objRect.y));
120 lrect.push_back(cv::Point2f((
float)objRect.x + objRect.width, (float)objRect.y + objRect.height));
121 lrect.push_back(cv::Point2f((
float)objRect.x, (float)objRect.y + objRect.height));
123 for (
unsigned k = 0; k < lrect.size() && !tracked; k++)
125 if (nRect.contains(lrect[k]))
184 for (
unsigned int j = 0; j < faceMarkers.size() && !found; j++)
189 std::vector<cv::Rect> lRects;
190 lRects.push_back(objRect);
197 outVector.push_back(objRect);
214 if (mLastData.
gray.rows != 480 || mLastData.
gray.cols != 640)
217 if (mLastData.
gray.rows >= mLastData.
gray.cols)
219 nsize.width = (int)(((
float)mLastData.
gray.cols * 480.0f) / (float)mLastData.
gray.rows);
225 nsize.height = (int)(((
float)mLastData.
gray.rows * 640.0f) / (
float)mLastData.
gray.cols);
227 cv::resize(mLastData.
gray, mLastData.
gray, nsize, 0, 0, cv::INTER_LINEAR);
230 cv::equalizeHist(mLastData.
gray, mLastData.
gray);
237 boost::shared_lock< boost::shared_mutex > lockList(manager->
listMutex);
240 bool needFaceDetect =
false;
241 ArManager::MarkerList::iterator imarker;
242 std::vector<ArMarker*> faceMarkers;
249 needFaceDetect =
true;
251 faceMarkers.push_back((*imarker));
261 std::vector<ArMarker*> foundMarkers;
262 for (
unsigned int j = 0; j < faceMarkers.size(); j++)
266 if (faceMarkers[j]->IsVisible())
268 foundMarkers.push_back(faceMarkers[j]);
275 boost::this_thread::sleep_for(boost::chrono::milliseconds(1));
aruco::CameraParameters camParam
virtual ~ArFaceDetector()
void SetImage(const cv::Mat image, std::vector< cv::Rect > objRects)
void Update(cv::Mat frame, cv::Mat color, aruco::CameraParameters &camparam, bool reverse)
void GetLastData(LASTDATA &data)
static ArManager * GetInstance()
boost::shared_mutex listMutex
void StartThreading(std::function< void()> threadFunction)