Răsfoiți Sursa

Z991239-5321 #comment 优化脸部跟踪流程

80274480 1 an în urmă
părinte
comite
952e8ab7aa

+ 34 - 47
Module/mod_facetracking/mod_facetracking.cpp

@@ -37,7 +37,7 @@ public:
 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)
+	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
@@ -50,7 +50,7 @@ public:
 	{
 		CSmartPointer<IEntityFunction> spFunction = GetFunction();
 		ErrorCodeEnum Error;
-		BOOL bRet = FALSE;
+		bool bRet = false;
 		m_facecapture = new Clibfacecapture(&bRet, this, this, REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE, REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE, REC_COMMON_VIDEO_OPT_SHM_RTP_QUEUE);
 		if (!bRet) 
 		{
@@ -114,19 +114,10 @@ public:
 		//is Pad Version
 		CSystemStaticInfo stStaticinfo;
 		spFunction->GetSystemStaticInfo(stStaticinfo);
-		if (stricmp(stStaticinfo.strMachineType,"RVC.PAD")==0)
-		{
-			m_bIsPadType = TRUE;
-		}
-		else
-		{
-			m_bIsPadType = FALSE;
+		if (stricmp(stStaticinfo.strMachineType,"RVC.Stand1SPlus")==0){
+			m_bSingleCamera = true;
 		}
 
-		if (!m_bIsPadType) 
-		{
-			spFunction->SetTimer(1, this, 500);
-		}
 		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);
@@ -136,7 +127,6 @@ public:
 	virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext) 
 	{ 
 		CSmartPointer<IEntityFunction> spFunction = GetFunction();
-		spFunction->KillTimer(1); // if timer 1 not exist also ok
 		delete m_facecapture;
 		m_facecapture = NULL;
 		spFunction->UnsubscribeLog(m_UUid1);
@@ -179,6 +169,7 @@ public:
 		}
 		else if (dwUserCode == LOG_EVT_MEDIACONTROLLER_CAMERA_STARTED)
 		{
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("recv LOG_EVT_MEDIACONTROLLER_CAMERA_STARTED event");
 			CSimpleStringA strValue;
 			GetFunction()->GetSysVar("CameraState", strValue);
 #if defined(RVC_OS_WIN)
@@ -186,7 +177,8 @@ public:
 			if (3 != iState) {
 				m_facecapture->SetCameraState(iState);
 				m_facecapture->StartFaceCapture();
-			} else {
+			} 
+			else {
 				m_facecapture->SetCameraState(3);
 			}
 #else
@@ -209,19 +201,25 @@ public:
 				m_facecapture->SetCameraState(3);
 			}	
 #endif //RVC_OS_WIN
+			if (!m_bSingleCamera) {
+				GetFunction()->SetTimer(1, this, 1000);
+			}
 		}
 		else if (dwUserCode == LOG_EVT_MEDIACONTROLLER_CAMERA_STOPPED)
 		{
-#if defined(RVC_OS_LINUX)
-			m_facecapture->SetCameraState(3);
-#endif //RVC_OS_LINUX
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("recv LOG_EVT_MEDIACONTROLLER_CAMERA_STOPPED event");
+			
 			m_facecapture->StopFaceCapture();
-#if defined(RVC_OS_WIN)
 			CSimpleStringA strValue;
 			GetFunction()->GetSysVar("CameraState", strValue);
 			int iState = TransCameraStateToInt(strValue[0]);
 			m_facecapture->SetCameraState(iState);
-#endif //RVC_OS_WIN
+
+			if (!m_bSingleCamera) {
+				GetFunction()->KillTimer(1);
+			}
+
+			GetFunction()->SetSysVar(SYSVAR_ACTIVETRACKINGCAMERA, ACTIVETRACKINGCAMERA_ENV); // from Operation -> Environment
 		}
 	}
 
