Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

Commit

Permalink
Update Main.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
brian8544 committed Jun 9, 2023
1 parent 27656d0 commit 69a024b
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/Main.cpp
Expand Up @@ -41,6 +41,8 @@ void readSettings()
{
Messages::Info("settings.conf is empty or corrupt.");
settingsFile.close();
system("pause");
exit(1); // Use exit(1) to indicate an error
}
std::string line;
while (std::getline(settingsFile, line))
Expand Down Expand Up @@ -77,7 +79,7 @@ std::string getCurrentTime() {
return buffer;
}

void log(const std::string& message) {
void logWrite(const std::string& message) {
std::ofstream logFile(LOGGING_DIR + "/system.log", std::ios::app);
if (logFile.is_open()) {
logFile << getCurrentTime() << " "; // Add current time before the log message
Expand All @@ -87,6 +89,8 @@ void log(const std::string& message) {
}
else {
Messages::Error("Unable to open log file.");
system("pause");
exit(1); // Use exit(1) to indicate an error
}
}

Expand Down Expand Up @@ -126,6 +130,7 @@ void detectAndDraw(cv::Mat& img, cv::CascadeClassifier& cascade, double scale)
if (compareImg.empty())
{
Messages::Error("Failed to read image: " + entry.path().filename().string());
logWrite("Failed to read image: " + entry.path().filename().string());
continue; // Skip to the next image
}

Expand All @@ -144,6 +149,7 @@ void detectAndDraw(cv::Mat& img, cv::CascadeClassifier& cascade, double scale)
catch (const cv::Exception& e)
{
Messages::Error("Error occurred during template matching: " + std::string(e.what()));
logWrite("Error occurred during template matching: " + std::string(e.what()));
continue; // Skip to the next image
}

Expand All @@ -162,7 +168,7 @@ void detectAndDraw(cv::Mat& img, cv::CascadeClassifier& cascade, double scale)
{
// Print other matches to the console
Messages::Info("Other match: " + entry.path().filename().string());
log("Hello World");
logWrite("Other match: " + entry.path().filename().string());
}
}

Expand All @@ -188,6 +194,7 @@ int main(int argc, char** argv)
// Face cascade could not be found
std::system("cls");
Messages::Error("Could not find the face cascade.");
logWrite("Could not find the face cascade.");
std::system("pause");
return -1;
}
Expand All @@ -200,6 +207,7 @@ int main(int argc, char** argv)
{
std::system("cls");
Messages::Error("Error opening camera.");
logWrite("Error opening camera.");
std::system("pause");
return -1;
}
Expand Down Expand Up @@ -235,7 +243,13 @@ int main(int argc, char** argv)
// If the user presses Q, then break from the loop
if (key == 27 || key == 'q' || key == 'Q')
{
break;
//break;
Messages::Info("User has shutdown the application.");
logWrite("User has shutdown the application.");
capture.release();
cv::destroyWindow("Face Detection");
system("pause");
return 0;
}
}

Expand Down

0 comments on commit 69a024b

Please sign in to comment.