Add face rectangle to JSON & test single image scan

This commit is contained in:
Ruben 2017-11-16 20:12:29 +01:00
parent 019498ea1f
commit 6e6415433f
1 changed files with 38 additions and 9 deletions

View File

@ -22,6 +22,30 @@ using namespace affdex;
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::stringstream ss;
@ -30,11 +54,12 @@ std::string getAsJson(int framenr, const std::map<FaceId, Face> faces, const dou
ss << "'faces':[";
int i(0);
for (auto & face_id_pair : faces)
{
Face f = face_id_pair.second;
if(i > 0) { ss << ","; }
i++;
@ -78,7 +103,13 @@ std::string getAsJson(int framenr, const std::map<FaceId, Face> faces, const dou
ss << "'" << expression << "':" << (*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 << "'id':"<< f.id;
ss << "}";
@ -240,7 +271,7 @@ int main(int argsc, char ** argsv)
std::cerr << "Failed to read frame from webcam! " << std::endl;
break;
}*/
std::string infile = "/home/crowd/capt0000.jpg";
std::string infile = "/home/crowd/IMG_0011.JPG";
cv::Mat img = imread(infile, 1);
//~ imread(img);
@ -254,11 +285,10 @@ int main(int argsc, char ** argsv)
capture_fps = 1.0f / (seconds - last_timestamp);
last_timestamp = seconds;
frameDetector->process(f); //Pass the frame to detector
std::cerr << "test1";
// For each frame processed
if (listenPtr->getDataSize() > 0)
{
std::cerr << "test2";
framenr++;
std::pair<Frame, std::map<FaceId, Face> > dataPoint = listenPtr->getData();
@ -284,16 +314,15 @@ int main(int argsc, char ** argsv)
char buff[100];
snprintf(buff, sizeof(buff), "frame%06d.jpg", framenr);
std::string targetFilename = buff; // convert to std::string
vector<int> compression_params;
compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);
compression_params.push_back(90);
imwrite(targetFilename, img, compression_params);
break;
}
break;
}