浏览代码

Z991240-987 #comment first commit

Signed-Off-By: commit-hook
陈富强80252003 4 年之前
父节点
当前提交
c4b65704ad

+ 2 - 2
Module/CMakeLists.txt

@@ -1,4 +1,4 @@
-
+
 #设置实体名称 ${MODULE_NAME},和实体前缀定义 ${MODULE_PREFIX}
 macro(define_module _module_name)
 	set(MODULE_NAME "mod_${_module_name}")
@@ -205,7 +205,7 @@ add_subdirectory(mod_heartbeat)
 add_subdirectory(mod_alarm)
 add_subdirectory(mod_RomoteController)
 add_subdirectory(mod_ResourceWatcher)
-#add_subdirectory(mod_livenessdetection)
+add_subdirectory(mod_livenessdetection)
 
 #below should be compiled succesufully.
 add_subdirectory(mod_SalesRecorder)

+ 146 - 0
Module/mod_livenessdetection/CMakeLists.txt

@@ -0,0 +1,146 @@
+define_module("livenessdetection")
+
+if(MSVC)
+    set(WIN_SRC 
+	LivenessDetectionFSM.h
+	LivenessDetectionFSM.cpp
+	YituLiveSDK.h
+	YituLiveSDK.cpp
+	stdafx.h
+	stdafx.cpp)
+else()
+	set(WIN_SRC )
+endif(MSVC)
+
+set(${MODULE_PREFIX}_SRCS
+	#Common.h
+    #Common.cpp
+	MyEvent.h
+    LivenessDetection_client_g.h
+	LivenessDetection_def_g.h
+	LivenessDetection_msg_g.h
+	LivenessDetection_server_g.h
+	mod_livenessdetection.h
+	mod_livenessdetection.cpp
+	#RvcFaceCapture.h
+	#RvcFaceCapturer.h
+    #RvcFaceCapturer.cpp
+	#SingleTimer.h
+    #SingleTimer.cpp
+	#${WIN_SRC}
+)
+
+if(RVC_DEBUG_MODE)
+set(OPENCV_DYNAMIC_LIBS 
+opencv_calib3d 
+opencv_core 
+opencv_features2d 
+opencv_flann 
+opencv_highgui 
+opencv_imgcodecs 
+opencv_imgproc 
+opencv_ml 
+opencv_objdetect 
+opencv_photo 
+opencv_video 
+opencv_videoio 
+opencv_videostab
+)
+else()
+set(OPENCV_DYNAMIC_LIBS
+opencv_calib3d 
+opencv_core 
+opencv_features2d 
+opencv_flann 
+opencv_highgui 
+opencv_imgcodecs 
+opencv_imgproc 
+opencv_ml 
+opencv_objdetect 
+opencv_photo 
+opencv_video 
+opencv_videoio 
+opencv_videostab
+)
+endif(RVC_DEBUG_MODE)
+
+set(MOD_VERSION_STRING "0.0.1-dev1")
+add_module_libraries(${MODULE_PREFIX} ${MODULE_NAME} ${MOD_VERSION_STRING})
+
+if(MSVC)
+#add_precompiled_header(${MODULE_NAME} stdafx.h SOURCE_CXX stdafx.cpp FORCEINCLUDE)
+endif(MSVC)
+
+
+if(MSVC)
+conan_cmake_run(REQUIRES opencv/3.1.0@LR04.02_ThirdParty/testing
+BASIC_SETUP CMAKE_TARGETS)
+else()
+conan_cmake_run(REQUIRES opencv/3.1.0@LR04.02_ThirdParty/stable
+BASIC_SETUP CMAKE_TARGETS
+BUILD missing)
+endif(MSVC)
+
+if(WIN32)
+conan_cmake_run(REQUIRES ffmpeg/4.1@LR04.02_ThirdParty/testing
+BASIC_SETUP CMAKE_TARGETS
+BUILD missing)
+else(WIN32)
+conan_cmake_run(REQUIRES ffmpeg/4.1.6@LR04.02_ThirdParty/stable
+BASIC_SETUP CMAKE_TARGETS
+BUILD missing)
+endif(WIN32)
+
+target_include_directories(${MODULE_NAME} PRIVATE
+	${RVC_FRAMEWORK_INCLUDES_DIR}
+	${RVC_COMMON_INCLUDE_DIR}
+	${CONAN_RVCFRAMEWORK_ROOT}/include/libtoolkit
+	${CONAN_INCLUDE_DIRS_OPENCV}
+    ${CONAN_INCLUDE_DIRS_OPENCV}/opencv
+	${CONAN_INCLUDE_DIRS_FFMPEG}
+	${OTHER_LIB_BASE_DIR}/libvideoqueue
+	${OTHER_LIB_BASE_DIR}/libvideoframework
+	${MODULE_BASE_DIR}/mod_customeraware
+	${MODULE_BASE_DIR}/mod_facetracking
+	${MODULE_BASE_DIR}/include
+)
+
+message(STATUS "RVC_FRAMEWORK_INCLUDES_DIR == ${RVC_FRAMEWORK_INCLUDES_DIR}")
+
+target_link_directories(${MODULE_NAME} PRIVATE
+	#${CONAN_LIB_DIRS_OPENCV}
+	${CONAN_BIN_DIRS_OPENCV}
+	${CONAN_LIB_DIRS_FFMPEG}
+	${RVC_FRAMEWORK_LIBRARIES_DIR}
+)
+
+
+# 添加实体需要依赖的其他共享库(包括系统库)
+if(WIN32)
+set(${MODULE_PREFIX}_LIBS  ${MODULE_BASE_LIBS} 
+	${OPENCV_DYNAMIC_LIBS}
+	${SPBASE_LIB}
+	libvideoframework
+	videoqueue
+)
+else(WIN32)
+set(${MODULE_PREFIX}_LIBS  ${MODULE_BASE_LIBS} 
+	${OPENCV_DYNAMIC_LIBS}
+	${SPBASE_LIB}
+	libvideoframework
+	videoqueue
+)
+endif(WIN32)
+
+
+target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
+
+
+deploy_module(${MODULE_PREFIX} ${MODULE_NAME})
+
+
+if(MSVC)
+	set(MODULE_CONAN_DEP_LIBS ${MODULE_CONAN_DEP_LIBS} ${CONAN_BIN_DIRS} PARENT_SCOPE)
+else()
+	set(MODULE_CONAN_DEP_LIBS ${MODULE_CONAN_DEP_LIBS} ${CONAN_LIB_DIRS} PARENT_SCOPE)
+endif(MSVC)

