Skip to content

Commit

Permalink
Added onlyErrorLogs cmd line argument
Browse files Browse the repository at this point in the history
  • Loading branch information
hudrima1 committed Dec 9, 2023
1 parent be40868 commit 7c03129
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 62 deletions.
9 changes: 9 additions & 0 deletions apps/app_demo_slproject/glfw/AppDemoMainGLFW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,15 @@ int main(int argc, char* argv[])
for (int i = 0; i < argc; i++)
cmdLineArgs.push_back(SLstring(argv[i]));

// parse cmd line arguments
for (int i=1; i<cmdLineArgs.size(); ++i)
{
if (cmdLineArgs[i] == "-onlyErrorLogs")
{
Utils::onlyErrorLogs = true;
}
}

scrWidth = 1280;
scrHeight = 720;
scrWdivH = (float)scrWidth / (float)scrHeight;
Expand Down
58 changes: 39 additions & 19 deletions modules/cv/source/CVTrackedFaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ CVTrackedFaces::CVTrackedFaces(string faceClassifierFilename,
Utils::exitMsg("SLProject", msg.c_str(), __LINE__, __FILE__);
}

_facemark = cv::face::FacemarkLBF::create();
cv::face::FacemarkLBF::Params facemarkParams;
facemarkParams.verbose = false; // no logging
_facemark = cv::face::FacemarkLBF::create(facemarkParams);
_facemark->loadModel(faceMarkModelFilename);

