Commit 094b9a99 by guanghui.cui

1.添加日志 2.修复多线程同步bug

parent b73fa348
...@@ -15,6 +15,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Executables", "Executables" ...@@ -15,6 +15,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Executables", "Executables"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FaceLandmarkVid", "exe\FaceLandmarkVid\FaceLandmarkVid.vcxproj", "{34032CF2-1B99-4A25-9050-E9C13DD4CD0A}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FaceLandmarkVid", "exe\FaceLandmarkVid\FaceLandmarkVid.vcxproj", "{34032CF2-1B99-4A25-9050-E9C13DD4CD0A}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FaceLandmarkVidMulti", "exe\FaceLandmarkVidMulti\FaceLandmarkVidMulti.vcxproj", "{C3FAF36F-44BC-4454-87C2-C5106575FE50}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32 Debug|Win32 = Debug|Win32
...@@ -55,6 +57,14 @@ Global ...@@ -55,6 +57,14 @@ Global
{34032CF2-1B99-4A25-9050-E9C13DD4CD0A}.Release|Win32.Build.0 = Release|Win32 {34032CF2-1B99-4A25-9050-E9C13DD4CD0A}.Release|Win32.Build.0 = Release|Win32
{34032CF2-1B99-4A25-9050-E9C13DD4CD0A}.Release|x64.ActiveCfg = Release|x64 {34032CF2-1B99-4A25-9050-E9C13DD4CD0A}.Release|x64.ActiveCfg = Release|x64
{34032CF2-1B99-4A25-9050-E9C13DD4CD0A}.Release|x64.Build.0 = Release|x64 {34032CF2-1B99-4A25-9050-E9C13DD4CD0A}.Release|x64.Build.0 = Release|x64
{C3FAF36F-44BC-4454-87C2-C5106575FE50}.Debug|Win32.ActiveCfg = Debug|Win32
{C3FAF36F-44BC-4454-87C2-C5106575FE50}.Debug|Win32.Build.0 = Debug|Win32
{C3FAF36F-44BC-4454-87C2-C5106575FE50}.Debug|x64.ActiveCfg = Debug|x64
{C3FAF36F-44BC-4454-87C2-C5106575FE50}.Debug|x64.Build.0 = Debug|x64
{C3FAF36F-44BC-4454-87C2-C5106575FE50}.Release|Win32.ActiveCfg = Release|Win32
{C3FAF36F-44BC-4454-87C2-C5106575FE50}.Release|Win32.Build.0 = Release|Win32
{C3FAF36F-44BC-4454-87C2-C5106575FE50}.Release|x64.ActiveCfg = Release|x64
{C3FAF36F-44BC-4454-87C2-C5106575FE50}.Release|x64.Build.0 = Release|x64
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
...@@ -64,5 +74,6 @@ Global ...@@ -64,5 +74,6 @@ Global
{BDC1D107-DE17-4705-8E7B-CDDE8BFB2BF8} = {99FEBA13-BDDF-4076-B57E-D8EF4076E20D} {BDC1D107-DE17-4705-8E7B-CDDE8BFB2BF8} = {99FEBA13-BDDF-4076-B57E-D8EF4076E20D}
{0E7FC556-0E80-45EA-A876-DDE4C2FEDCD7} = {99FEBA13-BDDF-4076-B57E-D8EF4076E20D} {0E7FC556-0E80-45EA-A876-DDE4C2FEDCD7} = {99FEBA13-BDDF-4076-B57E-D8EF4076E20D}
{34032CF2-1B99-4A25-9050-E9C13DD4CD0A} = {9961DDAC-BE6E-4A6E-8EEF-FFC7D67BD631} {34032CF2-1B99-4A25-9050-E9C13DD4CD0A} = {9961DDAC-BE6E-4A6E-8EEF-FFC7D67BD631}
{C3FAF36F-44BC-4454-87C2-C5106575FE50} = {9961DDAC-BE6E-4A6E-8EEF-FFC7D67BD631}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal
...@@ -69,6 +69,9 @@ ...@@ -69,6 +69,9 @@
#include <opencv2/imgproc.hpp> #include <opencv2/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp> #include <opencv2/highgui/highgui.hpp>
#include "easylogging++.h"
INITIALIZE_EASYLOGGINGPP
#include "jsonAnalysis.h" #include "jsonAnalysis.h"
#include "../curl/curl.h" #include "../curl/curl.h"
#include "utility/utilCommonAPI.h" #include "utility/utilCommonAPI.h"
...@@ -88,17 +91,17 @@ struct faceModel ...@@ -88,17 +91,17 @@ struct faceModel
}; };
#define INFO_STREAM( stream ) \ #define INFO_STREAM( stream ) \
std::cout << stream << std::endl LOG(INFO) << stream
#define WARN_STREAM( stream ) \ #define WARN_STREAM( stream ) \
std::cout << "Warning: " << stream << std::endl LOG(INFO) << "Warning: " << stream
#define ERROR_STREAM( stream ) \ #define ERROR_STREAM( stream ) \
std::cout << "Error: " << stream << std::endl LOG(INFO) << "Error: " << stream
static void printErrorAndAbort( const std::string & error ) static void printErrorAndAbort( const std::string & error )
{ {
std::cout << error << std::endl; LOG(INFO) << error;
abort(); abort();
} }
...@@ -217,17 +220,21 @@ class serv : public dlib::server ...@@ -217,17 +220,21 @@ class serv : public dlib::server
char tmpJson[1000]; char tmpJson[1000];
int n = con.read(tmpJson, 1000); int n = con.read(tmpJson, 1000);
tmpJson[n] = '\0'; tmpJson[n] = '\0';
cout << "recived data:" << tmpJson << endl; LOG(INFO) << "recived data:" << tmpJson;
int fm_cmd = SocketRequestJson(tmpJson); int fm_cmd = SocketRequestJson(tmpJson);
if (2002 == fm_cmd) { if (2002 == fm_cmd) {
bTakePic = true; bTakePic = true;
DWORD dw = WaitForSingleObject(g_hSemaphore,10000 /*INFINITE*/); DWORD dw = WaitForSingleObject(g_hSemaphore,5000 /*INFINITE*/);
if (dw == WAIT_TIMEOUT) { if (dw == WAIT_TIMEOUT) {
LOG(INFO) << "timeout";
socketBackJson = GetSocketResultJson(99, "timeout", ""); socketBackJson = GetSocketResultJson(99, "timeout", "");
//ReleaseSemaphore(g_hSemaphore, 1, NULL);
//WaitForSingleObject(g_hSemaphore, INFINITE);
bTakePic = false;
} }
//----------- //-----------
cout << "-----------------------------socket back data:" << socketBackJson.data() << endl; LOG(INFO) << "-----------------------------socket back data:" << socketBackJson.data();
con.write(socketBackJson.data(), socketBackJson.length()); con.write(socketBackJson.data(), socketBackJson.length());
} }
...@@ -252,7 +259,7 @@ void dlibServer() ...@@ -252,7 +259,7 @@ void dlibServer()
} }
catch (exception& e) catch (exception& e)
{ {
cout << e.what() << endl; LOG(INFO) << e.what();
} }
} }
...@@ -266,7 +273,7 @@ int main (int argc, char **argv) ...@@ -266,7 +273,7 @@ int main (int argc, char **argv)
); );
if (NULL == g_hSemaphore) if (NULL == g_hSemaphore)
{ {
cout << "create hSemaphore failed! error_code:" << GetLastError() << endl; LOG(INFO) << "create hSemaphore failed! error_code:" << GetLastError();
return 0; return 0;
} }
WaitForSingleObject(g_hSemaphore, INFINITE); WaitForSingleObject(g_hSemaphore, INFINITE);
...@@ -586,9 +593,9 @@ int main (int argc, char **argv) ...@@ -586,9 +593,9 @@ int main (int argc, char **argv)
} }
//std::string strPathImg="E:\\tempImg.jpg"; //std::string strPathImg="E:\\tempImg.jpg";
if (vecFaceModel.size() > 0&& bTakePic&&vecFaceModel[posMax].dAcc < accuracy) { if (vecFaceModel.size() > 0&& bTakePic&&vecFaceModel[posMax].dAcc < accuracy) {
cout << strPathImg.data() << endl; LOG(INFO) << strPathImg.data();
socketBackJson.clear(); socketBackJson.clear();
cout << "+++++++attr:" << vecFaceModel[posMax].rect[0] << " " << vecFaceModel[posMax].rect[1] << " " << vecFaceModel[posMax].rect[2] << " " << vecFaceModel[posMax].rect[3] << " "<< vecFaceModel[posMax].dAcc<<endl; LOG(INFO) << "+++++++attr:" << vecFaceModel[posMax].rect[0] << " " << vecFaceModel[posMax].rect[1] << " " << vecFaceModel[posMax].rect[2] << " " << vecFaceModel[posMax].rect[3] << " "<< vecFaceModel[posMax].dAcc;
int rcX = captured_image.cols*vecFaceModel[posMax].rect[0]; int rcX = captured_image.cols*vecFaceModel[posMax].rect[0];
int rcY = captured_image.rows*vecFaceModel[posMax].rect[1]; int rcY = captured_image.rows*vecFaceModel[posMax].rect[1];
int rcWidth = captured_image.cols*vecFaceModel[posMax].rect[2]; int rcWidth = captured_image.cols*vecFaceModel[posMax].rect[2];
...@@ -598,10 +605,8 @@ int main (int argc, char **argv) ...@@ -598,10 +605,8 @@ int main (int argc, char **argv)
rcWidth = rcWidth + 50 < captured_image.cols ? rcWidth + 50 : rcWidth; rcWidth = rcWidth + 50 < captured_image.cols ? rcWidth + 50 : rcWidth;
rcHeight = rcHeight + 80 < captured_image.rows ? rcHeight + 80 : rcHeight; rcHeight = rcHeight + 80 < captured_image.rows ? rcHeight + 80 : rcHeight;
if (rcX < 0) rcX = rcX < 0 ? 0 : rcX;
rcX = 0; rcY = rcY < 0 ? 0 : rcY;
if (rcY < 0)
rcY = 0;
if (rcX + rcWidth > captured_image.cols) { if (rcX + rcWidth > captured_image.cols) {
rcWidth = captured_image.cols - rcX; rcWidth = captured_image.cols - rcX;
} }
...@@ -622,10 +627,10 @@ int main (int argc, char **argv) ...@@ -622,10 +627,10 @@ int main (int argc, char **argv)
postResponseStr.clear(); postResponseStr.clear();
auto res = curl_post_req(strUrl, strPathImg, postResponseStr); auto res = curl_post_req(strUrl, strPathImg, postResponseStr);
if (res != CURLE_OK) if (res != CURLE_OK)
cerr << "curl_easy_perform() failed: " + string(curl_easy_strerror(res)) << endl; LOG(INFO) << "curl_easy_perform() failed: " + string(curl_easy_strerror(res));
else { else {
postResponseStr = UnicodeToAscii(Utf8ToUnicode(postResponseStr)); postResponseStr = UnicodeToAscii(Utf8ToUnicode(postResponseStr));
cout << "utf8 to ascii:" << postResponseStr << endl; LOG(INFO) << "utf8 to ascii:" << postResponseStr;
} }
sServerResponse response = GetServerResultData(postResponseStr.data()); sServerResponse response = GetServerResultData(postResponseStr.data());
...@@ -647,11 +652,11 @@ int main (int argc, char **argv) ...@@ -647,11 +652,11 @@ int main (int argc, char **argv)
status = 31; status = 31;
msg = "no"; msg = "no";
} }
cout << "confidence:" << response.vecUser[0].confidence.data() << endl; LOG(INFO) << "confidence:" << response.vecUser[0].confidence.data();
socketBackJson = GetSocketResultJson(status, msg.data(), phone.data()); socketBackJson = GetSocketResultJson(status, msg.data(), phone.data());
cout << "soceket back json:" << socketBackJson.data() << endl; LOG(INFO) << "soceket back json:" << socketBackJson.data();
} }
cout << "---------------------------release semaphore" << endl; LOG(INFO) << "---------------------------release semaphore";
ReleaseSemaphore(g_hSemaphore, 1, NULL); ReleaseSemaphore(g_hSemaphore, 1, NULL);
} }
//------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------
......
...@@ -156,6 +156,7 @@ ...@@ -156,6 +156,7 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="easylogging++.cc" />
<ClCompile Include="FaceLandmarkVidMulti.cpp" /> <ClCompile Include="FaceLandmarkVidMulti.cpp" />
<ClCompile Include="jsonAnalysis.cpp" /> <ClCompile Include="jsonAnalysis.cpp" />
<ClCompile Include="utility\iniOperation.cpp" /> <ClCompile Include="utility\iniOperation.cpp" />
...@@ -168,6 +169,7 @@ ...@@ -168,6 +169,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="CommonStruct.h" /> <ClInclude Include="CommonStruct.h" />
<ClInclude Include="easylogging++.h" />
<ClInclude Include="jsonAnalysis.h" /> <ClInclude Include="jsonAnalysis.h" />
<ClInclude Include="utility\iniOperation.h" /> <ClInclude Include="utility\iniOperation.h" />
<ClInclude Include="utility\utilCommonAPI.h" /> <ClInclude Include="utility\utilCommonAPI.h" />
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<Filter>utility</Filter> <Filter>utility</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="jsonAnalysis.cpp" /> <ClCompile Include="jsonAnalysis.cpp" />
<ClCompile Include="easylogging++.cc" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Filter Include="utility"> <Filter Include="utility">
...@@ -24,5 +25,6 @@ ...@@ -24,5 +25,6 @@
</ClInclude> </ClInclude>
<ClInclude Include="CommonStruct.h" /> <ClInclude Include="CommonStruct.h" />
<ClInclude Include="jsonAnalysis.h" /> <ClInclude Include="jsonAnalysis.h" />
<ClInclude Include="easylogging++.h" />
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment