文件夹监控wei服务

伪服务
This commit is contained in:
yanshui177
2017-05-17 20:50:34 +08:00
parent 6dcd378738
commit e9f18bbc9b
11 changed files with 340 additions and 241 deletions

View File

@@ -1,241 +0,0 @@
/*
主函数文件segmentation.cpp 主函数的实现文件
*/
#include "segmentation.h"
#pragma comment( linker, "/subsystem:windows /entry:mainCRTStartup" )//无界面运行
/*主函数*/
int main(int argc,char* argv[])
{
if(argc<2) return -1;
//for(int iii=0;iii<argc;iii++)
// cout<<"argv"<<iii<<" "<<argv[iii]<<endl;
char *fpname1 = argv[1];
// cout<<"开始鉴定"<<fpname1<<endl;
//char *fpname1 = "010209400748";
/*变量定义*/
int i, ii, jj, feature[50][50][30] = { 0 }, featureall = 0;
double featurep[50][50][30] = { 0 };
double bzcu[50][50] = { 0 };
double bzckesa[50][50] = { 0 };
double wcd[30] = { 0 };
int featx[50][50] = { 0 };
int featdif[30] = { 0 };
float maxx = 0; //最大特征值的标号与值
int xyimgnum = 0; //嫌疑图片的数目
char str[80]; //存储地址
vector<string> suspict; //记录嫌疑图片地址
vector<float> suspict_wcd; //嫌疑图片的wcd值
vector<string> files; //存储该生所有考试文件路径
vector<string> dateVec, subjectVec, stuNum2;
vector<string> flagVec;//记录查到的学生的所有考试信息
/*读取配置文件,并配置各项参数*/
if (!ReadConfig("D:/HWCV/config/configure.cfg"))
{
SaveLog("\t配置文件读取失败\n", g_log_adr, "a");
return 0;
}
// cout<<"ReadConfig success"<<endl;
//
// string temp=g_db_hostName;
// temp+=g_db_dBName;temp+=g_db_userName;temp+=g_db_password;
// SaveLog((char*)temp.c_str(), g_log_adr, "a");
//
//查询数据库
string stuNum = fpname1;
if (!DbImg(stuNum, dateVec, subjectVec, stuNum2))
{
memset(g_log_rec, 0, sizeof(g_log_rec));
strcat(g_log_rec, GetTime());
strcat(g_log_rec, "\t数据库查询不到考号为:");
strcat(g_log_rec,fpname1);
strcat(g_log_rec, "的学生\n");
SaveLog(g_log_rec, g_log_adr, "a");
return 0;
}
//SaveLog("成功DB\n", g_log_adr, "a");
// cout << "成功DB\n数量为" << subjectVec.size() << endl;
//生成路径
int nn = 0;
for (int cp_i = 0; cp_i < subjectVec.size(); cp_i++)
{
if (!strcmp(subjectVec[cp_i].substr(0, 1).c_str(), "4") || !strcmp(subjectVec[cp_i].substr(0, 1).c_str(), "9"))
{
// cout << "无图像:" <<subjectVec[cp_i].c_str()<<" "<<dateVec[cp_i].c_str()<<" "<<stuNum2[cp_i].c_str()<< endl;
continue;
}
files.push_back(CrPath(dateVec[cp_i], subjectVec[cp_i], stuNum2[cp_i]));
// cout<<"PATH:"<<files[nn++].c_str()<<endl;
// SaveLog((char*)files[cp_i].c_str(), g_log_adr, "a");
// SaveLog("\n", g_log_adr, "a");
}
// cout << "生成路径结束" << endl;
int size = files.size();/*找到的路径的数量*/
/*对每一张图片进行处理*/
int realSize = 0;
for (i = 0; i < size; i++)
{
memset(str, 0, sizeof(str));
memset(featx, 0, sizeof(featx));
memset(bzcu, 0, sizeof(bzcu));
strcpy(str, files[i].c_str());
try{
singlefeature(str, featx);//featx[][50]
//正常处理了图像,说明图像可以照常处理
realSize += 1;
}
catch (_com_error e)
{
//没有正常处理图像,说明此地址下的图像不可用
memset(g_log_rec, 0, sizeof(g_log_rec));
strcat(g_log_rec, "\n读取路径:");
strcat(g_log_rec, str);
strcat(g_log_rec, " 的图像失败:");
strcat(g_log_rec, (char*)e.Description());
strcat(g_log_rec, " 的图像失败!\n");
SaveLog(g_log_rec, g_log_adr, "a");
continue;
}
// cout << "可以opencv\n" << endl;
featureall = 0; //图像特征值和的初始化
for (ii = 0; ii < 48; ii++) //将featx存起来,回头看能不能用函数换掉
for (jj = ii + 1; jj < 47; jj++)
{
feature[ii][jj][i] = featx[ii][jj];
featureall = featureall + featx[ii][jj];
}
/*求轮廓方向特征featurep式(5) 与标准差中的u的和*/
for (ii = 0; ii < 48; ii++)
for (jj = ii + 1; jj < 47; jj++)
{
featurep[ii][jj][i] = (double)featx[ii][jj] / featureall;
bzcu[ii][jj] += (double)featx[ii][jj] / featureall * 1000; //标准差的值过小,进行放大1
}
}/*处理完全部图片*/
if (realSize == 0)
{
SaveLog("\t此考生没有一张数据图像可用!\n", g_log_adr, "a");
return 0;
}
/*求标准差中u*/
for (ii = 0; ii < 48; ii++)
for (jj = ii + 1; jj < 47; jj++)
bzcu[ii][jj] = bzcu[ii][jj] / realSize;
/*步骤:读取标准差文件*/
int bzccolumns = 47;//txt文件中有47列
vector<double *> output_bzc;
if (!ReadScanf("D:\\HWCV\\config\\stdfile.db", bzccolumns, output_bzc))
{
memset(g_log_rec, 0, sizeof(g_log_rec));
SaveLog("\n读取路径D:\\HWCV\\config\\stdfile.db 的标准差文件失败!\n", g_log_adr, "a");
return 0;
}
for (ii = 0; ii < 48; ii++)//output_vector可视为二维数组;输出数组元素:
for (jj = ii + 1; jj < 47; jj++)
bzckesa[ii][jj] = output_bzc[ii][jj];
/*求相似性即带权卡方wcd*/
for (i = 0; i < realSize; i++)
for (ii = 0; ii < 48; ii++)
for (jj = ii + 1; jj < 47; jj++)
if (featurep[ii][jj][i] * featurep[ii][jj][g_conti] != 0 && bzckesa[ii][jj] != -1)
wcd[i] += pow((featurep[ii][jj][i] - featurep[ii][jj][g_conti]), 2) / ((featurep[ii][jj][i] + featurep[ii][jj][g_conti])*bzckesa[ii][jj]);
//标出所有有嫌疑的图像1无嫌疑的图像0
for (i = 0; i < dateVec.size(); i++)
{
if (wcd[i] > 0.12)
{
xyimgnum++;
suspict.push_back(files[i].c_str());
suspict_wcd.push_back(wcd[i]);
flagVec.push_back("1");//嫌疑标记1
}
else
{
flagVec.push_back("0");
}
}
//结果更新数据库
DbUpdate(stuNum, dateVec, subjectVec, stuNum2, flagVec);
// cout << "数据库更新完毕" << endl;
/*将结果存入log文件*/
strcat(g_log_rec, "\n");
memset(g_log_rec, 0, sizeof(g_log_rec));
strcat(g_log_rec, GetTime());
strcat(g_log_rec, "\t考生考号:");
strcat(g_log_rec, fpname1);
strcat(g_log_rec, " 图片总数为:");
char pic_num[20];
_itoa(realSize, pic_num, 10);
strcat(g_log_rec, pic_num);
if (xyimgnum > 0)
{
/* strcat(g_log_rec, "\t");
strcat(g_log_rec, suspict[0].c_str());
strcat(g_log_rec, "\t");
char a[20];
sprintf(a, "%g", suspict_wcd[0]);
strcat(g_log_rec, a);
*/ strcat(g_log_rec, "\n");
for (i = 0; i < xyimgnum; i++)
{
strcat(g_log_rec, "\t\t\t\t嫌疑图像:");
strcat(g_log_rec, suspict[i].c_str());
strcat(g_log_rec, "\t相似度:");
float sim=(1.0-suspict_wcd[i])*100;
char a[20];
sprintf(a, "%g", sim);
strcat(g_log_rec, a);
strcat(g_log_rec, "%%\n");
}
}
else
strcat(g_log_rec, "\t该考生没有嫌疑图像!\n");
SaveLog(g_log_rec, g_log_adr, "a");
/*善后*/
suspict.clear();
suspict_wcd.clear();
output_bzc.clear();
memset(g_log_rec, 0, sizeof(g_log_rec));
memset(feature, 0, sizeof(feature));
memset(featurep, 0, sizeof(featurep));
memset(bzckesa, 0, sizeof(bzckesa));
memset(wcd, 0, sizeof(wcd));
memset(featdif, 0, sizeof(featdif));
files.clear();
dateVec.clear();
subjectVec.clear();
stuNum2.clear();
flagVec.clear();
/*返回值*/
return 0;
}