+ 2 - 22
Module/mod_livenessdetection/Common.cpp

@@ -4,6 +4,8 @@
 #include <highgui.h>
 #pragma comment(lib, "Msimg32.lib")
 
+using namespace cv;
+
 namespace LivenessDetection {
 	// pJPG需要自己开辟自己释放
 	void RGB2JPG(const void* pRGB, int width, int height, int *nJpgSize, char* pJPG, CEntityBase *pDetection, RECT *pROI)
@@ -127,26 +129,4 @@ namespace LivenessDetection {
 			}
 		}
 	}
-
-	void DrawRectangle(HWND hWnd, RECT &rect, int iWidth, RECT &echoWinRect)
-	{
-		HDC hdc = ::GetDC(hWnd);
-
-		HPEN pen = CreatePen(PS_SOLID,iWidth,RGB(0,255,0));
-		HPEN oldPen = (HPEN)SelectObject(hdc,pen);//画笔选入设备描述表,并返回当前的画笔
-		HBRUSH brush = (HBRUSH)GetStockObject(NULL_BRUSH);//创建一个透明的画刷
-		HBRUSH oldBrush = (HBRUSH)SelectObject(hdc,brush);//选择画刷
-		Rectangle(hdc,rect.left,rect.top,rect.right,rect.bottom);
-		FillRect(hdc,&rect,brush);//恢复以前 的画刷
-		SelectObject(hdc,oldBrush);//恢复以前的画笔
-		SelectObject(hdc,oldPen);//刷新视图
-
-		DeleteObject(pen);
-		DeleteObject(brush);
-		DeleteObject(oldPen);
-		DeleteObject(oldBrush);
-
-		InvalidateRect(hWnd,&rect,FALSE);
-		UpdateWindow(hWnd);
-	}
 }

+ 0 - 0
Module/mod_livenessdetection/Event.h → Module/mod_livenessdetection/MyEvent.h


+ 62 - 0
Module/mod_livenessdetection/RvcFaceCapture.h

