Moved logging out of it's own loop, hopefully this fixes the issue with
it not outputting all log lines. recLoop() and detectLoop() will now
update logs synchronously.

The setup.sh script will now include gstreamer and pkg-config. This
should help fix opencv video-io format support.
This commit is contained in:
Maurice ONeal 2022-12-11 21:00:53 -05:00
parent 89129ad3f4
commit 651ec96083
6 changed files with 25 additions and 30 deletions

View File

@ -1,7 +1,8 @@
#!/bin/sh
apt update -y
apt install -y cmake g++ wget unzip git ffmpeg libavcodec-dev libavformat-dev libavutil-dev libswscale-dev
apt install -y pkg-config
apt install -y cmake g++ wget unzip git ffmpeg gstreamer1.0* libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
add-apt-repository -y ppa:ubuntu-toolchain-r/test
apt update -y
apt install -y gcc-10 gcc-10-base gcc-10-doc g++-10

View File

@ -35,7 +35,7 @@ using namespace cv;
using namespace std;
using namespace std::filesystem;
#define APP_VER "1.5.t6"
#define APP_VER "1.5.t7"
#define APP_NAME "Motion Watch"
struct shared_t

View File

@ -39,9 +39,14 @@ string combine(const vector<string> &log)
return ret;
}
void logLoop(shared_t *share)
void wrOutLogs(shared_t *share)
{
string htmlText = "<!DOCTYPE html>\n";
auto recLogFilePath = cleanDir(share->outDir) + "/recording_log.html";
auto detLogFilePath = cleanDir(share->outDir) + "/detection_log.html";
string htmlText = "<!DOCTYPE html>\n";
ofstream recFile(recLogFilePath.c_str());
ofstream detFile(detLogFilePath.c_str());
htmlText += "<html>\n";
htmlText += "<head>\n";
@ -50,23 +55,12 @@ void logLoop(shared_t *share)
htmlText += "<body>\n";
htmlText += "<p>\n";
while (share->logRun && (share->retCode == 0))
{
sleep(10);
recFile << htmlText << combine(share->recLogLines) << "</p>\n</body>\n</html>\n";
detFile << htmlText << combine(share->detLogLines) << "</p>\n</body>\n</html>\n";
recFile.close();
detFile.close();
enforceMaxLogLines(share->recLogLines, share);
enforceMaxLogLines(share->detLogLines, share);
auto recLogFilePath = cleanDir(share->outDir) + "/recording_log.html";
auto detLogFilePath = cleanDir(share->outDir) + "/detection_log.html";
ofstream recFile(recLogFilePath.c_str());
ofstream detFile(detLogFilePath.c_str());
recFile << htmlText << combine(share->recLogLines) << "</p>\n</body>\n</html>";
detFile << htmlText << combine(share->detLogLines) << "</p>\n</body>\n</html>";
recFile.close();
detFile.close();
}
enforceMaxLogLines(share->recLogLines, share);
enforceMaxLogLines(share->detLogLines, share);
}

View File

@ -17,7 +17,7 @@
void recLog(const string &line, shared_t *share);
void detLog(const string &line, shared_t *share);
void logLoop(shared_t *share);
void wrOutLogs(shared_t *share);
void enforceMaxLogLines(vector<string> &log, shared_t *share);
string combine(const vector<string> &log);

View File

@ -16,6 +16,7 @@
void detectLoop(shared_t *share)
{
detLog("detectLoop() -- start", share);
wrOutLogs(share);
vector<string> bufFiles;
@ -55,6 +56,7 @@ void detectLoop(shared_t *share)
while (!bufFiles.empty() && !share->recLoopWait);
detLog("detectLoop() -- finished", share);
wrOutLogs(share);
}
void recLoop(shared_t *share)
@ -62,6 +64,7 @@ void recLoop(shared_t *share)
while (rdConf(share))
{
recLog("recLoop() -- start", share);
wrOutLogs(share);
if (!fileExists("/tmp/mow-lock"))
{
@ -96,6 +99,8 @@ void recLoop(shared_t *share)
th2.join();
wrOutLogs(share);
if (!share->skipCmd)
{
recLog("motion not detected by detect loop.", share);
@ -108,6 +113,7 @@ void recLoop(shared_t *share)
}
recLog("recLoop() -- finished", share);
wrOutLogs(share);
}
share->logRun = false;
@ -143,12 +149,8 @@ int main(int argc, char** argv)
sharedRes.init = true;
sharedRes.logRun = true;
thread th3(logLoop, &sharedRes);
recLoop(&sharedRes);
th3.join();
return sharedRes.retCode;
}

View File

@ -116,9 +116,7 @@ bool moDetect(const string &buffFile, Mat &vidThumb, shared_t *share)
}
else
{
detLog("failed to open buff file: " + buffFile + " for reading.", share);
detLog("check formatting/permissions.", share);
detLog("also check if opencv was compiled with FFMPEG encoding enabled.", share);
detLog("failed to open buff file: " + buffFile + " for reading. check permissions and/or opencv's video-io support (gstreamer/ffmpeg).", share);
}
return mod;