@@ -266,7 +264,6 @@ public:
 	
 	virtual void OnTimeout(DWORD dwTimerID)
 	{
-		//LOG_FUNCTION();
 		__int64 uid;
 		CCustomerStatus status;
 		//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("before GetMainCustomerStatus");
@@ -280,7 +277,7 @@ public:
 			{
 				if (strValue[0] == 'O') 
 				{
-					//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ActiveTrackingCamera change from Opt->Env!");
+					DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ActiveTrackingCamera change from Opt->Env!");
 					spFunction->SetSysVar(SYSVAR_ACTIVETRACKINGCAMERA, ACTIVETRACKINGCAMERA_ENV); // from Operation -> Environment
 				}
 			} 
@@ -288,7 +285,7 @@ public:
 			{
 				if (strValue[0] == 'E') 
 				{
-					//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ActiveTrackingCamera change from Env->Opt!");
+					DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ActiveTrackingCamera change from Env->Opt!");
 					spFunction->SetSysVar(SYSVAR_ACTIVETRACKINGCAMERA, ACTIVETRACKINGCAMERA_OPT); // from Environment -> Operation
 				}
 			}			
@@ -307,9 +304,9 @@ public:
 		return m_lastUUID;
 	}
 
-	virtual BOOL IsCustomerChange()
+	virtual bool IsCustomerChange()
 	{
-		BOOL bChange = bIsSessionChange||bIsCustomerChange;
+		bool bChange = bIsSessionChange||bIsCustomerChange;
 		return bChange;
 	}
 
@@ -336,20 +333,21 @@ public:
 				snprintf(FaceName, uLen, "%s%s%s_%s", (LPCSTR)strPath, SPLIT_SLASH_STR, strSessionID.GetData(), strCustomerID.GetData());
 #endif // RVC_OS_WIN
 			}
-			bIsSessionChange = FALSE;
-			bIsCustomerChange = FALSE;
+			bIsSessionChange = false;
+			bIsCustomerChange = false;
 		} 
 		else 
 		{
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("getpath uploadphoto failed!");
 		}
 	}
