Add face rectangle to JSON & test single image scan
This commit is contained in:
parent
019498ea1f
commit
6e6415433f
1 changed files with 38 additions and 9 deletions
|
@ -22,6 +22,30 @@ using namespace affdex;
|
||||||
using namespace cv;
|
using namespace cv;
|
||||||
|
|
||||||
|
|
||||||
|
FeaturePoint minPoint(VecFeaturePoint points)
|
||||||
|
{
|
||||||
|
VecFeaturePoint::iterator it = points.begin();
|
||||||
|
FeaturePoint ret = *it;
|
||||||
|
for (; it != points.end(); it++)
|
||||||
|
{
|
||||||
|
if (it->x < ret.x) ret.x = it->x;
|
||||||
|
if (it->y < ret.y) ret.y = it->y;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
|
||||||
|
FeaturePoint maxPoint(VecFeaturePoint points)
|
||||||
|
{
|
||||||
|
VecFeaturePoint::iterator it = points.begin();
|
||||||
|
FeaturePoint ret = *it;
|
||||||
|
for (; it != points.end(); it++)
|
||||||
|
{
|
||||||
|
if (it->x > ret.x) ret.x = it->x;
|
||||||
|
if (it->y > ret.y) ret.y = it->y;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
|
||||||
std::string getAsJson(int framenr, const std::map<FaceId, Face> faces, const double timeStamp)
|
std::string getAsJson(int framenr, const std::map<FaceId, Face> faces, const double timeStamp)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
@ -31,6 +55,7 @@ std::string getAsJson(int framenr, const std::map<FaceId, Face> faces, const dou
|
||||||
|
|
||||||
int i(0);
|
int i(0);
|
||||||
|
|
||||||
|
|
||||||
for (auto & face_id_pair : faces)
|
for (auto & face_id_pair : faces)
|
||||||
{
|
{
|
||||||
Face f = face_id_pair.second;
|
Face f = face_id_pair.second;
|
||||||
|
@ -79,6 +104,12 @@ std::string getAsJson(int framenr, const std::map<FaceId, Face> faces, const dou
|
||||||
values++;
|
values++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FeaturePoint tl = minPoint(f.featurePoints);
|
||||||
|
FeaturePoint br = maxPoint(f.featurePoints);
|
||||||
|
|
||||||
|
ss << "'rect':{'x':" << tl.x << ",'y':" << tl.y
|
||||||
|
<< ",'w':" << (br.x - tl.x) << ",'h':" << (br.y - tl.y) << "},";
|
||||||
|
|
||||||
ss << "'ioDistance':"<< f.measurements.interocularDistance << ",";
|
ss << "'ioDistance':"<< f.measurements.interocularDistance << ",";
|
||||||
ss << "'id':"<< f.id;
|
ss << "'id':"<< f.id;
|
||||||
ss << "}";
|
ss << "}";
|
||||||
|
@ -240,7 +271,7 @@ int main(int argsc, char ** argsv)
|
||||||
std::cerr << "Failed to read frame from webcam! " << std::endl;
|
std::cerr << "Failed to read frame from webcam! " << std::endl;
|
||||||
break;
|
break;
|
||||||
}*/
|
}*/
|
||||||
std::string infile = "/home/crowd/capt0000.jpg";
|
std::string infile = "/home/crowd/IMG_0011.JPG";
|
||||||
cv::Mat img = imread(infile, 1);
|
cv::Mat img = imread(infile, 1);
|
||||||
|
|
||||||
//~ imread(img);
|
//~ imread(img);
|
||||||
|
@ -254,11 +285,10 @@ int main(int argsc, char ** argsv)
|
||||||
capture_fps = 1.0f / (seconds - last_timestamp);
|
capture_fps = 1.0f / (seconds - last_timestamp);
|
||||||
last_timestamp = seconds;
|
last_timestamp = seconds;
|
||||||
frameDetector->process(f); //Pass the frame to detector
|
frameDetector->process(f); //Pass the frame to detector
|
||||||
std::cerr << "test1";
|
|
||||||
// For each frame processed
|
// For each frame processed
|
||||||
if (listenPtr->getDataSize() > 0)
|
if (listenPtr->getDataSize() > 0)
|
||||||
{
|
{
|
||||||
std::cerr << "test2";
|
|
||||||
framenr++;
|
framenr++;
|
||||||
|
|
||||||
std::pair<Frame, std::map<FaceId, Face> > dataPoint = listenPtr->getData();
|
std::pair<Frame, std::map<FaceId, Face> > dataPoint = listenPtr->getData();
|
||||||
|
@ -290,10 +320,9 @@ int main(int argsc, char ** argsv)
|
||||||
compression_params.push_back(90);
|
compression_params.push_back(90);
|
||||||
|
|
||||||
imwrite(targetFilename, img, compression_params);
|
imwrite(targetFilename, img, compression_params);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue