Bladeren bron

Z991239-6192 #comment: 优化人脸检测实体实现

80274480 5 maanden geleden
bovenliggende
commit
e810fd84d9

+ 1 - 1
Module/mod_customeraware/CustomerHandleFSM.cpp

@@ -91,7 +91,7 @@ ErrorCodeEnum CCustomerHandleFSM::SetSysState( int state )
 			//客户离开,清空sessionid
 			errCode = GetEntityBase()->GetFunction()->SetSysVar("SessionID","N");
 			if (errCode != Error_Succeed){
-				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("customeraware end set SessionID to Null failed (%d).",errCode);
+				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("customeraware end set SessionID to Null failed (%d).", errCode);
 			}
 		}
 	}

+ 1 - 0
Module/mod_facetracking/CMakeLists.txt

@@ -3,6 +3,7 @@ define_module("facetracking")
 set(${MODULE_PREFIX}_SRCS
 	sysvar.h
 	Event.h
+	mod_facetracking.h
 	mod_facetracking.cpp
 	)
 

+ 305 - 322
Module/mod_facetracking/mod_facetracking.cpp

@@ -1,11 +1,7 @@
 #include "stdafx.h"
-#include "SpBase.h"
-#include "SpIni.h"
 
 #include "rvc_media_common.h"
-
-#include "libvideoqueue.h"
-#include "libfacecapture.h"
+#include "mod_facetracking.h"
 
 #include "y2k_time.h"
 
@@ -47,384 +43,371 @@ static struct {
 	{9, EVENT_MOD_NODETECT_BODY,"未检测到人脸"},
 };
 
