Commit b9a054eb by guanghui.cui

添加截图功能

parent 4f158923
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "CvxText.h" #include "CvxText.h"
#include "CommonStruct.h" #include "CommonStruct.h"
#include "utility/utilCommonAPI.h"
//using namespace cv; //using namespace cv;
using namespace std; using namespace std;
...@@ -37,6 +38,7 @@ using namespace std; ...@@ -37,6 +38,7 @@ using namespace std;
#pragma comment(lib, "../lib/freetype.lib") #pragma comment(lib, "../lib/freetype.lib")
#endif #endif
std::vector<dlib::rectangle> _get_rc_detectors(std::vector<TargetInfo> &vecTargets) std::vector<dlib::rectangle> _get_rc_detectors(std::vector<TargetInfo> &vecTargets)
{ {
std::vector<dlib::rectangle> final_dets(vecTargets.size()); std::vector<dlib::rectangle> final_dets(vecTargets.size());
...@@ -45,6 +47,36 @@ std::vector<dlib::rectangle> _get_rc_detectors(std::vector<TargetInfo> &vecTarge ...@@ -45,6 +47,36 @@ std::vector<dlib::rectangle> _get_rc_detectors(std::vector<TargetInfo> &vecTarge
return final_dets; return final_dets;
} }
bool _save_target_img(cv::Mat &img, dlib::rectangle &rc,const char* path)
{
int rcX = rc.left();
int rcY = rc.top();
int rcWidth = rc.width();
int rcHeight = rc.height();
rcX = rcX - 10 > 0 ? rcX - 10 : rcX;
rcY = rcY - 30 > 0 ? rcY - 30 : rcY;
rcWidth = rcWidth + 20 < img.cols ? rcWidth + 20 : rcWidth;
rcHeight = rcHeight + 50 < img.rows ? rcHeight + 50 : rcHeight;
rcX = rcX < 0 ? 0 : rcX;
rcY = rcY < 0 ? 0 : rcY;
if (rcX + rcWidth > img.cols) {
rcWidth = img.cols - rcX;
}
if (rcY + rcHeight > img.rows) {
rcHeight = img.rows - rcY;
}
cv::Rect rect(rcX, rcY, rcWidth, rcHeight);
cv::Mat newPhoto = img(rect);
vector<int> compression_params;
compression_params.push_back(CV_IMWRITE_JPEG_QUALITY); //选择jpeg
compression_params.push_back(100); //在这个填入你要的图片质量
return cv::imwrite(path, newPhoto, compression_params);
}
int main() int main()
{ {
try try
...@@ -63,6 +95,9 @@ int main() ...@@ -63,6 +95,9 @@ int main()
dlib::shape_predictor pose_model; dlib::shape_predictor pose_model;
dlib::deserialize("shape_predictor_68_face_landmarks.dat") >> pose_model; dlib::deserialize("shape_predictor_68_face_landmarks.dat") >> pose_model;
std::string strFilePath = GetProcDir();
//std::string strPathImg = strFilePath + "tmpimg.jpg";
int frame_count = 0; int frame_count = 0;
std::vector<dlib::rectangle> dets; std::vector<dlib::rectangle> dets;
std::vector<TargetInfo> temp_dets; //缓存位置信息 std::vector<TargetInfo> temp_dets; //缓存位置信息
...@@ -140,7 +175,12 @@ int main() ...@@ -140,7 +175,12 @@ int main()
track_dets[i].rc = new_position; track_dets[i].rc = new_position;
track_dets[i].iCode = iReqServerCount; track_dets[i].iCode = iReqServerCount;
//启动查询线程,查询用户信息 //启动查询线程,查询用户信息
std::string strPathImg = strFilePath+"tempimg"+ to_string(i)+".jpg";
cout << "path:" << strPathImg.data() << endl;
_save_target_img(temp, new_position, strPathImg.data());
cout << "cols:" << temp.cols << " rows:" << temp.rows << endl;
cout << "new_position.height():" << new_position.height() << " new_position.width():" << new_position.width() << endl;
cout << "iReqServerCount:" << iReqServerCount << endl; cout << "iReqServerCount:" << iReqServerCount << endl;
iReqServerCount++; iReqServerCount++;
} }
......
...@@ -151,6 +151,8 @@ ...@@ -151,6 +151,8 @@
<ClInclude Include="CvxText.h" /> <ClInclude Include="CvxText.h" />
<ClInclude Include="stdafx.h" /> <ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" /> <ClInclude Include="targetver.h" />
<ClInclude Include="utility\iniOperation.h" />
<ClInclude Include="utility\utilCommonAPI.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="CvxText.cpp" /> <ClCompile Include="CvxText.cpp" />
...@@ -161,6 +163,14 @@ ...@@ -161,6 +163,14 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile> </ClCompile>
<ClCompile Include="utility\iniOperation.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="utility\utilCommonAPI.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
</ClCompile>
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
......
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter> </Filter>
<Filter Include="utility">
<UniqueIdentifier>{9102a2c9-32e0-4435-acec-f1a025594c29}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Text Include="ReadMe.txt" /> <Text Include="ReadMe.txt" />
...@@ -30,6 +33,12 @@ ...@@ -30,6 +33,12 @@
<ClInclude Include="CommonStruct.h"> <ClInclude Include="CommonStruct.h">
<Filter>头文件</Filter> <Filter>头文件</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="utility\iniOperation.h">
<Filter>utility</Filter>
</ClInclude>
<ClInclude Include="utility\utilCommonAPI.h">
<Filter>utility</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="stdafx.cpp"> <ClCompile Include="stdafx.cpp">
...@@ -41,5 +50,11 @@ ...@@ -41,5 +50,11 @@
<ClCompile Include="CvxText.cpp"> <ClCompile Include="CvxText.cpp">
<Filter>源文件</Filter> <Filter>源文件</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="utility\iniOperation.cpp">
<Filter>utility</Filter>
</ClCompile>
<ClCompile Include="utility\utilCommonAPI.cpp">
<Filter>utility</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
///////////////////////////////////////////////////////////////
// Name: ZIni
// Version: 0.1
// Author: zhaobinjie
// Email: zhaobinjie1984@163.com
// Date: 2010-04-29
//
// Description:
// This class provides static functions for writing and
// reading INI files.
///////////////////////////////////////////////////////////////
#include "iniOperation.h"
#include <fstream>
#include <sstream>
#include <cctype>
#include <cstdlib>
bool ZIni::writeString(std::string strSectName,
std::string strKeyName,
std::string strValue,
std::string strFileName)
{
// open INI file
std::ifstream fsIni(strFileName.c_str(),
std::ios_base::in);
// open INI.bak file
std::ofstream fsIniBak((strFileName + ".zbk").c_str(),
std::ios_base::out | std::ios_base::trunc);
// file opened successfully
if (fsIni && fsIniBak)
{
// search section
std::string strLine = "";
std::string strSection = std::string("[") + strSectName + "]";
bool bWritten = false;
while (getline(fsIni, strLine))
{
// remain the others
fsIniBak << strLine << std::endl;
// section found
if (!bWritten && 0 == strSection.compare(trim(strLine)))
{
// search key
while (getline(fsIni, strLine))
{
std::string strTemp = trim(strLine);
// write value to the end of this section
if (strTemp.length() > 0 && '[' == strTemp[0])
{
fsIniBak << strKeyName << " = " << strValue
<< std::endl;
fsIniBak << strLine << std::endl;
bWritten = true;
break;
}
// replace the origin value
if (strTemp.length() > strKeyName.length() &&
0 == strTemp.compare(0,
strKeyName.length(), strKeyName) &&
'=' == strTemp[strKeyName.length()])
{
fsIniBak << strKeyName << " = " << strValue
<< std::endl;
bWritten = true;
break;
}
// remain the others
fsIniBak << strLine << std::endl;
}
// write value
if (!bWritten)
{
fsIniBak << strKeyName << " = " << strValue << std::endl;
bWritten = true;
}
}
}
// write value
if (!bWritten)
{
fsIniBak << strSection << std::endl;
fsIniBak << strKeyName << " = " << strValue << std::endl;
}
// close file stream
fsIni.close();
fsIniBak.close();
}
else
{
return false;
}
// open INI.zbk file
std::ifstream fsIniBakNew((strFileName + ".zbk").c_str(),
std::ios_base::in);
// open INI file
std::ofstream fsIniNew(strFileName.c_str(),
std::ios_base::out | std::ios_base::trunc);
// file opened successfully
if (fsIniBakNew && fsIniNew)
{
std::string strLine = "";
while (getline(fsIniBakNew, strLine))
{
fsIniNew << strLine << std::endl;
}
// close file stream
fsIniBakNew.close();
fsIniNew.close();
}
else
{
return false;
}
return true;
}
bool ZIni::writeInt(std::string strSectName,
std::string strKeyName,
int iValue,
std::string strFileName)
{
// convert int to string
std::stringstream ssValue;
ssValue << iValue;
return writeString(strSectName, strKeyName, ssValue.str(), strFileName);
}
bool ZIni::writeDouble(std::string strSectName,
std::string strKeyName,
double fValue,
std::string strFileName)
{
// convert double to string
std::stringstream ssValue;
ssValue << fValue;
return writeString(strSectName, strKeyName, ssValue.str(), strFileName);
}
std::string ZIni::readString(std::string strSectName,
std::string strKeyName,
std::string strDefault,
std::string strFileName)
{
// open INI file
std::ifstream fsIni(strFileName.c_str(), std::ios_base::in);
// file opened successfully
if (fsIni)
{
// search section
std::string strLine = "";
std::string strSection = std::string("[") + strSectName + "]";
while (getline(fsIni, strLine))
{
// section found
if (0 == strSection.compare(trim(strLine)))
{
// search key
while (getline(fsIni, strLine))
{
std::string strTemp = trim(strLine);
// end of this section
if (strTemp.length() > 0 && '[' == strTemp[0])
{
return strDefault;
}
if (strTemp.length() > strKeyName.length() + 1 &&
0 == strTemp.compare(0,
strKeyName.length(), strKeyName) &&
'=' == strTemp[strKeyName.length()])
{
return (strTemp.substr(strKeyName.length() + 1));
}
}
}
}
}
// read failed
return strDefault;
}
int ZIni::readInt(std::string strSectName,
std::string strKeyName,
int iDefault,
std::string strFileName)
{
// converting between int and string
std::stringstream ssDefault;
ssDefault << iDefault;
return atoi(readString(strSectName, strKeyName,
ssDefault.str(), strFileName).c_str());
}
double ZIni::readDouble(std::string strSectName,
std::string strKeyName,
double fDefault,
std::string strFileName)
{
// converting between double and string
std::stringstream ssDefault;
ssDefault << fDefault;
return atof(readString(strSectName, strKeyName,
ssDefault.str(), strFileName).c_str());
}
//消除字串两段的空格,字串中间的保留
std::string ZIni::trim(std::string &strInput)
{
std::string str(strInput);
if(str.empty())
return str;
str = str.substr(str.find_first_not_of(' '),str.find_last_not_of(' ')+1);
std::string::size_type pos_equations = str.find_first_of('=');
if(pos_equations != std::string::npos)
{
if(pos_equations > 0 && str[pos_equations-1] == ' ')
str.erase(pos_equations-1,1);
pos_equations = str.find_first_of('=');
if(pos_equations < str.size() && str[pos_equations+1] == ' ')
str.erase(pos_equations+1,1);
}
return str;
}
\ No newline at end of file
///////////////////////////////////////////////////////////////
// Name: ZIni
// Version: 0.1
// Author: zhaobinjie
// Email: zhaobinjie1984@163.com
// Date: 2010-04-29
//
// Description:
// This class provides static functions for writing and
// reading INI files.
///////////////////////////////////////////////////////////////
#ifndef ZINI_H
#define ZINI_H
#include <string>
class ZIni
{
public:
ZIni() {}
virtual ~ZIni() {}
public:
// return if succeed or not
static bool writeString(
std::string strSectName, // in. section name
std::string strKeyName, // in. key name
std::string strValue, // in. value to be write
std::string strFileName // in. INI file name
);
// return if succeed or not
static bool writeInt(
std::string strSectName, // in. section name
std::string strKeyName, // in. key name
int iValue, // in. value to be write
std::string strFileName // in. INI file name
);
// return if succeed or not
static bool writeDouble(
std::string strSectName, // in. section name
std::string strKeyName, // in. key name
double fValue, // in. value to be write
std::string strFileName // in. INI file name
);
// return the got string
static std::string readString(
std::string strSectName, // in. section name
std::string strKeyName, // in. key name
std::string strDefault, // in. defaut value if read failed
std::string strFileName // in. INI file name
);
// return the got int
static int readInt(
std::string strSectName, // in. section name
std::string strKeyName, // in. key name
int iDefault, // in. defaut value if read failed
std::string strFileName // in. INI file name
);
// return the got double
static double readDouble(
std::string strSectName, // in. section name
std::string strKeyName, // in. key name
double fDefault, // in. defaut value if read failed
std::string strFileName // in. INI file name
);
private:
static std::string trim(std::string &strInput);
};
#endif //ZINI_H
#include "utilCommonAPI.h"
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <stdarg.h>
#ifdef WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif
//函数名: GetProcDir()
//功 能: 获取当前程序的路径
std::string GetProcDir()
{
std::string strDir;
#ifdef WIN32
char exeFullPath[MAX_PATH]; // Full path
GetModuleFileNameA(NULL, exeFullPath, MAX_PATH);
strDir = exeFullPath; // Get full path of the file
int pos = strDir.find_last_of('\\', strDir.length());
strDir = strDir.substr(0, pos+1); // Return the directory without the file name
#else
char szBuffer[256];
int npos = 0;
npos = readlink( "/proc/self/exe", szBuffer, 256 );
if ( npos < 0 || npos >= 256 )
{
printf( "readlink failed.\n" );
return strDir;
}
szBuffer[npos] = '\0';
char *ptr = NULL;
char c = '/';
ptr = strrchr(szBuffer,c);
if(ptr != NULL)
*(ptr +1) = 0;
strDir = szBuffer;
#endif
return strDir;
}
#ifdef WIN32
std::string UnicodeToAscii(const std::wstring& wstr) {
// 预算-缓冲区中多字节的长度
int ansiiLen = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, nullptr, 0, nullptr, nullptr);
// 给指向缓冲区的指针变量分配内存
char *pAssii = (char*)malloc(sizeof(char)*ansiiLen);
// 开始向缓冲区转换字节
WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, pAssii, ansiiLen, nullptr, nullptr);
std::string ret_str = pAssii;
free(pAssii);
return ret_str;
}
std::wstring Utf8ToUnicode(const std::string& str) {
// 预算-缓冲区中宽字节的长度
int unicodeLen = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0);
// 给指向缓冲区的指针变量分配内存
wchar_t *pUnicode = (wchar_t*)malloc(sizeof(wchar_t)*unicodeLen);
// 开始向缓冲区转换字节
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, pUnicode, unicodeLen);
std::wstring ret_str = pUnicode;
free(pUnicode);
return ret_str;
}
#endif // WIN32
#include <string>
//函数名: GetProcDir()
//功 能: 获取当前程序的路径
std::string GetProcDir();
#ifdef WIN32
#else
void OutputDebugString(const char* lpOutputString);
#endif
#ifdef WIN32
#else //LINUX
#define _DO_NOT_HAVE_S
#endif //WIN32
#ifdef _DO_NOT_HAVE_S //如果没有_s版的函数,则启动如下的替换宏
//#define sprintf_s(buffer,size,format, ...) sprintf(buffer,format,__VA_ARGS__)
#include <stdio.h>
#include <stdarg.h>
int sprintf_s(
char *buffer,
size_t sizeOfBuffer,
const char *format ,...); //这个比较特殊,需要真的去实现
#define memcpy_s(dest,num,src,count) memcpy(dest,src,count)
#define fprintf_s fprintf
#define _strdate_s(buf,num) _strdate(buf)
#define strcat_s(dest,num,src) strcat(dest,src)
#define fopen_s(pf,name,mode) *pf=fopen(name,mode)
#define strncpy_s(dest,num,src,count) strncpy(dest,src,count)
#define localtime_s(tm,time) *tm=*localtime(time)
#define _strdup strdup
#else
#define mkdir(pathname,mode) _mkdir(pathname)
#endif
#ifdef WIN32
std::string UnicodeToAscii(const std::wstring& wstr);
std::wstring Utf8ToUnicode(const std::string& str);
#endif // WIN32
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