@@ -0,0 +1,62 @@
+#ifndef RVC_FACE_CAPTURE_H_
+#define RVC_FACE_CAPTURE_H_
+
+#ifdef RVC_OS_WIN
+#ifdef RVCFACECAPTURE_EXPORTS
+#define RVCFACECAPTURE_API extern "C" __declspec(dllexport)
+#else
+#define RVCFACECAPTURE_API extern "C" __declspec(dllimport)
+#endif
+#else
+#define RVCFACECAPTURE_API
+#endif
+
+#include <Windows.h>
+
+
+struct IFaceCapCallback
+{
+	virtual void OnFaceCapImgInfo(const char* msg) = 0;
+	virtual void OnEchoCamera(int cameraID) = 0;
+	virtual void OnFaceCapDone() = 0;
+	virtual ~IFaceCapCallback() { /*nothing to implement*/ }
+};
+
+struct RVC_ImageData
+{
+	BITMAP *pImage;         //image data
+	int nCameraID;          //identify
+	double dTimeStamp;      //seconds from 1970.1.1, in ms precision
+	int nFrameID;           //frame id, independent for each camera
+};
+
+struct RVC_FaceRect
+{
+	int x;
+	int y;
+	int width;
+	int height;
+};
+
+struct RVC_TrackData        //structure and functions for debug
+{
+	int mCameraId;
+	int mLastFrameId;
+	RVC_FaceRect rectFace;
+};
+
+RVCFACECAPTURE_API int Init(IFaceCapCallback *pCallback);
+
+RVCFACECAPTURE_API int StartCapture();
+
+RVCFACECAPTURE_API int FeedFrame(RVC_ImageData *pData);
+
+RVCFACECAPTURE_API int StopCapture();
+
+RVCFACECAPTURE_API int UnInit();
+
+RVCFACECAPTURE_API int GetImage(BITMAP* pbitmap, RVC_FaceRect* rectFace);
+
+RVCFACECAPTURE_API int GetTrackData(int nCameraID, RVC_TrackData* pData);
+
+#endif

+ 4 - 2
Module/mod_livenessdetection/RvcFaceCapturer.cpp

@@ -1,8 +1,10 @@
+#ifdef RVC_OS_WIN
 #include "stdafx.h"
+#endif // RVC_OS_WIN
 #include "RvcFaceCapturer.h"
-#include "Event.h"
+#include "MyEvent.h"
 #include "Common.h"
-#include "..\..\Other\libvideoframework\videoutil.h"
+#include "../../Other/libvideoframework/videoutil.h"
 #include <process.h>
 
 namespace RvcFaceCapture

+ 1 - 1
Module/mod_livenessdetection/RvcFaceCapturer.h

@@ -6,7 +6,7 @@
 #include "RvcFaceCapture.h"
 #include "SpBase.h"
 #include "SingleTimer.h"