// Init averaged 2D facial landmark points
Expand Down Expand Up @@ -117,7 +119,13 @@ bool CVTrackedFaces::track(CVMat imageGray,
int max = (int)((float)imageGray.rows * 0.8f); // the smaller max the faster
CVSize minSize(min, min);
CVSize maxSize(max, max);
_faceDetector->detectMultiScale(imageGray, faces, 1.05, 3, 0, minSize, maxSize);
_faceDetector->detectMultiScale(imageGray,
faces,
1.05,
3,
0,
minSize,
maxSize);

// Enlarge the face rect at the bottom to cover also the chin
for (auto& face : faces)
Expand All @@ -130,32 +138,33 @@ bool CVTrackedFaces::track(CVMat imageGray,
// Detect Landmarks //
//////////////////////

CVVVPoint2f landmarks;
bool foundLandmarks = _facemark->fit(imageBgr, faces, landmarks);
CVVVPoint2f lm;
bool foundLandmarks = _facemark->fit(imageBgr, faces, lm);

float time3MS = _timer.elapsedTimeInMilliSec();
CVTracked::detect2TimesMS.set(time3MS - time2MS);
CVTracked::detectTimesMS.set(time3MS - startMS);

if (foundLandmarks)
{
for (unsigned long i = 0; i < landmarks.size(); i++)
for (unsigned long i = 0; i < lm.size(); i++)
{
// Landmark indexes from
// https://cdn-images-1.medium.com/max/1600/1*AbEg31EgkbXSQehuNJBlWg.png
_avgPosePoints2D[0].set(CVVec2f(landmarks[i][30].x, landmarks[i][30].y)); // Nose tip
_avgPosePoints2D[1].set(CVVec2f(landmarks[i][31].x, landmarks[i][31].y)); // Nose hole left
_avgPosePoints2D[2].set(CVVec2f(landmarks[i][35].x, landmarks[i][35].y)); // Nose hole right
_avgPosePoints2D[3].set(CVVec2f(landmarks[i][36].x, landmarks[i][36].y)); // Left eye left corner
_avgPosePoints2D[4].set(CVVec2f(landmarks[i][39].x, landmarks[i][39].y)); // Left eye right corner
_avgPosePoints2D[5].set(CVVec2f(landmarks[i][42].x, landmarks[i][42].y)); // Right eye left corner
_avgPosePoints2D[6].set(CVVec2f(landmarks[i][45].x, landmarks[i][45].y)); // Right eye right corner
_avgPosePoints2D[7].set(CVVec2f(landmarks[i][48].x, landmarks[i][48].y)); // Left mouth corner
_avgPosePoints2D[8].set(CVVec2f(landmarks[i][54].x, landmarks[i][54].y)); // Right mouth corner
_avgPosePoints2D[0].set(CVVec2f(lm[i][30].x, lm[i][30].y)); // Nose tip
_avgPosePoints2D[1].set(CVVec2f(lm[i][31].x, lm[i][31].y)); // Nose hole left
_avgPosePoints2D[2].set(CVVec2f(lm[i][35].x, lm[i][35].y)); // Nose hole right
_avgPosePoints2D[3].set(CVVec2f(lm[i][36].x, lm[i][36].y)); // Left eye left corner
_avgPosePoints2D[4].set(CVVec2f(lm[i][39].x, lm[i][39].y)); // Left eye right corner
_avgPosePoints2D[5].set(CVVec2f(lm[i][42].x, lm[i][42].y)); // Right eye left corner
_avgPosePoints2D[6].set(CVVec2f(lm[i][45].x, lm[i][45].y)); // Right eye right corner
_avgPosePoints2D[7].set(CVVec2f(lm[i][48].x, lm[i][48].y)); // Left mouth corner
_avgPosePoints2D[8].set(CVVec2f(lm[i][54].x, lm[i][54].y)); // Right mouth corner

// Convert averaged 2D points to OpenCV points2d
for (unsigned long p = 0; p < _avgPosePoints2D.size(); p++)
_cvPosePoints2D[p] = CVPoint2f(_avgPosePoints2D[p].average()[0], _avgPosePoints2D[p].average()[1]);
_cvPosePoints2D[p] = CVPoint2f(_avgPosePoints2D[p].average()[0],
_avgPosePoints2D[p].average()[1]);

// delaunayTriangulate(imageBgr, landmarks[i], drawDetection);

Expand All @@ -166,15 +175,26 @@ bool CVTrackedFaces::track(CVMat imageGray,
if (_drawDetection)
{
// Draw rectangle of detected face
cv::rectangle(imageBgr, faces[i], cv::Scalar(255, 0, 0), 2);
cv::rectangle(imageBgr,
faces[i],
cv::Scalar(255, 0, 0),
2);

// Draw detected landmarks
for (auto& j : landmarks[i])
cv::circle(imageBgr, j, 2, cv::Scalar(0, 0, 255), -1);
for (auto& j : lm[i])
cv::circle(imageBgr,
j,
2,
cv::Scalar(0, 0, 255),
-1);

// Draw averaged face points used for pose estimation
for (unsigned long p = 0; p < _avgPosePoints2D.size(); p++)
cv::circle(imageBgr, _cvPosePoints2D[p], 5, cv::Scalar(0, 255, 0), 1);
cv::circle(imageBgr,
_cvPosePoints2D[p],
5,
cv::Scalar(0, 255, 0),
1);
}

// Do pose estimation for the first face found
Expand Down
3 changes: 1 addition & 2 deletions modules/sl/source/SLSceneView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1496,12 +1496,11 @@ SLbool SLSceneView::onDoubleClick(SLMouseButton button,

_s->root3D()->hitRec(&pickRay);
if (pickRay.hitNode)
cout << "NODE HIT: " << pickRay.hitNode->name() << endl;
SL_LOG("NODE HIT: %s", pickRay.hitNode->name().c_str());
}

if (pickRay.length < FLT_MAX)
{

if (mod & K_shift)
{
_s->selectNodeMesh(pickRay.hitNode, pickRay.hitMesh);
Expand Down
4 changes: 0 additions & 4 deletions modules/sl/source/gl/SLGLProgramGenerated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1856,10 +1856,6 @@ void SLGLProgramGenerated::buildProgramCode(SLMaterial* mat,
SLVLight* lights,
SLbool supportGPUSkinning)
{
if (mat->name() == "IBLMat")
{
std::cout << "build program code for IBLMat" << std::endl;
}
assert(mat && "No material pointer passed!");
assert(!lights->empty() && "No lights passed!");
assert(_shaders.size() > 1 &&
Expand Down
6 changes: 3 additions & 3 deletions modules/sl/source/input/SLAssimpImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1488,9 +1488,9 @@ SLstring SLAssimpImporter::checkFilePath(const SLstring& modelPath,

if (showWarning)
{
SLstring msg = "SLAssimpImporter: Texture file not found: \n" + aiTexFile +
"\non model path: " + modelPath + "\n";
SL_WARN_MSG(msg.c_str());
SLstring msg = "WARNING: SLAssimpImporter: Texture file not found: \n" +
aiTexFile + "\non model path: " + modelPath + "\n";
SL_LOG(msg.c_str());
}

// Return path for texture not found image;
Expand Down
55 changes: 21 additions & 34 deletions modules/utils/source/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ namespace Utils
///////////////////////////////
// Global variables //
///////////////////////////////

std::unique_ptr<CustomLog> customLog;

bool onlyErrorLogs = false;

///////////////////////////////
// String Handling Functions //
///////////////////////////////
Expand Down Expand Up @@ -141,7 +144,7 @@ string trimLeftString(const string& s, const string& drop)
return r;
}
//-----------------------------------------------------------------------------
// Splits an input string at a delimeter character into a string vector
// Splits an input string at a delimiter character into a string vector
void splitString(const string& s,
char delimiter,
vector<string>& splits)
Expand All @@ -159,7 +162,7 @@ void splitString(const string& s,
}
}
//-----------------------------------------------------------------------------
// Replaces in the source string the from string by the to string
// Replaces in the source-string the from-string by the to-string
void replaceString(string& source,
const string& from,
const string& to)
Expand Down Expand Up @@ -1115,6 +1118,9 @@ void log(const char* tag, const char* format, ...)
if (customLog)
customLog->post(msg);

if (Utils::onlyErrorLogs)
return;

#if defined(ANDROID) || defined(ANDROID_NDK)
__android_log_print(ANDROID_LOG_INFO, tag, msg);
#else
Expand All @@ -1128,28 +1134,7 @@ void exitMsg(const char* tag,
const int line,
const char* file)
{
#if defined(ANDROID) || defined(ANDROID_NDK)
__android_log_print(ANDROID_LOG_FATAL,
tag,
"Exit %s at line %d in %s\n",
msg,
line,
file);
#elif defined(__EMSCRIPTEN__)
std::cerr << "--------------------------------\n"
<< "Fatal Error\n"
<< "Tag: " << tag << '\n'
<< "Location: " << file << ":" << line << '\n'
<< "Message: " << msg << '\n'
<< "--------------------------------" << std::endl;
#else
log(tag,
"Exit %s at line %d in %s\n",
msg,
line,
file);
#endif

errorMsg(tag, msg, line, file);
exit(-1);
}
//-----------------------------------------------------------------------------
Expand All @@ -1167,11 +1152,12 @@ void warnMsg(const char* tag,
line,
file);
#else
log(tag,
"Warning %s at line %d in %s\n",
msg,
line,
file);
std::cout << "--------------------------------\n"
<< "Warning:\n"
<< "Tag: " << tag << '\n'
<< "Location: " << file << ":" << line << '\n'
<< "Message: " << msg << '\n'
<< "--------------------------------" << std::endl;
#endif
}
//-----------------------------------------------------------------------------
Expand All @@ -1189,11 +1175,12 @@ void errorMsg(const char* tag,
line,
file);
#else
log(tag,
"Error %s at line %d in %s\n",
msg,
line,
file);
std::cout << "--------------------------------\n"
<< "Error:\n"
<< "Tag: " << tag << '\n'
<< "Location: " << file << ":" << line << '\n'
<< "Message: " << msg << '\n'
<< "--------------------------------" << std::endl;
#endif
}
//-----------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions modules/utils/source/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ string findFile(const string& filename,
//! will also output into this file. Instantiate it with initFileLog function.
static std::unique_ptr<FileLog> fileLog;

//! if this flag is set to true all calls to log get ignored
extern bool onlyErrorLogs;

//! Instantiates FileLog instance
void initFileLog(const std::string& logDir, bool forceFlush);

Expand Down

0 comments on commit 7c03129

Please sign in to comment.