-	virtual BOOL LoadConfig(CFaceCaptureConfig &config)
+
+	virtual bool LoadConfig(CFaceCaptureConfig &config)
 	{
 		CSmartPointer<IEntityFunction> spFunction = GetFunction();
 		CSmartPointer<IConfigInfo> spConfig;
 		ErrorCodeEnum Error(Error_Succeed);
-		if (FALSE && (Error = spFunction->OpenConfig(Config_CenterSetting, spConfig)) == Error_Succeed) {
+		if (false && (Error = spFunction->OpenConfig(Config_CenterSetting, spConfig)) == Error_Succeed) {
 			SpIniMappingTable table;
 			table.AddEntryInt("general", "PrimCamera", config.nPrimCamera, 0);
 			table.AddEntryInt("general", "ContourMinAera", config.nContourMinAera, 0);
@@ -414,29 +412,18 @@ public:
 	{
 		va_list arg;
 		va_start(arg, fmt);
-
-#if defined(RVC_OS_WIN)
-		int n = _vscprintf(fmt, arg);
-#else
 		int n = vsnprintf(NULL, 0, fmt, arg);
-#endif //RVC_OS_WIN
+
 		if (n >= MAX_LOG_LEN) {
 			char* buf = (char*)malloc((size_t)(n + 1));
-#if defined(RVC_OS_WIN)
-			_vsnprintf(buf, n + 1, fmt, arg);
-#else
 			vsnprintf(buf, n + 1, fmt, arg);
-#endif //RVC_OS_WIN
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
 			free(buf);
 		}
 		else{
 			char strlog[MAX_LOG_LEN] = {0};
-#if defined(RVC_OS_WIN)
-			_vsnprintf(strlog, MAX_LOG_LEN, fmt, arg);
-#else
 			vsnprintf(strlog, MAX_LOG_LEN, fmt, arg);
-#endif //RVC_OS_WIN
+
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
 		}
 		va_end(arg);
@@ -492,14 +479,14 @@ private:
 		{
 			GetFunction()->GetSysVar("SessionID",strSessionID);
 			//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("sessionID change to %s",strSessionID);
-			bIsSessionChange = TRUE;
+			bIsSessionChange = true;
 		}
 
 		if (_stricmp(pszKey,"CustomerID") == 0)
 		{
 			GetFunction()->GetSysVar("CustomerID",strCustomerID);
 			//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("customerID change to %s",strCustomerID);
-			bIsCustomerChange = TRUE;
+			bIsCustomerChange = true;
 		}
 
 		if (_stricmp(pszKey,"CameraState") == 0)
@@ -529,14 +516,14 @@ private:
 
 private:
 	CUUID m_UUid1,m_UUid2,m_UUid3;
-	BOOL bIsSessionChange;
-	BOOL bIsCustomerChange;
-	BOOL m_bIsPadType;
+	bool bIsSessionChange;
+	bool bIsCustomerChange;
 	CSimpleStringA strCustomerID;
 	CSimpleStringA strSessionID;
 	CUUID m_lastUUID;
 	ChannelClient *m_pChannelClient;
 	Clibfacecapture *m_facecapture;
+	bool m_bSingleCamera;
 };
 
 void ChannelClient::OnMessage( ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData )

+ 4 - 4
Other/unix/libfacecapture/libfacecapture.cpp

@@ -174,7 +174,7 @@ void GetLocalTimeRVC(SYSTEMTIME& stTime)
 class Clibfacecapture_impl
 {
 public:
-	Clibfacecapture_impl(BOOL *pResult,CHostApi *pHostAPI,CVideoMonitorEvent*pHost,LPCSTR EnvironMinVideoName,LPCSTR EnvironMaxVideoName,LPCSTR OperateVideoName=NULL,MonitorEnum eMonitorType=MotionTarckAndFaceDetect)
+	Clibfacecapture_impl(bool *pResult,CHostApi *pHostAPI,CVideoMonitorEvent*pHost,LPCSTR EnvironMinVideoName,LPCSTR EnvironMaxVideoName,LPCSTR OperateVideoName=NULL,MonitorEnum eMonitorType=MotionTarckAndFaceDetect)
 	{
 		m_pResult = pResult;
 		m_pHostApi = pHostAPI;
@@ -380,7 +380,7 @@ private:
 	sem_t m_semt;
 
 #endif
-	BOOL* m_pResult;
+	bool* m_pResult;
 	MonitorEnum m_eType;
 
 	CvHaarClassifierCascade* m_pFaceCascade;	//脸部分类器
@@ -2496,7 +2496,7 @@ public:
 #else
 		sem_post(&m_semt);
 		if (0 == pthread_join(m_videomonitorthreadid, NULL)) {
-			//m_pHostApi->Debug("thread join video monitor thread %u success!", m_videomonitorthreadid);
+			m_pHostApi->Debug("thread join video monitor thread %u success!", m_videomonitorthreadid);
 			m_videomonitorthreadid = 0;
 		}
 		else{
@@ -2750,7 +2750,7 @@ public:
 
 // 这是已导出类的构造函数。
 // 有关类定义的信息,请参阅 libfacecapture.h
-Clibfacecapture::Clibfacecapture(BOOL *pResult,CHostApi *pHostAPI,CVideoMonitorEvent*pHost,LPCSTR EnvironMinVideoName,LPCSTR EnvironMaxVideoName,LPCSTR OperateVideoName,MonitorEnum eMonitorType)
+Clibfacecapture::Clibfacecapture(bool *pResult,CHostApi *pHostAPI,CVideoMonitorEvent*pHost,LPCSTR EnvironMinVideoName,LPCSTR EnvironMaxVideoName,LPCSTR OperateVideoName,MonitorEnum eMonitorType)
 {
 	m_pImpl = new Clibfacecapture_impl(pResult,pHostAPI,pHost,EnvironMinVideoName,EnvironMaxVideoName,OperateVideoName,eMonitorType);
 }

+ 3 - 3
Other/unix/libfacecapture/libfacecapture.h

@@ -186,8 +186,8 @@ struct __declspec(novtable) CHostApi
 {
 	virtual unsigned __int64 GenerateUUID() = 0;
 	virtual void GetFaceImgName(char* FaceName, size_t uLen) = 0;
-	virtual BOOL IsCustomerChange() = 0;
-	virtual BOOL LoadConfig(CFaceCaptureConfig &config) = 0;
+	virtual bool IsCustomerChange() = 0;
+	virtual bool LoadConfig(CFaceCaptureConfig &config) = 0;
 	virtual void Debug(const char *fmt, ...) = 0;
 };
 
@@ -205,7 +205,7 @@ public:
 	//OperateVideoName:操作摄像头共享视频队列的文件名
 	//OperateVideoName默认为Null时设备运行于单摄像头模式
 	//开始视频监控,pHost:事件,nMonitorFreq:监控频率,单位ms,MonitorType:监控类型,有三种模式可供选择
-	Clibfacecapture(BOOL *pResult, CHostApi *pHostAPI,CVideoMonitorEvent*pHost,LPCSTR EnvironMinVideoName,LPCSTR EnvironMaxVideoName = NULL,LPCSTR OperateVideoName=NULL,MonitorEnum eMonitorType=MotionTarckAndFaceDetect);
+	Clibfacecapture(bool *pResult, CHostApi *pHostAPI,CVideoMonitorEvent*pHost,LPCSTR EnvironMinVideoName,LPCSTR EnvironMaxVideoName = NULL,LPCSTR OperateVideoName=NULL,MonitorEnum eMonitorType=MotionTarckAndFaceDetect);
 	~Clibfacecapture(void);
 
 	bool StartFaceCapture();

+ 3 - 3
Other/win/libfacecapture/libfacecapture.cpp

@@ -104,7 +104,7 @@ enum MonitorStateEnum
 class Clibfacecapture_impl
 {
 public:
-	Clibfacecapture_impl(BOOL *pResult,CHostApi *pHostAPI,CVideoMonitorEvent*pHost,LPCSTR EnvironMinVideoName,LPCSTR EnvironMaxVideoName,LPCSTR OperateVideoName=NULL,MonitorEnum eMonitorType=MotionTarckAndFaceDetect)
+	Clibfacecapture_impl(bool *pResult,CHostApi *pHostAPI,CVideoMonitorEvent*pHost,LPCSTR EnvironMinVideoName,LPCSTR EnvironMaxVideoName,LPCSTR OperateVideoName=NULL,MonitorEnum eMonitorType=MotionTarckAndFaceDetect)
 	{
 		m_pResult = pResult;
 		m_pHostApi = pHostAPI;
@@ -298,7 +298,7 @@ private:
 	HANDLE m_hStopEventWait; // CreateEvent
 
 	CRITICAL_SECTION CS;
-	BOOL* m_pResult;
+	bool* m_pResult;
 	MonitorEnum m_eType;
 	CvHaarClassifierCascade* m_pFaceCascade;	//脸部分类器
 	CvHaarClassifierCascade* m_pEyeCascade;		//眼睛分类器
@@ -2564,7 +2564,7 @@ public:
 
 // 这是已导出类的构造函数。
 // 有关类定义的信息,请参阅 libfacecapture.h
-Clibfacecapture::Clibfacecapture(BOOL *pResult,CHostApi *pHostAPI,CVideoMonitorEvent*pHost,LPCSTR EnvironMinVideoName,LPCSTR EnvironMaxVideoName,LPCSTR OperateVideoName,MonitorEnum eMonitorType)
+Clibfacecapture::Clibfacecapture(bool *pResult,CHostApi *pHostAPI,CVideoMonitorEvent*pHost,LPCSTR EnvironMinVideoName,LPCSTR EnvironMaxVideoName,LPCSTR OperateVideoName,MonitorEnum eMonitorType)
 {
 	m_pImpl = new Clibfacecapture_impl(pResult,pHostAPI,pHost,EnvironMinVideoName,EnvironMaxVideoName,OperateVideoName,eMonitorType);
 }

+ 3 - 3
Other/win/libfacecapture/libfacecapture.h

@@ -174,8 +174,8 @@ struct __declspec(novtable) CHostApi
 {
 	virtual unsigned __int64 GenerateUUID() = 0;
 	virtual void GetFaceImgName(char* FaceName, size_t uLen) = 0;
-	virtual BOOL IsCustomerChange() = 0;
-	virtual BOOL LoadConfig(CFaceCaptureConfig &config) = 0;
+	virtual bool IsCustomerChange() = 0;
+	virtual bool LoadConfig(CFaceCaptureConfig &config) = 0;
 	virtual void Debug(const char *fmt, ...) = 0;
 };
 
@@ -193,7 +193,7 @@ public:
 	//OperateVideoName:操作摄像头共享视频队列的文件名
 	//OperateVideoName默认为Null时设备运行于单摄像头模式
 	//开始视频监控,pHost:事件,nMonitorFreq:监控频率,单位ms,MonitorType:监控类型,有三种模式可供选择
-	Clibfacecapture(BOOL *pResult, CHostApi *pHostAPI,CVideoMonitorEvent*pHost,LPCSTR EnvironMinVideoName,LPCSTR EnvironMaxVideoName = NULL,LPCSTR OperateVideoName=NULL,MonitorEnum eMonitorType=MotionTarckAndFaceDetect);
+	Clibfacecapture(bool *pResult, CHostApi *pHostAPI,CVideoMonitorEvent*pHost,LPCSTR EnvironMinVideoName,LPCSTR EnvironMaxVideoName = NULL,LPCSTR OperateVideoName=NULL,MonitorEnum eMonitorType=MotionTarckAndFaceDetect);
 	~Clibfacecapture(void);
 
 	bool StartFaceCapture();