-#include "..\..\Other\libvideoqueue\libvideoqueue.h"
+#include "../../Other/libvideoqueue/libvideoqueue.h"
 
 namespace RvcFaceCapture
 {

+ 0 - 1
Module/mod_livenessdetection/SingleTimer.cpp

@@ -1,4 +1,3 @@
-#include "stdafx.h"
 #include "SingleTimer.h"
 
 UINT WINAPI TimerWaitThread(LPVOID pM);

+ 59 - 5
Module/mod_livenessdetection/mod_livenessdetection.cpp

@@ -1,8 +1,13 @@
+#ifdef RVC_OS_WIN
 #include "stdafx.h"
+#endif // RVC_OS_WIN
 #include "mod_livenessdetection.h"
 
-CLivenessDetectionEntity::CLivenessDetectionEntity(): m_bStarted(FALSE), m_nCaptureType(-1), m_pFsm(NULL), m_pCapturer(NULL)
+CLivenessDetectionEntity::CLivenessDetectionEntity(): m_bStarted(FALSE), m_nCaptureType(-1)//, m_pCapturer(NULL)
 {
+#ifdef RVC_OS_WIN
+	m_pFsm = NULL;
+#endif
 	//m_pFsm = new CLivenessDetectionFSM(8,REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE,REC_COMMON_VIDEO_OPT_SHM_SNAPSHOT_QUEUE);
 }
 
@@ -84,13 +89,23 @@ ErrorCodeEnum CLivenessDetectionEntity::__OnStart(ErrorCodeEnum preOperationErro
 	
 	if (ePadtype==m_eDeviceType||eMobilePadType==m_eDeviceType||eDesk2SType==m_eDeviceType)
 	{
+#ifdef RVC_OS_WIN
 		m_pFsm = new CLivenessDetectionFSM(8,REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE,NULL,640,360);
-		m_pCapturer = new RvcFaceCapture::RvcFaceCapturer(REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE,NULL,640,360);
+#endif
+
+#ifndef CLOSE_CAPTURE
+		m_pCapturer = new RvcFaceCapture::RvcFaceCapturer(REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE, NULL, 640, 360);
+#endif // !CLOSE_CAPTURE
 	}
 	else
 	{
+#ifdef RVC_OS_WIN
 		m_pFsm = new CLivenessDetectionFSM(8,REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE,REC_COMMON_VIDEO_OPT_SHM_SNAPSHOT_QUEUE,640,360);
-		m_pCapturer = new RvcFaceCapture::RvcFaceCapturer(REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE,REC_COMMON_VIDEO_OPT_SHM_SNAPSHOT_QUEUE,640,360);
+#endif
+#ifndef CLOSE_CAPTURE
+		m_pCapturer = new RvcFaceCapture::RvcFaceCapturer(REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE, REC_COMMON_VIDEO_OPT_SHM_SNAPSHOT_QUEUE, 640, 360);
+#endif // !CLOSE_CAPTURE
+
 	}
 
 	int i = 0;
@@ -120,6 +135,7 @@ ErrorCodeEnum CLivenessDetectionEntity::__OnStart(ErrorCodeEnum preOperationErro
 		nActiveCamera = CAMERA_TYPE_ENV;
 	}
 
+#ifdef RVC_OS_WIN
 	//MessageBox(NULL,"hh","tishi",0);
 	ErrorCodeEnum rt = m_pFsm->Init(this);
 	Dbg("FsmInit:%d", rt);
@@ -127,13 +143,16 @@ ErrorCodeEnum CLivenessDetectionEntity::__OnStart(ErrorCodeEnum preOperationErro
 	{
 		return rt;
 	}
+#endif
 
+#ifndef CLOSE_CAPTURE
 	rt = m_pCapturer->Init(this);
 	Dbg("CapturerInit:0x%08x", rt);
 	if (rt!=Error_Succeed)
 	{
 		return rt;
 	}
+#endif
 
 	return Error;
 }
@@ -150,15 +169,18 @@ ErrorCodeEnum CLivenessDetectionEntity::__OnClose( ErrorCodeEnum preOperationErr
 		spFunction->UnsubscribeLog(m_arrListener[i]);
 	}
 
+#ifdef RVC_OS_WIN
 	m_pFsm->OnExit();
 
 	delete m_pFsm;
 	m_pFsm = NULL;
+#endif
 
+#ifndef CLOSE_CAPTURE
 	m_pCapturer->UnInit();
-
 	delete m_pCapturer;
 	m_pCapturer = NULL;
+#endif
 
 	ErrorCodeEnum Error = Error_Succeed;
 	return Error;
@@ -222,8 +244,12 @@ void CLivenessDetectionEntity::OnSysVarEvent( const char *pszKey, const char *ps
 		else if(pszValue[0] == 'B')   ///////显示贴图
 		{
 			nActiveCamera = CAMERA_TYPE_ERROR;
+#ifdef RVC_OS_WIN
 			m_pFsm->NotifyCameraFault();      // 摄像头故障,停止捕获
+#endif
+#ifndef CLOSE_CAPTURE
 			m_pCapturer->NotifyCameraFault(); // 摄像头故障,停止捕获
+#endif
 		}
 		else if (pszValue[0] == 'N')
 		{
@@ -286,6 +312,7 @@ void CLivenessDetectionEntity::StartLivenessDetection( SpReqAnsContext<LivenessD
 		bool bDoActiveDetect=CSimpleStringW2A(ctx->Req.Reserved)=="Y"?true:false;
 		if(!ctx->Req.IsActive||bDoActiveDetect) // 禁止pad或低柜双屏做被动捕获或者带活体检测的主动捕获
 		{
+#ifdef RVC_OS_WIN
 			ctx->Answer(Error_Succeed); // 告知中台已经收到了启动活体请求
 			Dbg("Pad or desk2s VTM only support active capture without liveness now!");
 			DetectionStopUnExpected evt;
@@ -295,30 +322,47 @@ void CLivenessDetectionEntity::StartLivenessDetection( SpReqAnsContext<LivenessD
 			evt.ErrorMsg = CSimpleStringA2W("Pad版或低柜双屏版VTM暂仅支持不带活体检测的主动捕获!");
 			SpSendBroadcast(GetFunction(), SP_MSG_OF(DetectionStopUnExpected), SP_MSG_SIG_OF(DetectionStopUnExpected), evt);
 			return;
+#else
+			ctx->Answer(Error_Succeed); // 告知中台已经收到了启动活体请求
+			Dbg("linux机器暂不支持活体检测");
+			DetectionStopUnExpected evt;
+			evt.IsActive = (false);
+			evt.ActionID = ctx->Req.ActionID;
+			evt.ErrorCode = CSimpleStringA2W("Error_LiveDetectType");
+			evt.ErrorMsg = CSimpleStringA2W("linux机器暂不支持活体检测");
+			SpSendBroadcast(GetFunction(), SP_MSG_OF(DetectionStopUnExpected), SP_MSG_SIG_OF(DetectionStopUnExpected), evt);
+#endif
 		}
 	}
 	if (ctx->Req.IsActive&&CSimpleStringW2A(ctx->Req.Reserved)=="S")
 	{
 		ctx->Answer(Error_Succeed);
+#ifndef CLOSE_CAPTURE
 		if (ctx->Req.ActionID.GetLength()>0)
 		{
 			m_pCapturer->m_ActionID=CSimpleStringW2A(ctx->Req.ActionID);
 		}
 		else
 		{
-			m_pCapturer->m_ActionID=m_pFsm->m_uid.ToString();
+			m_pCapturer->m_ActionID= CUUID::Create(m_pCapturer->m_ActionID)
 		}
 		
 		m_pCapturer->StartFaceCapture();
+#endif
 	}
 	else
 	{
+#ifdef RVC_OS_WIN
 		m_pFsm->StartLiveDetect(ctx);
+#else
+		Dbg("linux机器暂不支持活体检测");
+#endif
 	}
 }
 
 void CLivenessDetectionEntity::StopLivenessDetection( SpReqAnsContext<LivenessDetectionService_StopLivenessDetection_Req, LivenessDetectionService_StopLivenessDetection_Ans>::Pointer ctx )
 {
+#ifdef RVC_OS_WIN
 	bool bHasCapTask = m_pCapturer->GetHasCapTask();
 	bool bHasLiveTask = m_pFsm->GetHasLiveTask();
 
@@ -342,6 +386,16 @@ void CLivenessDetectionEntity::StopLivenessDetection( SpReqAnsContext<LivenessDe
 	{
 		m_pFsm->SetActiveStopLiveDetect(ctx);
 	}
+#else
+#ifndef CLOSE_CAPTURE
+	bool bHasCapTask = m_pCapturer->GetHasCapTask();
+	if (bHasCapTask) 
+	{
+		m_pCapturer->StopFaceCapture();
+		ctx->Answer(Error_Succeed);
+	}
+#endif
+#endif
 }
 
 void LivenessDetectionServerSession::Handle_StartLivenessDetection( SpReqAnsContext<LivenessDetectionService_StartLivenessDetection_Req, LivenessDetectionService_StartLivenessDetection_Ans>::Pointer ctx )

+ 16 - 3
Module/mod_livenessdetection/mod_livenessdetection.h

@@ -2,21 +2,30 @@
 #define MOD_LIVENESSDETECTION_H
 #pragma once
 
+#define CLOSE_CAPTURE 
+
+#ifdef RVC_OS_WIN
 #include "stdafx.h"
+#endif // RVC_OS_WIN
 #include "SpBase.h"
 #include "SpIni.h"
 #include "rec_common.h"
-#include "..\\mod_customeraware\\Event.h"
-#include "..\\mod_facetracking\\sysvar.h"
+#include "Event.h"
+#include "sysvar.h"
+#ifdef RVC_OS_WIN
 #include "LivenessDetectionFSM.h"
+#endif // RVC_OS_WIN
+
+#ifndef CLOSE_CAPTURE
 #include "RvcFaceCapturer.h"
+#endif // !CLOSE_CAPTURE
 
 #include "LivenessDetection_def_g.h"
 #include "LivenessDetection_msg_g.h"
 #include "LivenessDetection_server_g.h"
 
 #include <assert.h>
-#include "..\EventCode.h"
+#include "EventCode.h"
 
 using namespace LivenessDetection;
 
@@ -91,8 +100,12 @@ private:
 	int m_nCaptureType;
 
 private:
+#ifdef RVC_OS_WIN
 	CLivenessDetectionFSM *m_pFsm;
+#endif
+#ifndef CLOSE_CAPTURE
 	RvcFaceCapture::RvcFaceCapturer *m_pCapturer;
+#endif // !CLOSE_CAPTURE
 };
 
 #endif