View File

@@ -0,0 +1,64 @@
#include "Check.h"
char* GetTime();
/*功能:检查当前木有有无文件,若有,提取文件名,并删除此文件
@变量 path 检查文件位置
@返回值 返回检测到的变量向量
*/
int CheckFile(char* path, vector<string>& files)
{
using namespace std;//引入整个名空间
//文件句柄
long hFile = 0;
//文件信息
struct _finddata_t fileinfo;
string p;
if ((hFile = _findfirst(p.assign(path).append("/*").c_str(), &fileinfo)) != -1)
{
do
{
//如果是目录,直接返回
if ((fileinfo.attrib & _A_SUBDIR))
{
}
else //如果不是,加入列表
{
//files.push_back(p.assign(path).append("/").append(fileinfo.name));
files.push_back(fileinfo.name);
remove(p.assign(path).append("\\").append(fileinfo.name).c_str());
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
return 0;
}
/**
功能:泻入文件日志
*/
int WriteToLog(char* str)
{
FILE* log;
log = fopen(LOGFILE, "a+");
if (log == NULL) return -1;
fprintf(log, "%s ", str);
fclose(log);
return 0;
}
/**
获取并返回当前时间
*/
char* GetTime()
{
time( &ltime );
srcTime = ctime( &ltime );
strncpy(timeNow, srcTime, strlen(srcTime)-1); //不拷贝换行
timeNow[strlen(srcTime)-1] = '\0'; //加结束符'\0'
return timeNow;
}

View File

@@ -0,0 +1,41 @@
#include <windows.h>
#include <iostream>
#include <dos.h>
#include <stdio.h>
#include <time.h>
#include <vector>
#include <string.h>
#include <io.h>
using namespace std;
/*时间获取函数u*/
#define LOGFILE "D:\\HWCV\\memstatus.txt" //日志存储位置
extern time_t ltime;
extern char *srcTime;
extern char timeNow[22];
extern char msg[100];
/*功能:写入日志
@变量 str 写入内容
@返回值 固定
*/
int WriteToLog(char* str);
/**
功能:获取并返回当前时间
*/
char* GetTime();
/*功能:检查当前木有有无文件,若有,提取文件名,并删除此文件
@变量 path 检查文件位置
@变量 files 获取到的文件名称
@返回值 返回检测到的变量向量
*/
int CheckFile(char* path, vector<string>& files);

Binary file not shown.

View File

@@ -0,0 +1,112 @@
# Microsoft Developer Studio Project File - Name="HWCVServe" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=HWCVServe - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "HWCVServe.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "HWCVServe.mak" CFG="HWCVServe - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "HWCVServe - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "HWCVServe - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "HWCVServe - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x804 /d "NDEBUG"
# ADD RSC /l 0x804 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "HWCVServe - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD BASE RSC /l 0x804 /d "_DEBUG"
# ADD RSC /l 0x804 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "HWCVServe - Win32 Release"
# Name "HWCVServe - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\Check.cpp
# End Source File
# Begin Source File
SOURCE=.\Main.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\Check.h
# End Source File
# Begin Source File
SOURCE=.\Main.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# 警告: 不能编辑或删除该工作区文件!
###############################################################################
Project: "HWCVServe"=".\HWCVServe.dsp" - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

Binary file not shown.

View File

@@ -0,0 +1,25 @@
<html>
<body>
<pre>
<h1>Build Log</h1>
<h3>
--------------------Configuration: HWCVServe - Win32 Debug--------------------
</h3>
<h3>Command Lines</h3>
Creating temporary file "C:\Users\ãÆË§Ë§\AppData\Local\Temp\RSPC9C7.tmp" with contents
[
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/HWCVServe.pdb" /debug /machine:I386 /out:"Debug/HWCVServe.exe" /pdbtype:sept
".\Debug\Check.obj"
".\Debug\Main.obj"
]
Creating command line "link.exe @"C:\Users\ãÆË§Ë§\AppData\Local\Temp\RSPC9C7.tmp""
<h3>Output Window</h3>
Linking...
<h3>Results</h3>
HWCVServe.exe - 0 error(s), 0 warning(s)
</pre>
</body>
</html>

View File

@@ -0,0 +1,47 @@
#include "Main.h"
#include "Check.h"
using namespace std;
int main(int argc, char** argv)
{
//监控..\Check\路径下有没有新文件
char * path = "./Check/";
vector<string> files;
WriteToLog(GetTime());
WriteToLog("--开始运行服务--\n");
while(true)
{
//检查有没有新的文件若有则都在vector files中存储
CheckFile(path, files);
for (int iter = 0; iter < files.size();iter++)
{
// string cmd="D:/HWCV/config/HWCV-exe ";
// cmd += files[iter];
// WinExec((char*)cmd.c_str(),SW_HIDE);
try{
ShellExecute(NULL,"open",
"HWCV-exe.exe",
(char*)files[iter].c_str(),
NULL,
SW_SHOWNORMAL);
}catch(exception e)
{
}
}
files.clear();
Sleep(SLEEP_TIME);
}
WriteToLog(GetTime());
WriteToLog("--结束服务--\n");
return 1;
}

View File

@@ -0,0 +1,21 @@
#include <string>
#include <windows.h>
#include <string>
#include <stdio.h>
#include <iostream>
#include <dos.h>
#include <time.h>
#pragma comment(lib, "Advapi32")
//#pragma comment( linker, "/subsystem:windows /entry:mainCRTStartup" )//没有界面运行
using namespace std;
/*定义全局变量*/
#define SLEEP_TIME 1000 //5000毫秒刷新一次
/*时间获取函数u*/
time_t ltime;
char *srcTime=NULL;
char timeNow[22]={0};
char msg[100]={0};

View File

@@ -0,0 +1 @@
此程序时刻监控 Check文件下的文件并及时把文件名传递给HWCV-exe.exe并执行鉴定