You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

118 lines
4.6 KiB

#ifndef __IMAGE_MILL_DLIB_WORKER_HEADER__
#define __IMAGE_MILL_DLIB_WORKER_HEADER__
#include "../../lib/components/base/basicThread.h"
#include "../../lib/components/base/basicMutex.h"
#include "../../lib/components/base/basicSettingsProvider.h"
#include "../../lib/components/base/basicEventHeap.h"
#include "IM_DataStructs.h"
#include "IM_DataBaseAdapter.h"
#define DLIB
#ifdef DLIB
#define GPU
//#include <darknet/darknet.h>
//#include <darknet/yolo_v2_class.hpp>
#undef GPU
#endif
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/dnn/dnn.hpp>
#include <dlib/dnn.h>
#include <dlib/gui_widgets.h>
#include <dlib/clustering.h>
#include <dlib/string.h>
#include <dlib/image_io.h>
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/opencv.h>
using namespace cv;
using namespace dlib;
using namespace std;
template <template <int,template<typename>class,int,typename> class block, int N, template<typename>class BN, typename SUBNET>
using residual = add_prev1<block<N,BN,1,tag1<SUBNET>>>;
template <template <int,template<typename>class,int,typename> class block, int N, template<typename>class BN, typename SUBNET>
using residual_down = add_prev2<avg_pool<2,2,2,2,skip1<tag2<block<N,BN,2,tag1<SUBNET>>>>>>;
template <int N, template <typename> class BN, int stride, typename SUBNET>
using block = BN<con<N,3,3,1,1,relu<BN<con<N,3,3,stride,stride,SUBNET>>>>>;
template <int N, typename SUBNET> using ares = relu<residual<block,N,affine,SUBNET>>;
template <int N, typename SUBNET> using ares_down = relu<residual_down<block,N,affine,SUBNET>>;
template <typename SUBNET> using alevel0 = ares_down<256,SUBNET>;
template <typename SUBNET> using alevel1 = ares<256,ares<256,ares_down<256,SUBNET>>>;
template <typename SUBNET> using alevel2 = ares<128,ares<128,ares_down<128,SUBNET>>>;
template <typename SUBNET> using alevel3 = ares<64,ares<64,ares<64,ares_down<64,SUBNET>>>>;
template <typename SUBNET> using alevel4 = ares<32,ares<32,ares<32,SUBNET>>>;
using anet_type = loss_metric<fc_no_bias<128,avg_pool_everything<
alevel0<
alevel1<
alevel2<
alevel3<
alevel4<
max_pool<3,3,2,2,relu<affine<con<32,7,7,2,2,
input_rgb_image_sized<150>
>>>>>>>>>>>>;
// ----------------------------------------------------------------------------------------
std::vector<matrix<rgb_pixel>> jitter_image( const matrix<rgb_pixel>& img );
/**
* TODO: Add class description
*
* @author Gagua
*/
class IM_DlibWorker : public basicThread{
private:
frontal_face_detector m_oFaceDetector;
shape_predictor m_oShapePredictor;
anet_type m_oNet;
IM_DataBaseAdapter * m_pDBA;
//matrix<rgb_pixel> m_oInputImg;
//std::vector<matrix<rgb_pixel>> m_vFacesImg;
basicLogCollection * m_pLog;
config_setting_t * m_pSettings;
basicEventHeap * m_pEvtHeap;
cv::Mat m_oWorkingMat;
float m_fDetectionProbability;
bool m_bUseShapePredictor;
bool m_bUseFaceRecognition;
char m_pPicturesBase[1024];
char m_pFacesBase[1024];
char m_pShapePredictorPath[1024];
char m_pNetModelPath[1024];
char m_sChownUser[64];
char m_sChownGroup[64];
basicMutex m_mBufferProtectorMutex;
IM_JOB * m_pActiveJob;
bool m_bDataIsActive;
CSTR m_fSaveFace( matrix<rgb_pixel> &Picture, CSTR md5, uint32_t index );
IM_RESULT * m_fImageAnalyzer( cv::Mat &Picture );
protected:
virtual void m_fThreadProc( void );//getLayerNames()
public:
// Constructor
explicit IM_DlibWorker( config_setting_t * Settings = NULL );
// Destructor
virtual ~IM_DlibWorker();
bool create( void );
bool enqueueJob( IM_JOB *ptr );
};
#endif