-class CFaceTrackingEntity : public CEntityBase, public CHostApi , public CVideoMonitorEvent, public ISysVarListener, public ITimerListener,public ILogListener
-{
-public:
-	CFaceTrackingEntity() : m_facecapture(NULL), bIsSessionChange(false),strCustomerID(false),strSessionID(false),bIsCustomerChange(false), m_bSingleCamera(false)
-	{
-		// note: this object initialize at DllMain, so it suggests keep your code simple here. 
-		// 1) do simple initializing here
-		// 2) dont do complex operation, complex operation such as create new process(thread) and so on
-	}
-	virtual ~CFaceTrackingEntity() {}
-	virtual const char *GetEntityName() const { return "FaceTracking"; }
-
-	virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext) 
-	{
-		CSmartPointer<IEntityFunction> spFunction = GetFunction();
-
-		CSystemStaticInfo stStaticinfo;
-		spFunction->GetSystemStaticInfo(stStaticinfo);
-		if (stricmp(stStaticinfo.strMachineType, "RVC.Stand1SPlus") == 0) {
-			m_bSingleCamera = true;
-		}
 
-		ErrorCodeEnum Error;
-		bool bRet = false;
-		if (!m_bSingleCamera) {
-			m_facecapture = new Clibfacecapture(&bRet, this, this, REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE, REC_COMMON_VIDEO_OPT_SHM_RTP_QUEUE);
-		}
-		else {
-			m_facecapture = new Clibfacecapture(&bRet, this, this, REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE);
-		}
-
-		if (!bRet) {
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("load libface capture failed!");
-			pTransactionContext->SendAnswer(Error_Resource);
-			return;
-		}
-
-		Error = GetFunction()->RegistSysVarEvent("SessionID", this);
-		if (Error != Error_Succeed) {
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("register sysvar %s failed!", "SessionID");
-		}
+CFaceTrackingEntity::CFaceTrackingEntity()
+{
+	m_facecapture = NULL;
+	bIsSessionChange = false;
+	strCustomerID = false;
+	strSessionID = false;
+	bIsCustomerChange = false;
+	m_bSingleCamera = false;
+}
+
+void CFaceTrackingEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
+{
+	CSmartPointer<IEntityFunction> spFunction = GetFunction();
 
-		Error = GetFunction()->RegistSysVarEvent("CustomerID", this);
-		if (Error != Error_Succeed) {
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("register sysvar %s failed!", "CustomerID");
-		}
+	CSystemStaticInfo stStaticinfo;
+	spFunction->GetSystemStaticInfo(stStaticinfo);
+	if (stricmp(stStaticinfo.strMachineType, "RVC.Stand1SPlus") == 0) {
+		m_bSingleCamera = true;
+	}
 
-		Error = GetFunction()->RegistSysVarEvent(SYSVAR_CAMERASTATE, this);
-		if (Error != Error_Succeed) {
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("register sysvar %s failed!", SYSVAR_CAMERASTATE);
-		}
+	ErrorCodeEnum Error;
+	bool bRet = false;
+	if (!m_bSingleCamera) {
+		m_facecapture = new Clibfacecapture(&bRet, this, this, REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE, REC_COMMON_VIDEO_OPT_SHM_RTP_QUEUE);
+	}
+	else {
+		m_facecapture = new Clibfacecapture(&bRet, this, this, REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE);
+	}
 
-		CSimpleStringA strValue;
-		GetFunction()->GetSysVar(SYSVAR_CAMERASTATE, strValue);
-		if (strValue[0]  == 'N'){
-			m_facecapture->SetCameraState(0);
-		}
-		else if (strValue[0]  == 'E'){
-			m_facecapture->SetCameraState(1);
-		}
-		else if (strValue[0]  == 'O'){
-			m_facecapture->SetCameraState(2);
-		}
-		else if (strValue[0]  == 'B'){
-			m_facecapture->SetCameraState(3);
-		}	
+	if (!bRet) {
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("load libface capture failed!");
+		pTransactionContext->SendAnswer(Error_Resource);
+		return;
+	}
 
-		spFunction->SubscribeLog(m_UUid1, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_HEADLIGHT_GREEN_OFF,NULL,false);
-		spFunction->SubscribeLog(m_UUid2, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_MEDIACONTROLLER_CAMERA_STARTED,NULL,false);
-		spFunction->SubscribeLog(m_UUid3, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_MEDIACONTROLLER_CAMERA_STOPPED,NULL,false);
-		spFunction->SubscribeLog(m_UUid4, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_MEDIACONTROLLER_RESET_ACTIVECAMERA, NULL, false); 
-		
-		pTransactionContext->SendAnswer(Error);
+	Error = GetFunction()->RegistSysVarEvent("SessionID", this);
+	if (Error != Error_Succeed) {
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("register sysvar %s failed!", "SessionID");
 	}
 
-	virtual void OnStarted()
-	{
-		LogEvent(Severity_Middle, LOG_EVT_MOD_FACETRACKING_STARTED_SUCCESS, "facetracking entity started successfully.");
+	Error = GetFunction()->RegistSysVarEvent("CustomerID", this);
+	if (Error != Error_Succeed) {
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("register sysvar %s failed!", "CustomerID");
 	}
 
-	virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext) 
-	{ 
-		CSmartPointer<IEntityFunction> spFunction = GetFunction();
-		delete m_facecapture;
-		m_facecapture = NULL;
-		spFunction->UnsubscribeLog(m_UUid1);
-		spFunction->UnsubscribeLog(m_UUid2);
-		spFunction->UnsubscribeLog(m_UUid3);
-		spFunction->UnsubscribeLog(m_UUid4);
-		spFunction->UnregistSysVarEvent("SessionID");
-		spFunction->UnregistSysVarEvent("CustomerID");
-		spFunction->UnregistSysVarEvent(SYSVAR_CAMERASTATE);
-		pTransactionContext->SendAnswer(Error_Succeed); 
+	Error = GetFunction()->RegistSysVarEvent(SYSVAR_CAMERASTATE, this);
+	if (Error != Error_Succeed) {
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("register sysvar %s failed!", SYSVAR_CAMERASTATE);
 	}
 
-	int TransCameraStateToInt(char cData)
-	{
-		int iRet = 0;
-		if ('E' == cData){
-			iRet = 1;
-		}
-		else if('O' == cData){
-			iRet = 2;
-		}
-		else if('B' == cData){
-			iRet = 3;
-		}
+	CSimpleStringA strValue;
+	GetFunction()->GetSysVar(SYSVAR_CAMERASTATE, strValue);
+	if (strValue[0]  == 'N'){
+		m_facecapture->SetCameraState(0);
+	}
+	else if (strValue[0]  == 'E'){
+		m_facecapture->SetCameraState(1);
+	}
+	else if (strValue[0]  == 'O'){
+		m_facecapture->SetCameraState(2);
+	}
+	else if (strValue[0]  == 'B'){
+		m_facecapture->SetCameraState(3);
+	}	
+
+	spFunction->SubscribeLog(m_UUid1, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_HEADLIGHT_GREEN_OFF,NULL,false);
+	spFunction->SubscribeLog(m_UUid2, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_MEDIACONTROLLER_CAMERA_STARTED,NULL,false);
+	spFunction->SubscribeLog(m_UUid3, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_MEDIACONTROLLER_CAMERA_STOPPED,NULL,false);
+	spFunction->SubscribeLog(m_UUid4, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_MEDIACONTROLLER_RESET_ACTIVECAMERA, NULL, false); 
+		
+	pTransactionContext->SendAnswer(Error);
+}
 
-		return iRet;
+void CFaceTrackingEntity::OnStarted()
+{
+	LogEvent(Severity_Middle, LOG_EVT_MOD_FACETRACKING_STARTED_SUCCESS, "facetracking entity started successfully.");
+}
+
+void CFaceTrackingEntity::OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
+{ 
+	CSmartPointer<IEntityFunction> spFunction = GetFunction();
+	delete m_facecapture;
+	m_facecapture = NULL;
+	spFunction->UnsubscribeLog(m_UUid1);
+	spFunction->UnsubscribeLog(m_UUid2);
+	spFunction->UnsubscribeLog(m_UUid3);
+	spFunction->UnsubscribeLog(m_UUid4);
+	spFunction->UnregistSysVarEvent("SessionID");
+	spFunction->UnregistSysVarEvent("CustomerID");
+	spFunction->UnregistSysVarEvent(SYSVAR_CAMERASTATE);
+	pTransactionContext->SendAnswer(Error_Succeed); 
+}
+
+int CFaceTrackingEntity::TransCameraStateToInt(char cData)
+{
+	int iRet = 0;
+	if ('E' == cData){
+		iRet = 1;
+	}
+	else if('O' == cData){
+		iRet = 2;
+	}
+	else if('B' == cData){
+		iRet = 3;
 	}
 
-	void OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
-		const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID, 
-		const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext &pLinkInfo)
+	return iRet;
+}
+
+void CFaceTrackingEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
+	const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID, 
+	const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext &pLinkInfo)
+{
+	switch (dwUserCode)
 	{
-		switch (dwUserCode)
-		{
-		case LOG_EVT_HEADLIGHT_GREEN_OFF:
-			m_facecapture->SetLightChange();
-			break;
+	case LOG_EVT_HEADLIGHT_GREEN_OFF:
+		m_facecapture->SetLightChange();
+		break;
 
-		case LOG_EVT_MEDIACONTROLLER_CAMERA_STARTED:
-			{
-				CSimpleStringA strValue;
-				GetFunction()->GetSysVar(SYSVAR_CAMERASTATE, strValue);
-				int iState = TransCameraStateToInt(strValue[0]);
-				if (3 != iState) {
-					m_facecapture->SetCameraState(iState);
-					m_facecapture->StartFaceCapture();
-				}
-				else {
-					m_facecapture->SetCameraState(3);
-				}
-
-				if (!m_bSingleCamera) {
-					GetFunction()->SetTimer(1, this, 1000);
-				}
+	case LOG_EVT_MEDIACONTROLLER_CAMERA_STARTED:
+		{
+			CSimpleStringA strValue;
+			GetFunction()->GetSysVar(SYSVAR_CAMERASTATE, strValue);
+			int iState = TransCameraStateToInt(strValue[0]);
+			if (3 != iState) {
+				m_facecapture->SetCameraState(iState);
+				m_facecapture->StartFaceCapture();
+			}
+			else {
+				m_facecapture->SetCameraState(3);
 			}
-			break;
 
-		case LOG_EVT_MEDIACONTROLLER_CAMERA_STOPPED:
-			{
-				m_facecapture->StopFaceCapture();
-				CSimpleStringA strValue;
-				GetFunction()->GetSysVar(SYSVAR_CAMERASTATE, strValue);
-				int iState = TransCameraStateToInt(strValue[0]);
-				m_facecapture->SetCameraState(iState);
+			if (!m_bSingleCamera) {
+				GetFunction()->SetTimer(1, this, 1000);
+			}
+		}
+		break;
 
-				if (!m_bSingleCamera) {
-					GetFunction()->KillTimer(1);
-				}
+	case LOG_EVT_MEDIACONTROLLER_CAMERA_STOPPED:
+		{
+			m_facecapture->StopFaceCapture();
+			CSimpleStringA strValue;
+			GetFunction()->GetSysVar(SYSVAR_CAMERASTATE, strValue);
+			int iState = TransCameraStateToInt(strValue[0]);
+			m_facecapture->SetCameraState(iState);
 
-				GetFunction()->SetSysVar(SYSVAR_ACTIVETRACKINGCAMERA, ACTIVETRACKINGCAMERA_ENV); // from Operation -> Environment
+			if (!m_bSingleCamera) {
+				GetFunction()->KillTimer(1);
 			}
-			break;
 
-		case LOG_EVT_MEDIACONTROLLER_RESET_ACTIVECAMERA:
-			{
-				CSimpleStringA strValue;
-				GetFunction()->GetSysVar(SYSVAR_ACTIVETRACKINGCAMERA, strValue); // E or O
-				if ('O' == strValue[0]) {
-					GetFunction()->SetSysVar(SYSVAR_ACTIVETRACKINGCAMERA, ACTIVETRACKINGCAMERA_ENV); // from Operation -> Environment
-				}
+			GetFunction()->SetSysVar(SYSVAR_ACTIVETRACKINGCAMERA, ACTIVETRACKINGCAMERA_ENV); // from Operation -> Environment
+		}
+		break;
+
+	case LOG_EVT_MEDIACONTROLLER_RESET_ACTIVECAMERA:
+		{
+			CSimpleStringA strValue;
+			GetFunction()->GetSysVar(SYSVAR_ACTIVETRACKINGCAMERA, strValue); // E or O
+			if ('O' == strValue[0]) {
+				GetFunction()->SetSysVar(SYSVAR_ACTIVETRACKINGCAMERA, ACTIVETRACKINGCAMERA_ENV); // from Operation -> Environment
 			}
-			break;
-		default:
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("unknown event.");
-			break;
 		}
+		break;
+	default:
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("unknown event.");
+		break;
 	}
+}
 
-	//////////////////////////////////////////////////////////////////////////////////////////////////////
-	// ITimerListener implementation
+//////////////////////////////////////////////////////////////////////////////////////////////////////
+// ITimerListener implementation
 	
-	virtual void OnTimeout(DWORD dwTimerID)
+void CFaceTrackingEntity::OnTimeout(DWORD dwTimerID)
+{
+	uint64_t uid;
+	CCustomerStatus status;
+	//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("before GetMainCustomerStatus");
+	if (m_facecapture->GetMainCustomerStatus(uid, status)) 
 	{
-		uint64_t uid;
-		CCustomerStatus status;
-		//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("before GetMainCustomerStatus");
-		if (m_facecapture->GetMainCustomerStatus(uid, status)) 
+		CSmartPointer<IEntityFunction> spFunction = GetFunction();
+		CSimpleStringA strValue;
+		spFunction->GetSysVar(SYSVAR_ACTIVETRACKINGCAMERA, strValue); // E or O
+		if (status.stCustomerPos.eCamera == EnvironCamera) 
 		{
-			CSmartPointer<IEntityFunction> spFunction = GetFunction();
-			CSimpleStringA strValue;
-			spFunction->GetSysVar(SYSVAR_ACTIVETRACKINGCAMERA, strValue); // E or O
-			if (status.stCustomerPos.eCamera == EnvironCamera) 
-			{
-				if (strValue[0] == 'O') 
-				{
-					DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ActiveTrackingCamera change from Opt->Env!");
-					spFunction->SetSysVar(SYSVAR_ACTIVETRACKINGCAMERA, ACTIVETRACKINGCAMERA_ENV); // from Operation -> Environment
-				}
-			} 
-			else 
+			if (strValue[0] == 'O') 
 			{
-				if (strValue[0] == 'E') 
-				{
-					DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ActiveTrackingCamera change from Env->Opt!");
-					spFunction->SetSysVar(SYSVAR_ACTIVETRACKINGCAMERA, ACTIVETRACKINGCAMERA_OPT); // from Environment -> Operation
-				}
-			}			
+				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ActiveTrackingCamera change from Opt->Env!");
+				spFunction->SetSysVar(SYSVAR_ACTIVETRACKINGCAMERA, ACTIVETRACKINGCAMERA_ENV); // from Operation -> Environment
+			}
 		} 
 		else 
 		{
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetMainCustomerStatus failed!");
-		}
+			if (strValue[0] == 'E') 
+			{
+				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ActiveTrackingCamera change from Env->Opt!");
+				spFunction->SetSysVar(SYSVAR_ACTIVETRACKINGCAMERA, ACTIVETRACKINGCAMERA_OPT); // from Environment -> Operation
+			}
+		}			
+	} 
+	else 
+	{
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetMainCustomerStatus failed!");
 	}
+}
 
-	//////////////////////////////////////////////////////////////////////////////////////////////////////
-	// CHostApi implementation
+//////////////////////////////////////////////////////////////////////////////////////////////////////
+// CHostApi implementation
 
-	virtual uint64_t GenerateUUID()
-	{
-		m_lastUUID = CUUID::Create(m_lastUUID);
-		return m_lastUUID;
-	}
+uint64_t CFaceTrackingEntity::GenerateUUID()
+{
+	m_lastUUID = CUUID::Create(m_lastUUID);
+	return m_lastUUID;
+}
 
-	virtual bool IsCustomerChange()
-	{
-		bool bChange = bIsSessionChange||bIsCustomerChange;
-		return bChange;
-	}
+bool CFaceTrackingEntity::IsCustomerChange()
+{
+	bool bChange = bIsSessionChange||bIsCustomerChange;
+	return bChange;
+}
 
-	virtual void GetFaceImgName(char* FaceName, uint32_t uLen)
+void CFaceTrackingEntity::GetFaceImgName(char* FaceName, uint32_t uLen)
+{
+	CSimpleStringA strPath;
+	ErrorCodeEnum Error = GetFunction()->GetPath("UploadPhoto", strPath);
+	if (Error == Error_Succeed) 
 	{
-		CSimpleStringA strPath;
-		ErrorCodeEnum Error = GetFunction()->GetPath("UploadPhoto", strPath);
-		if (Error == Error_Succeed) 
+		if (((const char*)strCustomerID == NULL)||(_stricmp(strCustomerID,"N") == 0))
 		{
-
-			if (((const char*)strCustomerID == NULL)||(_stricmp(strCustomerID,"N") == 0))
-			{
-				rvc_snprintf(FaceName, uLen,"%s%s%s_0", strPath.GetData(), SPLIT_SLASH_STR, strSessionID.GetData());
-			}
-			else
-			{
-				rvc_snprintf(FaceName, uLen, "%s%s%s_%s", strPath.GetData(), SPLIT_SLASH_STR, strSessionID.GetData(), strCustomerID.GetData());
-			}
-			bIsSessionChange = false;
-			bIsCustomerChange = false;
-		} 
-		else 
+			rvc_snprintf(FaceName, uLen,"%s%s%s_0", strPath.GetData(), SPLIT_SLASH_STR, strSessionID.GetData());
+		}
+		else
 		{
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("getpath uploadphoto failed!");
+			rvc_snprintf(FaceName, uLen, "%s%s%s_%s", strPath.GetData(), SPLIT_SLASH_STR, strSessionID.GetData(), strCustomerID.GetData());
 		}
+		bIsSessionChange = false;
+		bIsCustomerChange = false;
+	} 
+	else 
+	{
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("getpath uploadphoto failed!");
 	}
+}
 
-	virtual bool LoadConfig(CFaceCaptureConfig &config)
-	{
-		CSmartPointer<IEntityFunction> spFunction = GetFunction();
-		CSmartPointer<IConfigInfo> spConfig;
-		ErrorCodeEnum Error(Error_Succeed);
-
-		/*
-		PrimCamera=1
-		UpCameraEdgeLimit=3
-		DownCameraEdgeLimit=2
-		ServersType=0
-		ContourMinAera=14400
-		FaceDataDirPath=facedata
-		OperateFaceSize=4.2
-		CloseFaceSize=6.6
-		FarFaceSize=8.2
-		SearchFaceSize=8.2
-		DetectFaceSize=6.6
-		FaceSizeOffset=18
-		SleepLong=800
-		SleepMiddle=600
-		SleepShort=500
-		ThresholdNum=10
-		*/
-		CSimpleStringA strPath;
-		config.nServersType = 0;
-		GetFunction()->GetPath("cfg", strPath);
-		strcpy(config.strFaceDataDirPath, strPath);
-		strcat(config.strFaceDataDirPath, SPLIT_SLASH_STR "facedata");
-
-		config.nPrimCamera = 1;
-		if (m_bSingleCamera) {
-			config.nPrimCamera = 0;
-		}
-		config.nContourMinAera = 14400;
-		config.nUpCameraEdgeLimit = 3;
-		config.nDownCameraEdgeLimit = 2;
-		config.fOperateFaceSize = 4.2f;
-		config.fCloseFaceSize = 6.6f;
-		config.fFarFaceSize = 8.2f;
-		config.fSearchFaceSize = 8.2f;
-		config.fDetectFaceSize = 6.6f;
-		config.nFaceSizeOffset = 18;
-		config.nSleepLong = 800;
-		config.nSleepMiddle = 600;
-		config.nSleepShort = 500;
-		config.nThresholdNum = 10;
-		Error = Error_Succeed;
-		return Error == Error_Succeed;
+bool CFaceTrackingEntity::LoadConfig(CFaceCaptureConfig &config)
+{
+	CSmartPointer<IEntityFunction> spFunction = GetFunction();
+	CSmartPointer<IConfigInfo> spConfig;
+	ErrorCodeEnum Error(Error_Succeed);
+
+	/*
+	PrimCamera=1
+	UpCameraEdgeLimit=3
+	DownCameraEdgeLimit=2
+	ServersType=0
+	ContourMinAera=14400
+	FaceDataDirPath=facedata
+	OperateFaceSize=4.2
+	CloseFaceSize=6.6
+	FarFaceSize=8.2
+	SearchFaceSize=8.2
+	DetectFaceSize=6.6
+	FaceSizeOffset=18
+	SleepLong=800
+	SleepMiddle=600
+	SleepShort=500
+	ThresholdNum=10
+	*/
+	CSimpleStringA strPath;
+	config.nServersType = 0;
+	GetFunction()->GetPath("cfg", strPath);
+	strcpy(config.strFaceDataDirPath, strPath);
+	strcat(config.strFaceDataDirPath, SPLIT_SLASH_STR "facedata");
+
+	config.nPrimCamera = 1;
+	if (m_bSingleCamera) {
+		config.nPrimCamera = 0;
+	}
+	config.nContourMinAera = 14400;
+	config.nUpCameraEdgeLimit = 3;
+	config.nDownCameraEdgeLimit = 2;
+	config.fOperateFaceSize = 4.2f;
+	config.fCloseFaceSize = 6.6f;
+	config.fFarFaceSize = 8.2f;
+	config.fSearchFaceSize = 8.2f;
+	config.fDetectFaceSize = 6.6f;
+	config.nFaceSizeOffset = 18;
+	config.nSleepLong = 800;
+	config.nSleepMiddle = 600;
+	config.nSleepShort = 500;
+	config.nThresholdNum = 10;
+	Error = Error_Succeed;
+	return Error == Error_Succeed;
+}
+
+void CFaceTrackingEntity::Debug(facecap_loglevel elevel, const char *fmt, ...)
+{
+	va_list arg;
+	va_start(arg, fmt);
+	int n = vsnprintf(NULL, 0, fmt, arg);
+
+	if (n >= MAX_LOG_LEN) {
+		char* buf = (char*)malloc((size_t)(n + 1));
+		vsnprintf(buf, n + 1, fmt, arg);
+		DbgWithLink((LOG_LEVEL_E)elevel, LOG_TYPE_SYSTEM)("%s", buf);
+		free(buf);
+	}
+	else{
+		char strlog[MAX_LOG_LEN] = {0};
+		vsnprintf(strlog, MAX_LOG_LEN, fmt, arg);
+		DbgWithLink((LOG_LEVEL_E)elevel, LOG_TYPE_SYSTEM)("%s", strlog);
 	}
+	va_end(arg);
+}
 
-	virtual void Debug(facecap_loglevel elevel, const char *fmt, ...)
-	{
-		va_list arg;
-		va_start(arg, fmt);
-		int n = vsnprintf(NULL, 0, fmt, arg);
-
-		if (n >= MAX_LOG_LEN) {
-			char* buf = (char*)malloc((size_t)(n + 1));
-			vsnprintf(buf, n + 1, fmt, arg);
-			DbgWithLink((LOG_LEVEL_E)elevel, LOG_TYPE_SYSTEM)("%s", buf);
-			free(buf);
-		}
-		else{
-			char strlog[MAX_LOG_LEN] = {0};
-			vsnprintf(strlog, MAX_LOG_LEN, fmt, arg);
-			DbgWithLink((LOG_LEVEL_E)elevel, LOG_TYPE_SYSTEM)("%s", strlog);
-		}
-		va_end(arg);
+////////////////////////////////////////////////////////////////////////////////////
+// CVideoMonitorEvent
+void CFaceTrackingEntity::GenerateMonitorEvent(video_monitor_event_type eType, char* strMsg)
+{
+	if (!strMsg) {
+		LogEvent(Severity_Middle, monitor_id_evtmsg[eType].evt_code, monitor_id_evtmsg[eType].evt_msg);
 	}
+	else {
+		LogEvent(Severity_Middle, monitor_id_evtmsg[eType].evt_code, strMsg);
+	}
+}
+
 
-	////////////////////////////////////////////////////////////////////////////////////
-	// CVideoMonitorEvent
-	void GenerateMonitorEvent(video_monitor_event_type eType, char* strMsg)
+void CFaceTrackingEntity::OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName)
+{
+	if (_stricmp(pszKey,"SessionID") == 0)
 	{
-		if (!strMsg) {
-			LogEvent(Severity_Middle, monitor_id_evtmsg[eType].evt_code, monitor_id_evtmsg[eType].evt_msg);
-		}
-		else {
-			LogEvent(Severity_Middle, monitor_id_evtmsg[eType].evt_code, strMsg);
-		}
+		GetFunction()->GetSysVar("SessionID",strSessionID);
+		bIsSessionChange = true;
 	}
 
-private:
+	if (_stricmp(pszKey,"CustomerID") == 0)
+	{
+		GetFunction()->GetSysVar("CustomerID",strCustomerID);
+		bIsCustomerChange = true;
+	}
 
-	virtual void OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName)
+	if (_stricmp(pszKey, SYSVAR_CAMERASTATE) == 0)
 	{
-		if (_stricmp(pszKey,"SessionID") == 0)
+		CSimpleStringA str;
+		GetFunction()->GetSysVar(SYSVAR_CAMERASTATE,str);
+		if (str == 'N')
 		{
-			GetFunction()->GetSysVar("SessionID",strSessionID);
-			bIsSessionChange = true;
+			m_facecapture->SetCameraState(0);
 		}
-
-		if (_stricmp(pszKey,"CustomerID") == 0)
+		else if (str == 'E')
 		{
-			GetFunction()->GetSysVar("CustomerID",strCustomerID);
-			bIsCustomerChange = true;
+			m_facecapture->SetCameraState(1);
 		}
-
-		if (_stricmp(pszKey, SYSVAR_CAMERASTATE) == 0)
+		else if (str == 'O')
 		{
-			CSimpleStringA str;
-			GetFunction()->GetSysVar(SYSVAR_CAMERASTATE,str);
-			if (str == 'N')
-			{
-				m_facecapture->SetCameraState(0);
-			}
-			else if (str == 'E')
-			{
-				m_facecapture->SetCameraState(1);
-			}
-			else if (str == 'O')
-			{
-				m_facecapture->SetCameraState(2);
-			}
-			else if (str == 'B')
-			{
-				m_facecapture->SetCameraState(3);
-			}	
+			m_facecapture->SetCameraState(2);
 		}
+		else if (str == 'B')
+		{
+			m_facecapture->SetCameraState(3);
+		}	
 	}
+}
 
-private:
-	CUUID m_UUid1,m_UUid2,m_UUid3,m_UUid4;
-	bool bIsSessionChange;
-	bool bIsCustomerChange;
-	CSimpleStringA strCustomerID;
-	CSimpleStringA strSessionID;
-	CUUID m_lastUUID;
-	Clibfacecapture *m_facecapture;
-	bool m_bSingleCamera;
-};
 
 SP_BEGIN_ENTITY_MAP()
 	SP_ENTITY(CFaceTrackingEntity)

+ 53 - 0
Module/mod_facetracking/mod_facetracking.h

@@ -0,0 +1,53 @@
+#ifndef __MOD_FACETRACKING_H
+#define __MOD_FACETRACKING_H
+#pragma once
+
+#include "SpBase.h"
+#include "SpIni.h"
+
+#include "libvideoqueue.h"
+#include "libfacecapture.h"
+
+class CFaceTrackingEntity : public CEntityBase, public CHostApi, public CVideoMonitorEvent, public ISysVarListener, public ITimerListener, public ILogListener
+{
+public:
+	CFaceTrackingEntity();
+	virtual ~CFaceTrackingEntity() {}
+	virtual const char* GetEntityName() const { return "FaceTracking"; }
+	virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext);
+	virtual void OnStarted();
+	virtual void OnPreClose(EntityCloseCauseEnum eCloseCause, CSmartPointer<ITransactionContext> pTransactionContext);
+	int TransCameraStateToInt(char cData);
+	void OnLog(const CAutoArray<CUUID>& SubIDs, const CUUID nLogID, const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
+		const DWORD dwSysError, const DWORD dwUserCode, const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
+		const CAutoArray<DWORD>& Param, const char* pszEntityName, const char* pszModuleName, const char* pszMessage, const linkContext& pLinkInfo);
+	//////////////////////////////////////////////////////////////////////////////////////////////////////
+	// ITimerListener implementation
+	virtual void OnTimeout(DWORD dwTimerID);
+	//////////////////////////////////////////////////////////////////////////////////////////////////////
+	// CHostApi implementation
+	virtual uint64_t GenerateUUID();
+	virtual bool IsCustomerChange();
+	virtual void GetFaceImgName(char* FaceName, uint32_t uLen);
+	virtual bool LoadConfig(CFaceCaptureConfig& config);
+	virtual void Debug(facecap_loglevel elevel, const char* fmt, ...);
+	////////////////////////////////////////////////////////////////////////////////////
+	// CVideoMonitorEvent
+	void GenerateMonitorEvent(video_monitor_event_type eType, char* strMsg);
+
+private:
+	virtual void OnSysVarEvent(const char* pszKey, const char* pszValue, const char* pszOldValue, const char* pszEntityName);
+
+private:
+	CUUID m_UUid1, m_UUid2, m_UUid3, m_UUid4;
+	bool bIsSessionChange;
+	bool bIsCustomerChange;
+	CSimpleStringA strCustomerID;
+	CSimpleStringA strSessionID;
+	CUUID m_lastUUID;
+	Clibfacecapture* m_facecapture;
+	bool m_bSingleCamera;
+};
+
+
+#endif	__MOD_FACETRACKING_H