Commit 7c160cdc authored by Alexander Smorkalov's avatar Alexander Smorkalov

Detection based tracker was refactored. Detector interface added.

parent a20837fb
...@@ -12,17 +12,66 @@ class DetectionBasedTracker ...@@ -12,17 +12,66 @@ class DetectionBasedTracker
public: public:
struct Parameters struct Parameters
{ {
int minObjectSize;
int maxObjectSize;
double scaleFactor;
int maxTrackLifetime; int maxTrackLifetime;
int minNeighbors;
int minDetectionPeriod; //the minimal time between run of the big object detector (on the whole frame) in ms (1000 mean 1 sec), default=0 int minDetectionPeriod; //the minimal time between run of the big object detector (on the whole frame) in ms (1000 mean 1 sec), default=0
Parameters(); Parameters();
}; };
DetectionBasedTracker(const std::string& cascadeFilename, const Parameters& params); class IDetector
{
public:
IDetector():
MinObjSize(96, 96),
MaxObjSize(INT_MAX, INT_MAX),
ScaleFactor(1.1f),
MinNeighbours(2)
{}
virtual void detect(const cv::Mat& Image, std::vector<cv::Rect>& objects) = 0;
void setMinObjectSize(const cv::Size& min)
{
MinObjSize = min;
}
void setMaxObjectSize(const cv::Size& max)
{
MaxObjSize = max;
}
cv::Size getMinObjectSize() const
{
return MinObjSize;
}
cv::Size getMaxObjectSize() const
{
return MaxObjSize;
}
float getScaleFactor()
{
return ScaleFactor;
}
void setScaleFactor(float value)
{
ScaleFactor = value;
}
int getMinNeighbours()
{
return ScaleFactor;
}
void setMinNeighbours(int value)
{
}
virtual ~IDetector() {}
protected:
cv::Size MinObjSize;
cv::Size MaxObjSize;
int MinNeighbours;
float ScaleFactor;
};
DetectionBasedTracker(cv::Ptr<IDetector> MainDetector, cv::Ptr<IDetector> TrackingDetector, const Parameters& params);
virtual ~DetectionBasedTracker(); virtual ~DetectionBasedTracker();
virtual bool run(); virtual bool run();
...@@ -44,7 +93,6 @@ class DetectionBasedTracker ...@@ -44,7 +93,6 @@ class DetectionBasedTracker
cv::Ptr<SeparateDetectionWork> separateDetectionWork; cv::Ptr<SeparateDetectionWork> separateDetectionWork;
friend void* workcycleObjectDetectorFunction(void* p); friend void* workcycleObjectDetectorFunction(void* p);
struct InnerParameters struct InnerParameters
{ {
int numLastPositionsToTrack; int numLastPositionsToTrack;
...@@ -90,8 +138,7 @@ class DetectionBasedTracker ...@@ -90,8 +138,7 @@ class DetectionBasedTracker
std::vector<float> weightsPositionsSmoothing; std::vector<float> weightsPositionsSmoothing;
std::vector<float> weightsSizesSmoothing; std::vector<float> weightsSizesSmoothing;
cv::CascadeClassifier cascadeForTracking; cv::Ptr<IDetector> cascadeForTracking;
void updateTrackedObjects(const std::vector<cv::Rect>& detectedObjects); void updateTrackedObjects(const std::vector<cv::Rect>& detectedObjects);
cv::Rect calcTrackedObjectPositionToShow(int i) const; cv::Rect calcTrackedObjectPositionToShow(int i) const;
......
...@@ -52,10 +52,11 @@ static inline cv::Rect scale_rect(const cv::Rect& r, float scale) ...@@ -52,10 +52,11 @@ static inline cv::Rect scale_rect(const cv::Rect& r, float scale)
}; };
void* workcycleObjectDetectorFunction(void* p); void* workcycleObjectDetectorFunction(void* p);
class DetectionBasedTracker::SeparateDetectionWork class DetectionBasedTracker::SeparateDetectionWork
{ {
public: public:
SeparateDetectionWork(DetectionBasedTracker& _detectionBasedTracker, const std::string& cascadeFilename); SeparateDetectionWork(DetectionBasedTracker& _detectionBasedTracker, cv::Ptr<DetectionBasedTracker::IDetector> _detector);
virtual ~SeparateDetectionWork(); virtual ~SeparateDetectionWork();
bool communicateWithDetectingThread(const Mat& imageGray, vector<Rect>& rectsWhereRegions); bool communicateWithDetectingThread(const Mat& imageGray, vector<Rect>& rectsWhereRegions);
bool run(); bool run();
...@@ -77,7 +78,7 @@ class DetectionBasedTracker::SeparateDetectionWork ...@@ -77,7 +78,7 @@ class DetectionBasedTracker::SeparateDetectionWork
protected: protected:
DetectionBasedTracker& detectionBasedTracker; DetectionBasedTracker& detectionBasedTracker;
cv::CascadeClassifier cascadeInThread; cv::Ptr<DetectionBasedTracker::IDetector> cascadeInThread;
pthread_t second_workthread; pthread_t second_workthread;
pthread_mutex_t mutex; pthread_mutex_t mutex;
...@@ -105,7 +106,7 @@ class DetectionBasedTracker::SeparateDetectionWork ...@@ -105,7 +106,7 @@ class DetectionBasedTracker::SeparateDetectionWork
long long timeWhenDetectingThreadStartedWork; long long timeWhenDetectingThreadStartedWork;
}; };
DetectionBasedTracker::SeparateDetectionWork::SeparateDetectionWork(DetectionBasedTracker& _detectionBasedTracker, const std::string& cascadeFilename) DetectionBasedTracker::SeparateDetectionWork::SeparateDetectionWork(DetectionBasedTracker& _detectionBasedTracker, cv::Ptr<DetectionBasedTracker::IDetector> _detector)
:detectionBasedTracker(_detectionBasedTracker), :detectionBasedTracker(_detectionBasedTracker),
cascadeInThread(), cascadeInThread(),
isObjectDetectingReady(false), isObjectDetectingReady(false),
...@@ -113,9 +114,10 @@ DetectionBasedTracker::SeparateDetectionWork::SeparateDetectionWork(DetectionBas ...@@ -113,9 +114,10 @@ DetectionBasedTracker::SeparateDetectionWork::SeparateDetectionWork(DetectionBas
stateThread(STATE_THREAD_STOPPED), stateThread(STATE_THREAD_STOPPED),
timeWhenDetectingThreadStartedWork(-1) timeWhenDetectingThreadStartedWork(-1)
{ {
if(!cascadeInThread.load(cascadeFilename)) { CV_Assert(!_detector.empty());
CV_Error(CV_StsBadArg, "DetectionBasedTracker::SeparateDetectionWork::SeparateDetectionWork: Cannot load a cascade from the file '"+cascadeFilename+"'");
} cascadeInThread = _detector;
int res=0; int res=0;
res=pthread_mutex_init(&mutex, NULL);//TODO: should be attributes? res=pthread_mutex_init(&mutex, NULL);//TODO: should be attributes?
if (res) { if (res) {
...@@ -274,20 +276,17 @@ void DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() ...@@ -274,20 +276,17 @@ void DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector()
int64 t1_detect=getTickCount(); int64 t1_detect=getTickCount();
int minObjectSize=detectionBasedTracker.parameters.minObjectSize; cascadeInThread->detect(imageSeparateDetecting, objects);
Size min_objectSize=Size(minObjectSize, minObjectSize);
int maxObjectSize=detectionBasedTracker.parameters.maxObjectSize; /*cascadeInThread.detectMultiScale( imageSeparateDetecting, objects,
Size max_objectSize(maxObjectSize, maxObjectSize);
cascadeInThread.detectMultiScale( imageSeparateDetecting, objects,
detectionBasedTracker.parameters.scaleFactor, detectionBasedTracker.parameters.minNeighbors, 0 detectionBasedTracker.parameters.scaleFactor, detectionBasedTracker.parameters.minNeighbors, 0
|CV_HAAR_SCALE_IMAGE |CV_HAAR_SCALE_IMAGE
, ,
min_objectSize, min_objectSize,
max_objectSize max_objectSize
); );
*/
LOGD("DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- end handling imageSeparateDetecting"); LOGD("DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- end handling imageSeparateDetecting");
if (!isWorking()) { if (!isWorking()) {
...@@ -422,16 +421,10 @@ bool DetectionBasedTracker::SeparateDetectionWork::communicateWithDetectingThrea ...@@ -422,16 +421,10 @@ bool DetectionBasedTracker::SeparateDetectionWork::communicateWithDetectingThrea
DetectionBasedTracker::Parameters::Parameters() DetectionBasedTracker::Parameters::Parameters()
{ {
minObjectSize=96;
maxObjectSize=INT_MAX;
scaleFactor=1.1;
maxTrackLifetime=5; maxTrackLifetime=5;
minNeighbors=2;
minDetectionPeriod=0; minDetectionPeriod=0;
} }
DetectionBasedTracker::InnerParameters::InnerParameters() DetectionBasedTracker::InnerParameters::InnerParameters()
{ {
numLastPositionsToTrack=4; numLastPositionsToTrack=4;
...@@ -444,39 +437,32 @@ DetectionBasedTracker::InnerParameters::InnerParameters() ...@@ -444,39 +437,32 @@ DetectionBasedTracker::InnerParameters::InnerParameters()
coeffObjectSpeedUsingInPrediction=0.8; coeffObjectSpeedUsingInPrediction=0.8;
} }
DetectionBasedTracker::DetectionBasedTracker(const std::string& cascadeFilename, const Parameters& params)
DetectionBasedTracker::DetectionBasedTracker(cv::Ptr<IDetector> MainDetector, cv::Ptr<IDetector> TrackingDetector, const Parameters& params)
:separateDetectionWork(), :separateDetectionWork(),
innerParameters(), innerParameters(),
cascadeForTracking(TrackingDetector),
parameters(params),
numTrackedSteps(0) numTrackedSteps(0)
{ {
CV_Assert( (params.minObjectSize > 0) CV_Assert( (params.maxTrackLifetime >= 0)
&& (params.maxObjectSize >= 0) && (!MainDetector.empty())
&& (params.scaleFactor > 1.0) && (!TrackingDetector.empty()) );
&& (params.maxTrackLifetime >= 0) );
if (!cascadeForTracking.load(cascadeFilename)) {
CV_Error(CV_StsBadArg, "DetectionBasedTracker::DetectionBasedTracker: Cannot load a cascade from the file '"+cascadeFilename+"'");
}
parameters=params;
separateDetectionWork=new SeparateDetectionWork(*this, cascadeFilename); separateDetectionWork = new SeparateDetectionWork(*this, MainDetector);
weightsPositionsSmoothing.push_back(1); weightsPositionsSmoothing.push_back(1);
weightsSizesSmoothing.push_back(0.5); weightsSizesSmoothing.push_back(0.5);
weightsSizesSmoothing.push_back(0.3); weightsSizesSmoothing.push_back(0.3);
weightsSizesSmoothing.push_back(0.2); weightsSizesSmoothing.push_back(0.2);
} }
DetectionBasedTracker::~DetectionBasedTracker() DetectionBasedTracker::~DetectionBasedTracker()
{ {
} }
void DetectionBasedTracker::process(const Mat& imageGray) void DetectionBasedTracker::process(const Mat& imageGray)
{ {
CV_Assert(imageGray.type()==CV_8UC1); CV_Assert(imageGray.type()==CV_8UC1);
if (!separateDetectionWork->isWorking()) { if (!separateDetectionWork->isWorking()) {
...@@ -494,15 +480,9 @@ void DetectionBasedTracker::process(const Mat& imageGray) ...@@ -494,15 +480,9 @@ void DetectionBasedTracker::process(const Mat& imageGray)
Mat imageDetect=imageGray; Mat imageDetect=imageGray;
int D=parameters.minObjectSize;
if (D < 1)
D=1;
vector<Rect> rectsWhereRegions; vector<Rect> rectsWhereRegions;
bool shouldHandleResult=separateDetectionWork->communicateWithDetectingThread(imageGray, rectsWhereRegions); bool shouldHandleResult=separateDetectionWork->communicateWithDetectingThread(imageGray, rectsWhereRegions);
if (shouldHandleResult) { if (shouldHandleResult) {
LOGD("DetectionBasedTracker::process: get _rectsWhereRegions were got from resultDetect"); LOGD("DetectionBasedTracker::process: get _rectsWhereRegions were got from resultDetect");
} else { } else {
...@@ -517,7 +497,6 @@ void DetectionBasedTracker::process(const Mat& imageGray) ...@@ -517,7 +497,6 @@ void DetectionBasedTracker::process(const Mat& imageGray)
continue; continue;
} }
//correction by speed of rectangle //correction by speed of rectangle
if (n > 1) { if (n > 1) {
Point2f center=centerRect(r); Point2f center=centerRect(r);
...@@ -560,6 +539,7 @@ void DetectionBasedTracker::getObjects(std::vector<cv::Rect>& result) const ...@@ -560,6 +539,7 @@ void DetectionBasedTracker::getObjects(std::vector<cv::Rect>& result) const
LOGD("DetectionBasedTracker::process: found a object with SIZE %d x %d, rect={%d, %d, %d x %d}", r.width, r.height, r.x, r.y, r.width, r.height); LOGD("DetectionBasedTracker::process: found a object with SIZE %d x %d, rect={%d, %d, %d x %d}", r.width, r.height, r.x, r.y, r.width, r.height);
} }
} }
void DetectionBasedTracker::getObjects(std::vector<Object>& result) const void DetectionBasedTracker::getObjects(std::vector<Object>& result) const
{ {
result.clear(); result.clear();
...@@ -574,8 +554,6 @@ void DetectionBasedTracker::getObjects(std::vector<Object>& result) const ...@@ -574,8 +554,6 @@ void DetectionBasedTracker::getObjects(std::vector<Object>& result) const
} }
} }
bool DetectionBasedTracker::run() bool DetectionBasedTracker::run()
{ {
return separateDetectionWork->run(); return separateDetectionWork->run();
...@@ -711,6 +689,7 @@ void DetectionBasedTracker::updateTrackedObjects(const vector<Rect>& detectedObj ...@@ -711,6 +689,7 @@ void DetectionBasedTracker::updateTrackedObjects(const vector<Rect>& detectedObj
} }
} }
} }
Rect DetectionBasedTracker::calcTrackedObjectPositionToShow(int i) const Rect DetectionBasedTracker::calcTrackedObjectPositionToShow(int i) const
{ {
if ( (i < 0) || (i >= (int)trackedObjects.size()) ) { if ( (i < 0) || (i >= (int)trackedObjects.size()) ) {
...@@ -743,8 +722,8 @@ Rect DetectionBasedTracker::calcTrackedObjectPositionToShow(int i) const ...@@ -743,8 +722,8 @@ Rect DetectionBasedTracker::calcTrackedObjectPositionToShow(int i) const
double sum=0; double sum=0;
for(int j=0; j < Nsize; j++) { for(int j=0; j < Nsize; j++) {
int k=N-j-1; int k=N-j-1;
w+= lastPositions[k].width * weightsSizesSmoothing[j]; w += lastPositions[k].width * weightsSizesSmoothing[j];
h+= lastPositions[k].height * weightsSizesSmoothing[j]; h += lastPositions[k].height * weightsSizesSmoothing[j];
sum+=weightsSizesSmoothing[j]; sum+=weightsSizesSmoothing[j];
} }
w /= sum; w /= sum;
...@@ -762,7 +741,7 @@ Rect DetectionBasedTracker::calcTrackedObjectPositionToShow(int i) const ...@@ -762,7 +741,7 @@ Rect DetectionBasedTracker::calcTrackedObjectPositionToShow(int i) const
Point br(lastPositions[k].br()); Point br(lastPositions[k].br());
Point2f c1; Point2f c1;
c1=tl; c1=tl;
c1=c1* 0.5f; c1=c1* 0.5f;
Point2f c2; Point2f c2;
c2=br; c2=br;
c2=c2*0.5f; c2=c2*0.5f;
...@@ -802,8 +781,7 @@ void DetectionBasedTracker::detectInRegion(const Mat& img, const Rect& r, vector ...@@ -802,8 +781,7 @@ void DetectionBasedTracker::detectInRegion(const Mat& img, const Rect& r, vector
return; return;
} }
int d=std::min(r.width, r.height); int d = cvRound(std::min(r.width, r.height) * innerParameters.coeffObjectSizeToTrack);
d=cvRound(d * innerParameters.coeffObjectSizeToTrack);
vector<Rect> tmpobjects; vector<Rect> tmpobjects;
...@@ -811,17 +789,17 @@ void DetectionBasedTracker::detectInRegion(const Mat& img, const Rect& r, vector ...@@ -811,17 +789,17 @@ void DetectionBasedTracker::detectInRegion(const Mat& img, const Rect& r, vector
LOGD("DetectionBasedTracker::detectInRegion: img1.size()=%d x %d, d=%d", LOGD("DetectionBasedTracker::detectInRegion: img1.size()=%d x %d, d=%d",
img1.size().width, img1.size().height, d); img1.size().width, img1.size().height, d);
int maxObjectSize=parameters.maxObjectSize; cascadeForTracking->setMinObjectSize(Size(d, d));
Size max_objectSize(maxObjectSize, maxObjectSize); cascadeForTracking->detect(img1, tmpobjects);
/*
cascadeForTracking.detectMultiScale( img1, tmpobjects, detectMultiScale( img1, tmpobjects,
parameters.scaleFactor, parameters.minNeighbors, 0 parameters.scaleFactor, parameters.minNeighbors, 0
|CV_HAAR_FIND_BIGGEST_OBJECT |CV_HAAR_FIND_BIGGEST_OBJECT
|CV_HAAR_SCALE_IMAGE |CV_HAAR_SCALE_IMAGE
, ,
Size(d,d), Size(d,d),
max_objectSize max_objectSize
); );*/
for(size_t i=0; i < tmpobjects.size(); i++) { for(size_t i=0; i < tmpobjects.size(); i++) {
Rect curres(tmpobjects[i].tl() + r1.tl(), tmpobjects[i].size()); Rect curres(tmpobjects[i].tl() + r1.tl(), tmpobjects[i].size());
...@@ -831,10 +809,7 @@ void DetectionBasedTracker::detectInRegion(const Mat& img, const Rect& r, vector ...@@ -831,10 +809,7 @@ void DetectionBasedTracker::detectInRegion(const Mat& img, const Rect& r, vector
bool DetectionBasedTracker::setParameters(const Parameters& params) bool DetectionBasedTracker::setParameters(const Parameters& params)
{ {
if ( (params.minObjectSize <= 0) if ( params.maxTrackLifetime < 0 )
|| (params.maxObjectSize < 0)
|| (params.scaleFactor <= 1.0)
|| (params.maxTrackLifetime < 0) )
{ {
LOGE("DetectionBasedTracker::setParameters: ERROR: wrong parameters value"); LOGE("DetectionBasedTracker::setParameters: ERROR: wrong parameters value");
return false; return false;
......
#include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur
#include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar)
#include <opencv2/highgui/highgui.hpp> // OpenCV window I/O
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/contrib/detection_based_tracker.hpp>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
using namespace cv;
const string WindowName = "Face Detection example";
class CascadeDetectorAdapter: public DetectionBasedTracker::IDetector
{
public:
CascadeDetectorAdapter(cv::Ptr<cv::CascadeClassifier> detector):
Detector(detector)
{
CV_Assert(!detector.empty());
}
void detect(const cv::Mat &Image, std::vector<cv::Rect> &objects)
{
Detector->detectMultiScale(Image, objects, ScaleFactor, MinNeighbours, 0, MinObjSize, MaxObjSize);
}
virtual ~CascadeDetectorAdapter()
{}
private:
CascadeDetectorAdapter();
cv::Ptr<cv::CascadeClassifier> Detector;
};
int main(int argc, char* argv[])
{
namedWindow(WindowName);
VideoCapture VideoStream(0);
if (!VideoStream.isOpened())
{
printf("Error: Cannot open video stream from camera\n");
return 1;
}
std::string cascadeFrontalfilename = "../../data/lbpcascades/lbpcascade_frontalface.xml";
cv::Ptr<cv::CascadeClassifier> cascade = new cv::CascadeClassifier(cascadeFrontalfilename);
cv::Ptr<DetectionBasedTracker::IDetector> MainDetector = new CascadeDetectorAdapter(cascade);
cascade = new cv::CascadeClassifier(cascadeFrontalfilename);
cv::Ptr<DetectionBasedTracker::IDetector> TrackingDetector = new CascadeDetectorAdapter(cascade);
DetectionBasedTracker::Parameters params;
DetectionBasedTracker Detector(MainDetector, TrackingDetector, params);
if (!Detector.run())
{
printf("Error: Detector initialization failed\n");
return 2;
}
Mat ReferenceFrame;
Mat GrayFrame;
vector<Rect> Faces;
while(true)
{
VideoStream >> ReferenceFrame;
cvtColor(ReferenceFrame, GrayFrame, COLOR_RGB2GRAY);
Detector.process(GrayFrame);
Detector.getObjects(Faces);
for (size_t i = 0; i < Faces.size(); i++)
{
rectangle(ReferenceFrame, Faces[i], CV_RGB(0,255,0));
}
imshow(WindowName, ReferenceFrame);
if (cvWaitKey(30) >= 0) break;
}
Detector.stop();
return 0;
}
...@@ -43,8 +43,6 @@ ...@@ -43,8 +43,6 @@
#define LOGE(...) do{} while(0) #define LOGE(...) do{} while(0)
#endif #endif
using namespace cv; using namespace cv;
using namespace std; using namespace std;
...@@ -63,9 +61,31 @@ static void usage() ...@@ -63,9 +61,31 @@ static void usage()
LOGE0("\t (e.g.\"opencv/data/lbpcascades/lbpcascade_frontalface.xml\" "); LOGE0("\t (e.g.\"opencv/data/lbpcascades/lbpcascade_frontalface.xml\" ");
} }
class CascadeDetectorAdapter: public DetectionBasedTracker::IDetector
{
public:
CascadeDetectorAdapter(cv::Ptr<cv::CascadeClassifier> detector):
Detector(detector)
{
CV_Assert(!detector.empty());
}
void detect(const cv::Mat &Image, std::vector<cv::Rect> &objects)
{
Detector->detectMultiScale(Image, objects, 1.1, 3, 0, MinObjSize, MaxObjSize);
}
virtual ~CascadeDetectorAdapter()
{}
private:
CascadeDetectorAdapter();
cv::Ptr<cv::CascadeClassifier> Detector;
};
static int test_FaceDetector(int argc, char *argv[]) static int test_FaceDetector(int argc, char *argv[])
{ {
if (argc < 4) { if (argc < 4)
{
usage(); usage();
return -1; return -1;
} }
...@@ -80,12 +100,14 @@ static int test_FaceDetector(int argc, char *argv[]) ...@@ -80,12 +100,14 @@ static int test_FaceDetector(int argc, char *argv[])
vector<Mat> images; vector<Mat> images;
{ {
char filename[256]; char filename[256];
for(int n=1; ; n++) { for(int n=1; ; n++)
{
snprintf(filename, sizeof(filename), filepattern, n); snprintf(filename, sizeof(filename), filepattern, n);
LOGD("filename='%s'", filename); LOGD("filename='%s'", filename);
Mat m0; Mat m0;
m0=imread(filename); m0=imread(filename);
if (m0.empty()) { if (m0.empty())
{
LOGI0("Cannot read the file --- break"); LOGI0("Cannot read the file --- break");
break; break;
} }
...@@ -94,10 +116,15 @@ static int test_FaceDetector(int argc, char *argv[]) ...@@ -94,10 +116,15 @@ static int test_FaceDetector(int argc, char *argv[])
LOGD("read %d images", (int)images.size()); LOGD("read %d images", (int)images.size());
} }
DetectionBasedTracker::Parameters params;
std::string cascadeFrontalfilename=cascadefile; std::string cascadeFrontalfilename=cascadefile;
cv::Ptr<cv::CascadeClassifier> cascade = new cv::CascadeClassifier(cascadeFrontalfilename);
cv::Ptr<DetectionBasedTracker::IDetector> MainDetector = new CascadeDetectorAdapter(cascade);
cascade = new cv::CascadeClassifier(cascadeFrontalfilename);
cv::Ptr<DetectionBasedTracker::IDetector> TrackingDetector = new CascadeDetectorAdapter(cascade);
DetectionBasedTracker fd(cascadeFrontalfilename, params); DetectionBasedTracker::Parameters params;
DetectionBasedTracker fd(MainDetector, TrackingDetector, params);
fd.run(); fd.run();
...@@ -108,12 +135,13 @@ static int test_FaceDetector(int argc, char *argv[]) ...@@ -108,12 +135,13 @@ static int test_FaceDetector(int argc, char *argv[])
double freq=getTickFrequency(); double freq=getTickFrequency();
int num_images=images.size(); int num_images=images.size();
for(int n=1; n <= num_images; n++) { for(int n=1; n <= num_images; n++)
{
int64 tcur=getTickCount(); int64 tcur=getTickCount();
int64 dt=tcur-tprev; int64 dt=tcur-tprev;
tprev=tcur; tprev=tcur;
double t_ms=((double)dt)/freq * 1000.0; double t_ms=((double)dt)/freq * 1000.0;
LOGD("\n\nSTEP n=%d from prev step %f ms\n\n", n, t_ms); LOGD("\n\nSTEP n=%d from prev step %f ms\n", n, t_ms);
m=images[n-1]; m=images[n-1];
CV_Assert(! m.empty()); CV_Assert(! m.empty());
cvtColor(m, gray, CV_BGR2GRAY); cvtColor(m, gray, CV_BGR2GRAY);
...@@ -123,11 +151,8 @@ static int test_FaceDetector(int argc, char *argv[]) ...@@ -123,11 +151,8 @@ static int test_FaceDetector(int argc, char *argv[])
vector<Rect> result; vector<Rect> result;
fd.getObjects(result); fd.getObjects(result);
for(size_t i=0; i < result.size(); i++)
{
for(size_t i=0; i < result.size(); i++) {
Rect r=result[i]; Rect r=result[i];
CV_Assert(r.area() > 0); CV_Assert(r.area() > 0);
Point tl=r.tl(); Point tl=r.tl();
...@@ -136,14 +161,14 @@ static int test_FaceDetector(int argc, char *argv[]) ...@@ -136,14 +161,14 @@ static int test_FaceDetector(int argc, char *argv[])
rectangle(m, tl, br, color, 3); rectangle(m, tl, br, color, 3);
} }
} }
char outfilename[256];
for(int n=1; n <= num_images; n++)
{ {
char outfilename[256]; snprintf(outfilename, sizeof(outfilename), outfilepattern, n);
for(int n=1; n <= num_images; n++) { LOGD("outfilename='%s'", outfilename);
snprintf(outfilename, sizeof(outfilename), outfilepattern, n); m=images[n-1];
LOGD("outfilename='%s'", outfilename); imwrite(outfilename, m);
m=images[n-1];
imwrite(outfilename, m);
}
} }
fd.stop(); fd.stop();
...@@ -151,8 +176,6 @@ static int test_FaceDetector(int argc, char *argv[]) ...@@ -151,8 +176,6 @@ static int test_FaceDetector(int argc, char *argv[])
return 0; return 0;
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
return test_FaceDetector(argc, argv); return test_FaceDetector(argc, argv);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment