1. #define _WIN32_DCOM
  2. #include <SDKDDKVer.h>
  3. #include <direct.h>
  4. #include <thr/threads.h>
  5. #include <stdlib.h>
  6. #include <assert.h>
  7. #include <stdio.h>
  8. #include <tchar.h>
  9. #include <io.h>
  10. #include <time.h>
  11. #include <sys/types.h>
  12. #include <sys/stat.h>
  13. #include "..\..\lib\libcii\cii11\include\libcii.h"
  14. #include "algo.h"
  15.  
  16. extern TCHAR tcLogFile[];
  17. //
  18. #ifdef UNICODE
  19. #define __FILET__ __FILEW__
  20. #define __FUNCTIONT__ __FUNCTIONW__
  21. #else
  22. #define __FILET__ __FILE__
  23. #define __FUNCTIONT__ __FUNCTION__
  24. #endif
  25. #define TRACE_OUT(out ,fmt,...) do{TCHAR tcDate[24],tcTime[24];_tstrdate_s(tcDate),_tstrtime_s(tcTime);\
  26. _ftprintf_s(out, _T(" %s %s - FILE:%s - FUN:%s - LINE:%d \r\n MESSAGE: ") fmt _T("\r\n")\
  27. ,tcDate,tcTime,__FILET__,__FUNCTIONT__,__LINE__, ##__VA_ARGS__); } while ()
  28. //
  29. #define TRACE_LOG(fmt,...) do{ FILE* stream ; TRACE_OUT(stderr, fmt , ##__VA_ARGS__); \
  30. if( != _tfopen_s(&stream,tcLogFile,_T("a"))) break; \
  31. TRACE_OUT(stream, fmt , ##__VA_ARGS__); \
  32. fclose(stream); \
  33. } while()
  34.  
  35. #import <IsVision_9007\ISCFaceRecognize.dll> no_namespace
  36. #import <IsVision_9007\ISCFaceDetect.dll> no_namespace
  37. #import <IsVision_9007\ISCFaceRectify.dll> no_namespace
  38. #import <IsVision_9007\ISCFaceTools.dll> no_namespace
  39. #import <IsVision_9007\ISCFaceTracking.dll> no_namespace
  40. #import <IsVision_9007\ISCImageProc.dll> no_namespace
  41. #import <IsVision_9007\ISCImageQuality.dll> no_namespace
  42. #import <IsVision_9007\ISXImage.dll> no_namespace
  43. #import <IsVision_9007\ISCFaceMedia.dll> no_namespace
  44.  
  45. #ifdef __cplusplus
  46. typedef struct Algo_T * LpAlgo_T;
  47. typedef struct Args_T * LpArgs_T;
  48. typedef struct Pipe_T * LpPipe_T;
  49. typedef struct Item_T * LpItem_T;
  50. #define T LpAlgo_T
  51. #define R LpArgs_T
  52. #define P LpPipe_T
  53. #define I LpItem_T
  54. #else
  55. #define T Arena_T
  56. #define R Args_T
  57. #define P Pipe_T
  58. typedef struct Algo_T *Algo_T;
  59. typedef struct Args_T *Args_T;
  60. typedef struct Pipe_T *Pipe_T;
  61. #endif
  62.  
  63. #define _CT_FileName_ 0x01
  64. #define _CT_FileData_ 0x02
  65. #define _CT_ImageRgb_ 0x03
  66.  
  67. #define _IRecognize 0x0001
  68. #define _ITransImage 0x0002
  69. #define _IFaceDetect 0x0004
  70. #define _IFaceRectify 0x0008
  71. #define _IFaceTool 0x0010
  72. #define _IFaceTrack 0x0020
  73. #define _IImageProc 0x0040
  74. #define _IImageQuality 0x0080
  75. #define _IVisionImage 0x0100
  76. #define _IPosition 0x0200
  77. #define _IComImageAll 0x01FF
  78.  
  79. #ifndef _THR_THREADS_H
  80. #define mtx_init(mtx, typ) InitializeSRWLock(mtx)
  81. #define mtx_destroy(mtx) __noop
  82. #define mtx_lock(mtx) AcquireSRWLockExclusive (mtx)
  83. #define mtx_unlock(mtx) ReleaseSRWLockExclusive (mtx);
  84. #define cnd_init(cnd) InitializeConditionVariable(cnd);
  85. #define cnd_destroy(cnd) __noop
  86. #define cnd_signal(cnd) WakeConditionVariable(cnd)
  87. #define cnd_wait(cnd, mtx) SleepConditionVariableSRW(cnd, mtx, INFINITE, 0)
  88. #define mtx_t_ SRWLOCK
  89. #define cnd_t_ CONDITION_VARIABLE
  90. #else
  91. #define mtx_t_ mtx_t
  92. #define cnd_t_ cnd_t
  93. #endif
  94. #define NUMBER_ALGO 7
  95. #define NUMBER_ITEM 7
  96.  
  97. struct Global_T
  98. {
  99. long nNumberCpu;
  100. };
  101. static volatile struct Global_T _global;
  102. TCHAR tcLogFile[];
  103. struct Args_T
  104. {
  105. enumTemplateType eTemplateType;
  106. PTP_WORK pwkNewTemplate;
  107. _TCHAR tcIniFile[];
  108. _TCHAR tcSN[];
  109. _TCHAR tcLicense[];
  110. long lTemplateSize;
  111.  
  112. int iNetLogin;
  113. int used;
  114. int total;
  115. T* algo;
  116. SRWLOCK srw_;
  117. static mtx_t_ mtx_;
  118. static long once;
  119. static long count_ref;
  120. };
  121. mtx_t_ Args_T::mtx_;
  122. long Args_T::once = 0L;
  123. long Args_T::count_ref = 0L;
  124. //
  125. struct Algo_T
  126. {
  127. IRecognizePtr m_IRecognize;
  128. ITransImagePtr m_ITransImage;
  129. IDetectPtr m_pIDetect;
  130. IFaceRectifyPtr m_pFaceRectify;
  131. IFaceToolsPtr m_pIFaceTool;
  132. IFaceTrackingPtr m_pIFaceTrack;
  133. IImageProcPtr m_pIImageProc;
  134. IImageQualityPtr m_pIImageQuality;
  135. IVisionImagePtr m_pIVisionImage;
  136. IPositionPtr m_pIPosition;
  137. unsigned long nIptrFlag;
  138. R m_lpArgs;
  139. };
  140. typedef struct Data_T *LpData_T;
  141. typedef struct Pipe_T
  142. {
  143. LpData_T* ptr;
  144. size_t length;
  145. size_t used;
  146. size_t iget;
  147. size_t iput;
  148. mtx_t_ _mtx;
  149. cnd_t_ _cndr;
  150. cnd_t_ _cndw;
  151. }* LpPipe_T;
  152. enum eOptType{ eNewTemplate, eNewTemplate2, eCmprTemplate ,eNullOpt };
  153. struct Item_T
  154. {
  155. T cl;
  156. eOptType opt;
  157. HANDLE event;
  158. LpPipe_T pipe;
  159. LpPipe_T pipe2;
  160. long ref_count;
  161. long ref_signal;
  162. long num_thread;
  163. long seq;
  164. bool result;
  165. static long ref_selfbuf;
  166. static I selfbuf[NUMBER_ITEM];
  167. //
  168. union
  169. {
  170. struct
  171. {
  172. const char* srcpath;
  173. const char* wildcard;
  174. const char* dstfile;
  175. }ready;
  176. struct
  177. {
  178. unsigned char** img;
  179. long* length;
  180. long size;
  181. long size2;
  182. const char* imgtype;
  183. unsigned char** tmp;
  184. }ready2;
  185. };
  186. void* pvResult;
  187. LpList_T list;
  188. SRWLOCK mtx_;
  189. };
  190. long Item_T::ref_selfbuf;
  191. I Item_T::selfbuf[NUMBER_ITEM];
  192. struct Data_T
  193. {
  194. union
  195. {
  196. struct
  197. {
  198. char* file;
  199. }result;
  200. struct
  201. {
  202. unsigned char** img;
  203. long* length;
  204. long size;
  205. const char* imgtype;
  206. long pos;
  207. }result2;
  208. };
  209. void* pvResult;
  210. struct
  211. {
  212. double simi;
  213. long seq;
  214. long size;
  215. }vTemplate;
  216. eOptType opt;
  217. };
  218. static P Pipe_new(size_t length)
  219. {
  220. P pi = (P)malloc(sizeof *pi);
  221. assert(pi);
  222. mtx_init(&pi->_mtx, _Mtx_plain);
  223. cnd_init(&pi->_cndr);
  224. cnd_init(&pi->_cndw);
  225. pi->ptr = (LpData_T*)calloc(length, sizeof LpData_T );
  226. assert(pi->ptr);
  227. pi->length = length;
  228. pi->used = ;
  229. pi->iget = ;
  230. pi->iput = ;
  231. return pi;
  232. }
  233. static void Pipe_put(P pi, LpData_T ptr)
  234. {
  235. assert(pi);
  236. mtx_lock(&pi->_mtx);
  237. while (pi->used >= pi->length)
  238. {
  239. cnd_wait(&pi->_cndr, &pi->_mtx);
  240. }
  241. pi->ptr[pi->iput++] = ptr;
  242. ++pi->used;
  243. if (pi->iput >= pi->length)
  244. {
  245. pi->iput = ;
  246. }
  247. cnd_signal(&pi->_cndw);
  248. mtx_unlock(&pi->_mtx);
  249. }
  250. static void Pipe_get(P pi, LpData_T* ptr)
  251. {
  252. assert(pi);
  253. mtx_lock(&pi->_mtx);
  254. while (pi->used <= )
  255. {
  256. cnd_wait(&pi->_cndw, &pi->_mtx);
  257. }
  258. --pi->used;
  259. *ptr = pi->ptr[pi->iget++];
  260. if (pi->iget >= pi->length)
  261. {
  262. pi->iget = ;
  263. }
  264. cnd_signal(&pi->_cndr);
  265. mtx_unlock(&pi->_mtx);
  266. }
  267. static void Pipe_free(P* pi)
  268. {
  269. assert(pi && *pi);
  270. assert((*pi)->ptr);
  271. free((*pi)->ptr);
  272. mtx_destroy(&(*pi)->_mtx);
  273. cnd_destroy(&(*pi)->_cndr);
  274. cnd_destroy(&(*pi)->_cndw);
  275. free(*pi);
  276. (*pi) = nullptr;
  277. }
  278. static R Args_new()
  279. {
  280. static R ag = nullptr;
  281. if ( == InterlockedCompareExchange(&ag->once, 1L, 0L))
  282. {
  283. ag = (R)malloc( sizeof *ag );
  284. ag->count_ref = 0L;
  285. ag->pwkNewTemplate = nullptr;// CreateThreadpoolWork(__ThreadCreateTemplate, ag, NULL);
  286. InitializeSRWLock(&ag->srw_);
  287. mtx_init(&ag->mtx_, _Mtx_plain);
  288. {
  289. TCHAR tcFileName[], tcModuleFile[MAX_PATH];
  290. SYSTEM_INFO _syInfo;
  291. GetSystemInfo(&_syInfo);
  292. _global.nNumberCpu = _syInfo.dwNumberOfProcessors;
  293. GetModuleFileName(NULL, tcModuleFile, MAX_PATH);
  294. _tsplitpath_s(tcModuleFile, NULL, , NULL, , tcFileName, , NULL, );
  295. _tmakepath_s(ag->tcIniFile, , NULL, NULL, tcFileName, _T("ini"));
  296. _tmakepath_s(tcLogFile, , NULL, NULL, tcFileName, _T("log"));
  297. if (_taccess_s(ag->tcIniFile, 0x04) == )
  298. {
  299. GetPrivateProfileString(_T("Register"), _T("sn"), _T(""), ag->tcSN, _countof(ag->tcSN), ag->tcIniFile);
  300. GetPrivateProfileString(_T("Register"), _T("license"), _T(""), ag->tcLicense, _countof(ag->tcLicense), ag->tcIniFile);
  301. ag->iNetLogin = GetPrivateProfileInt(_T("Register"), _T("netlogin"), , ag->tcIniFile);
  302. ag->eTemplateType = (enumTemplateType)GetPrivateProfileInt(_T("Parameters"), _T("TemplateType"), , ag->tcIniFile);
  303. }
  304. else
  305. {
  306. ag->iNetLogin = ;
  307. ag->eTemplateType = (enumTemplateType);
  308. _tcscpy_s(ag->tcSN, _T(""));
  309. _tcscpy_s(ag->tcLicense, _T(""));
  310. }
  311. }
  312. ag->total = _global.nNumberCpu;
  313. ag->used = ;
  314. ag->algo = (T*)malloc(ag->total * sizeof T);
  315. _tprintf(_T("+++++++++++++++++++++++++++++++++++++++++++++++++++++++Args_new.\r\n"));
  316. }
  317. InterlockedIncrement(&ag->count_ref);
  318. return ag;
  319. }
  320. static T Algo_get(R ag)
  321. {
  322. T al;
  323. mtx_lock(&ag->mtx_);
  324. if (ag->used > )
  325. al = ag->algo[--ag->used];
  326. else
  327. al = nullptr;
  328. mtx_unlock(&ag->mtx_);
  329. return al;
  330. }
  331. static bool Algo_put(T al)
  332. {
  333. R ag = al->m_lpArgs;
  334. mtx_lock(&ag->mtx_);
  335. if (ag->used < ag->total && ag->count_ref > )
  336. ag->algo[ag->used++] = al;
  337. else
  338. al = nullptr;
  339. mtx_unlock(&ag->mtx_);
  340. return al != nullptr;
  341. }
  342. static I Item_get()
  343. {
  344. I im = nullptr;
  345. mtx_lock(&Args_T::mtx_);
  346. if (Item_T::ref_selfbuf > )
  347. {
  348. im = Item_T::selfbuf[--Item_T::ref_selfbuf];
  349. im->ref_count = ;
  350. im->seq = ;
  351. im->cl = nullptr;
  352. im->result = false;
  353. im->pipe->used = ;
  354. im->pipe->iget = ;
  355. im->pipe->iput = ;
  356. im->pipe2->used = ;
  357. im->pipe2->iget = ;
  358. im->pipe2->iput = ;
  359. }
  360. else
  361. im = nullptr;
  362. mtx_unlock(&Args_T::mtx_);
  363. return im;
  364. }
  365. static bool Item_put(I im)
  366. {
  367. mtx_lock(&Args_T::mtx_);
  368. if (Item_T::ref_selfbuf < NUMBER_ITEM && Args_T::count_ref > )
  369. Item_T::selfbuf[Item_T::ref_selfbuf++] = im;
  370. else
  371. im = nullptr;
  372. mtx_unlock(&Args_T::mtx_);
  373. return im != nullptr;
  374. }
  375. static void Item_free(I *im)
  376. {
  377. assert(im && *im);
  378. if (!Item_put(*im))
  379. {
  380. CloseHandle((*im)->event);
  381. Pipe_free(&(*im)->pipe);
  382. Pipe_free(&(*im)->pipe2);
  383. free(*im);
  384. (*im) = nullptr;
  385. }
  386. }
  387. static I Item_new()
  388. {
  389. I im = Item_get();
  390. if (nullptr == im)
  391. {
  392. im = (I)malloc(sizeof *im);
  393. im->ref_count = ;
  394. im->seq = ;
  395. im->cl = nullptr;
  396. im->result = false;
  397. InitializeSRWLock(&im->mtx_);
  398. im->pipe = Pipe_new();
  399. im->pipe2 = Pipe_new();
  400. im->event = CreateEvent(NULL, FALSE, FALSE, NULL);
  401. }
  402. return im;
  403. }
  404. static void Args_free(R* ag)
  405. {
  406. long ref;
  407. assert(ag && *ag);
  408. ref = InterlockedDecrement(&(*ag)->count_ref);
  409. if (ref == )
  410. {
  411. T al;// this code is not excute
  412. I im;
  413. assert(ref == );
  414. InterlockedExchange(&(*ag)->once, 0L);
  415. while (al = Algo_get(*ag))
  416. {
  417. Algo_free(&al);
  418. }
  419. while (im = Item_get())
  420. {
  421. Item_free(&im);
  422. }
  423. mtx_destroy(&(*ag)->mtx_);
  424. free((*ag)->algo);
  425. free(*ag);
  426. (*ag) = nullptr;
  427. _tprintf(_T("-------------------------------------------------------Args_free.\r\n"));
  428. }
  429. }
  430. T Algo_new()
  431. {
  432. R ag = Args_new();
  433. T al = Algo_get(ag);
  434. if (!al)
  435. {
  436. CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_SPEED_OVER_MEMORY);
  437. al = new Algo_T;
  438. al->nIptrFlag = 0UL;
  439. al->m_lpArgs = ag;
  440. }
  441. assert(al);
  442. return al;
  443. }
  444. static bool NewTemplateFile( const char* filename)
  445. {
  446. size_t len;
  447. if ( == _access(filename, 0x06))
  448. {
  449. return true;
  450. }
  451. if ( < (len = strlen(filename)))
  452. {
  453. char* tmpbuf, *p, c;
  454. tmpbuf = (char*)malloc(len + );
  455. strcpy_s(tmpbuf, len + , filename);
  456. for (p = tmpbuf; *p; ++p)
  457. {
  458. if ('\\' != *p && '/' != *p)
  459. {
  460. continue;
  461. }
  462. c = *++p;
  463. *p = '\0';
  464. if ((_access(tmpbuf, )) != )
  465. {
  466. if ( != _mkdir(tmpbuf))
  467. {
  468. break;
  469. }
  470. }
  471. *p = c;
  472. }
  473. {
  474. bool bret;
  475. FILE* file;
  476. bret = ( == _tfopen_s(&file, tmpbuf, _T("a")));
  477. free(tmpbuf);
  478. fclose(file);
  479. return bret;
  480. }
  481. }
  482. else
  483. return false;
  484. }
  485. static bool IsMatched(CONST TCHAR* p, CONST TCHAR* q)
  486. {
  487. CONST TCHAR *r, *z, *x = _T("");
  488. for (r = p; *p; ++p)
  489. if (*p == '\\')
  490. r = p + ;
  491. else if (*p == '.')
  492. x = p;
  493. z = r;
  494. while (*q)
  495. {
  496. while (*q == '|')q++;
  497. if (*q == '*')
  498. {
  499. r = x;
  500. while (*++q != '.' && *q);
  501. }
  502. while (tolower(*q) == tolower(*r) && *r) r++, q++;
  503. if (*q == '*' || !*r && (!*q || *q == '|'))
  504. {
  505. return true;
  506. }
  507. while (*q != '|' && *q)++q;
  508. r = z;
  509. }
  510. return false;
  511. }
  512. static void FetchFile(TCHAR* tcFile, size_t nChars, CONST TCHAR* tcWard, P pi)
  513. {
  514. _tfinddata_t _tfddt;
  515. intptr_t intptr = _tfindfirst(tcFile, &_tfddt);
  516. if (- == intptr)
  517. {
  518. return;
  519. }
  520. do
  521. {
  522. tcFile[nChars] = '\0';
  523. if (_tfddt.attrib & _A_SUBDIR )
  524. {
  525. if (_tfddt.name[] != '.')
  526. {
  527. _tcscat_s(tcFile, MAX_PATH, _tfddt.name);
  528. _tcscat_s(tcFile, MAX_PATH, _T("\\"));
  529. _tcscat_s(tcFile, MAX_PATH, _T("*.*"));
  530. FetchFile(tcFile, nChars + + _tcslen(_tfddt.name), tcWard, pi);
  531. }
  532. }
  533. else if (IsMatched(_tfddt.name, tcWard))
  534. {
  535. LpData_T ptr = (LpData_T)malloc(sizeof(*ptr));
  536. size_t length = nChars + _tcslen(_tfddt.name) + ;
  537. ptr->result.file = new char[length];// (_TCHAR*)malloc( length * sizeof _TCHAR);
  538. _tcscat_s(tcFile, MAX_PATH, _tfddt.name);
  539. _tcscpy_s(ptr->result.file, length, tcFile);
  540. ptr->opt = eNewTemplate;
  541. Pipe_put(pi, ptr);
  542. }
  543. } while ( == _tfindnext(intptr, &_tfddt));
  544. _findclose(intptr);
  545. }
  546. static void GetSubDir(CONST TCHAR* tcFile, CONST TCHAR *tcWard, P pi)
  547. {
  548. TCHAR tcFileName[MAX_PATH], *pEnd;
  549. //if (_taccess_s(ag->tcIniFile, 0x04) == 0)
  550. //
  551. struct stat s_buf;
  552. stat(tcFile, &s_buf);
  553.  
  554. /*判断输入的文件路径是否目录,若是目录,则往下执行,分析目录下的文件*/
  555. if ( s_buf.st_mode&_S_IFDIR)
  556. {
  557. _tcscpy_s(tcFileName, tcFile);
  558. (pEnd = _tcsrchr(tcFileName, '\\'))[] = '\0';
  559. _tcscat_s(tcFileName, _T("*.*"));
  560. FetchFile(tcFileName, pEnd - tcFileName + , tcWard, pi);
  561. }
  562. else if (s_buf.st_mode&_S_IFREG)
  563. {
  564. TCHAR tcFileExt[];
  565. _tsplitpath_s(tcFile, NULL, , NULL, , tcFileName, MAX_PATH, tcFileExt, );
  566. _tmakepath_s(tcFileName, MAX_PATH, NULL, NULL, tcFileName, tcFileExt);
  567. if (IsMatched(tcFileName, tcWard))
  568. {
  569. LpData_T ptr = (LpData_T)malloc(sizeof(*ptr));
  570. ptr->result.file = new char[MAX_PATH];
  571. _tcscpy_s(ptr->result.file, MAX_PATH, tcFile);
  572. ptr->opt = eNewTemplate;
  573. Pipe_put(pi, ptr);
  574. }
  575. }
  576. Pipe_put(pi, nullptr);
  577. }
  578. static void ComObjectInstance(T al, unsigned long nIptrFlag)
  579. {
  580. HRESULT hr;
  581. assert(al);
  582. if ((nIptrFlag & _IRecognize) && !(_IRecognize & al->nIptrFlag))
  583. {
  584. al->nIptrFlag &= ~_IRecognize;
  585. if (FAILED(hr = al->m_IRecognize.CreateInstance(__uuidof(Recognize))))
  586. {
  587. TRACE_LOG(_T("_IRecognize接口创建失败:%#08x"), hr);
  588. }
  589. else if (FAILED(hr = al->m_IRecognize->SetModelType((enumFrameModelType)al->m_lpArgs->eTemplateType)))
  590. {
  591. TRACE_LOG(_T("_IRecognize::SetModelType:ErrCode = %d"), al->m_IRecognize->GetLastError());
  592. }
  593. else
  594. {
  595. if (al->m_lpArgs->iNetLogin && al->m_IRecognize->Initialize(VARIANT_TRUE) == VARIANT_TRUE
  596. || !al->m_lpArgs->iNetLogin
  597. && ((( == _tcslen(al->m_lpArgs->tcSN) || == _tcslen(al->m_lpArgs->tcLicense))
  598. && al->m_IRecognize->Initialize(VARIANT_FALSE) == VARIANT_TRUE) || al->m_IRecognize->SetRegisteredInfo(_bstr_t(al->m_lpArgs->tcSN), _bstr_t(al->m_lpArgs->tcLicense)) == VARIANT_TRUE))
  599. {
  600. al->nIptrFlag |= _IRecognize;
  601. al->m_lpArgs->lTemplateSize = al->m_IRecognize->GetTemplateSize(al->m_lpArgs->eTemplateType);
  602. TRACE_LOG(_T("_IRecognize:GetVersion() = %s,_IRecognize::GetTemplateSize() = %d"), (const char*)al->m_IRecognize->GetVersion(), al->m_lpArgs->lTemplateSize);
  603. }
  604. else
  605. {
  606. TRACE_LOG(_T("_IRecognize接口初始化失败:ErrCode = %d"), al->m_IRecognize->GetLastError());
  607. }
  608. }
  609. }
  610. if ((nIptrFlag & _ITransImage) && !(_ITransImage & al->nIptrFlag))
  611. {
  612. if (FAILED(hr = al->m_ITransImage.CreateInstance(__uuidof(TransImage))))
  613. {
  614. TRACE_LOG(_T("_ITransImage接口创建失败:%#08x"), hr);
  615. al->nIptrFlag &= ~_ITransImage;
  616. }
  617. else
  618. {
  619. al->nIptrFlag |= _ITransImage;
  620. TRACE_LOG(_T("_ITransImage:CreateInstance Finished."));
  621. }
  622. }
  623. if ((nIptrFlag & _IFaceDetect) && !(_IFaceDetect & al->nIptrFlag))
  624. {
  625. al->nIptrFlag &= ~_IFaceDetect;
  626. if (FAILED(hr = al->m_pIDetect.CreateInstance(__uuidof(Detect))))
  627. {
  628. TRACE_LOG(_T("_IFaceDetect接口创建失败:%#08x"), hr);
  629. }
  630. else
  631. {
  632. if (al->m_lpArgs->iNetLogin && al->m_pIDetect->Initialize(VARIANT_TRUE) == VARIANT_TRUE
  633. || !al->m_lpArgs->iNetLogin
  634. && ((( == _tcslen(al->m_lpArgs->tcSN) || == _tcslen(al->m_lpArgs->tcLicense))
  635. && al->m_pIDetect->Initialize(VARIANT_FALSE) == VARIANT_TRUE) || al->m_pIDetect->SetRegisteredInfo(_bstr_t(al->m_lpArgs->tcSN), _bstr_t(al->m_lpArgs->tcLicense)) == VARIANT_TRUE))
  636. {
  637. al->nIptrFlag |= _IFaceDetect;
  638. TRACE_LOG(_T("_IFaceDetect:GetVersion() = %s"), (const char*)al->m_pIDetect->GetVersion());
  639. }
  640. else
  641. {
  642. TRACE_LOG(_T("_IFaceDetect接口初始化失败:ErrCode = %d"), al->m_pIDetect->GetLastError());
  643. }
  644. }
  645. }
  646. if ((nIptrFlag & _IFaceRectify) && !(_IFaceRectify & al->nIptrFlag))
  647. {
  648. if (FAILED(hr = al->m_pFaceRectify.CreateInstance(__uuidof(FaceRectify))))
  649. {
  650. TRACE_LOG(_T("_IFaceRectify接口创建失败:%#08x"), hr);
  651. al->nIptrFlag &= ~_IFaceRectify;
  652. }
  653. else
  654. {
  655. al->nIptrFlag |= _IFaceRectify;
  656. TRACE_LOG(_T("_IFaceRectify:CreateInstance Finished."));
  657. }
  658. }
  659. if ((nIptrFlag & _IFaceTool) && !(_IFaceTool & al->nIptrFlag))
  660. {
  661. if (FAILED(hr = al->m_pIFaceTool.CreateInstance(__uuidof(FaceTools))))
  662. {
  663. TRACE_LOG(_T("_IFaceTool接口创建失败:%#08x"), hr);
  664. al->nIptrFlag &= ~_IFaceTool;
  665. }
  666. else
  667. {
  668. al->nIptrFlag |= _IFaceTool;
  669. TRACE_LOG(_T("_IFaceTool:CreateInstance Finished."));
  670. }
  671. }
  672. if ((nIptrFlag & _IFaceTrack) && !(_IFaceTrack & al->nIptrFlag))
  673. {
  674. if (FAILED(hr = al->m_pIFaceTrack.CreateInstance(__uuidof(FaceTracking))))
  675. {
  676. TRACE_LOG(_T("_IFaceTrack接口创建失败:%#08x"), hr);
  677. al->nIptrFlag &= ~_IFaceTrack;
  678. }
  679. else
  680. {
  681. al->nIptrFlag |= _IFaceTrack;
  682. TRACE_LOG(_T("_IFaceTrack:CreateInstance Finished."));
  683. }
  684. }
  685. if ((nIptrFlag & _IImageProc) && !(_IImageProc & al->nIptrFlag))
  686. {
  687. if (FAILED(hr = al->m_pIImageProc.CreateInstance(__uuidof(ImageProc))))
  688. {
  689. TRACE_LOG(_T("_IImageProc接口创建失败:%#08x"), hr);
  690. al->nIptrFlag &= ~_IImageProc;
  691. }
  692. else
  693. {
  694. al->nIptrFlag |= _IImageProc;
  695. TRACE_LOG(_T("_IImageProc:CreateInstance Finished."));
  696. }
  697. }
  698. if ((nIptrFlag & _IImageQuality) && !(_IImageQuality & al->nIptrFlag))
  699. {
  700. if (FAILED(hr = al->m_pIImageQuality.CreateInstance(__uuidof(ImageQuality))))
  701. {
  702. TRACE_LOG(_T("_IImageQuality接口创建失败:%#08x"), hr);
  703. al->nIptrFlag &= ~_IImageQuality;
  704. }
  705. else
  706. {
  707. al->nIptrFlag |= _IImageQuality;
  708. TRACE_LOG(_T("_IImageQuality:CreateInstance Finished."));
  709. }
  710. }
  711. if ((nIptrFlag & _IVisionImage) && !(_IVisionImage & al->nIptrFlag))
  712. {
  713. if (FAILED(hr = al->m_pIVisionImage.CreateInstance(__uuidof(VisionImage))))
  714. {
  715. TRACE_LOG(_T("_IFaceTrack接口创建失败:%#08x"), hr);
  716. al->nIptrFlag &= ~_IVisionImage;
  717. }
  718. else
  719. {
  720. al->nIptrFlag |= _IVisionImage;
  721. TRACE_LOG(_T("_IFaceTrack:CreateInstance Finished."));
  722. }
  723. }
  724. if ((nIptrFlag & _IPosition) && !(_IPosition & al->nIptrFlag))
  725. {
  726. if (FAILED(hr = al->m_pIPosition.CreateInstance(__uuidof(Position))))
  727. {
  728. TRACE_LOG(_T("_IPosition接口创建失败:%#08x"), hr);
  729. al->nIptrFlag &= ~_IPosition;
  730. }
  731. else
  732. {
  733. al->nIptrFlag |= _IPosition;
  734. }
  735. }
  736. }
  737. static void ComObjectRelease(T al, unsigned long nIptrFlag)
  738. {
  739. if ((nIptrFlag & _IRecognize) && (_IRecognize & al->nIptrFlag))
  740. {
  741. al->m_IRecognize->Uninitialize();
  742. al->m_IRecognize.Release();
  743. al->nIptrFlag &= ~_IRecognize;
  744. }
  745. if ((nIptrFlag & _ITransImage) && (_ITransImage & al->nIptrFlag))
  746. {
  747. al->m_ITransImage.Release();
  748. al->nIptrFlag &= ~_ITransImage;
  749. }
  750. if ((nIptrFlag & _IFaceDetect) && (_ITransImage & al->nIptrFlag))
  751. {
  752. al->m_pIDetect->Uninitialize();
  753. al->m_pIDetect.Release();
  754. al->nIptrFlag &= ~_IFaceDetect;
  755. }
  756. if ((nIptrFlag & _IFaceRectify) && (_ITransImage & al->nIptrFlag))
  757. {
  758. al->m_pFaceRectify.Release();
  759. al->nIptrFlag &= ~_IFaceRectify;
  760. }
  761. if ((nIptrFlag & _IFaceTool) && (_ITransImage & al->nIptrFlag))
  762. {
  763. al->m_pIFaceTool->Uninitialize();
  764. al->m_pIFaceTool.Release();
  765. al->nIptrFlag &= ~_IFaceTool;
  766. }
  767. if ((nIptrFlag & _IFaceTrack) && (_ITransImage & al->nIptrFlag))
  768. {
  769. al->m_pIFaceTrack.Release();
  770. al->nIptrFlag &= ~_IFaceTrack;
  771. }
  772. if ((nIptrFlag & _IImageProc) && (_ITransImage & al->nIptrFlag))
  773. {
  774. al->m_pIImageProc.Release();
  775. al->nIptrFlag &= ~_IImageProc;
  776. }
  777. if ((nIptrFlag & _IImageQuality) && (_ITransImage & al->nIptrFlag))
  778. {
  779. al->m_pIImageQuality->Uninitialize();
  780. al->m_pIImageQuality.Release();
  781. al->nIptrFlag &= ~_IImageQuality;
  782. }
  783. if ((nIptrFlag & _IVisionImage) && (_ITransImage & al->nIptrFlag))
  784. {
  785. al->m_pIVisionImage.Release();
  786. al->nIptrFlag &= ~_IVisionImage;
  787. }
  788. if ((nIptrFlag & _IPosition) && (_IPosition & al->nIptrFlag))
  789. {
  790. al->m_pIPosition.Release();
  791. al->nIptrFlag &= ~_IPosition;
  792. }
  793. }
  794. static long Algo_create_template(T al, char* lpData, unsigned char** ppTemplate, int *iTemplateSize, int DataType, long Datalength)
  795. {
  796. unsigned char* pTemplate;
  797. assert(al && lpData && ppTemplate);
  798. if (!(al->nIptrFlag & _ITransImage))
  799. {
  800. ComObjectInstance(al, _ITransImage);
  801. }
  802. if (!(al->nIptrFlag & _ITransImage))
  803. {
  804. return (-);
  805. }
  806. if (!(al->nIptrFlag & _IFaceDetect))
  807. {
  808. ComObjectInstance(al, _IFaceDetect);
  809. }
  810. if (!(al->nIptrFlag & _IFaceDetect))
  811. {
  812. return (-);
  813. }
  814. if (!(al->nIptrFlag & _IPosition))
  815. {
  816. ComObjectInstance(al, _IPosition);
  817. }
  818. if (!(al->nIptrFlag & _IPosition))
  819. {
  820. return (-);
  821. }
  822. switch (DataType)
  823. {
  824. case _CT_FileName_:
  825. if (VARIANT_TRUE != al->m_ITransImage->ReadImageFile(_bstr_t(lpData), enumFileType::TRANS_FILE_TYPE_UNKNOWN))
  826. {
  827. TRACE_LOG(_T("加载图像文件失败, ErrCode = %d"), GetLastError());
  828. return (-);
  829. }
  830. break;
  831. case _CT_FileData_:
  832. if (VARIANT_TRUE != al->m_ITransImage->ReadImageData((unsigned char*)lpData, Datalength, enumFileType::TRANS_FILE_TYPE_UNKNOWN))
  833. {
  834. TRACE_LOG(_T("加载图像文件失败, ErrCode = %d"), GetLastError());
  835. return (-);
  836. }
  837. break;
  838. case _CT_ImageRgb_:
  839. default:
  840. TRACE_LOG(_T("建模数据源类型不明确!"));
  841. return (-);
  842. }
  843. al->m_pIPosition->Clear();
  844. if (VARIANT_TRUE != al->m_pIDetect->FindFace(al->m_ITransImage, al->m_pIPosition))
  845. {
  846. TRACE_LOG(_T("检测人脸失败, ErrCode = %d"), al->m_pIDetect->GetLastError());
  847. return (-);
  848. }
  849. *iTemplateSize = Algo_template_size(al);
  850. if (*iTemplateSize < )
  851. {
  852. return (-);
  853. }
  854. pTemplate = new unsigned char[*iTemplateSize * al->m_pIPosition->GetlFaceNum()];
  855. if (VARIANT_TRUE != al->m_IRecognize->CreateTemplate(al->m_ITransImage, al->m_pIPosition
  856. , enumTemplateType::TEMPLATE_TYPE_GENERAL, al->m_pIPosition->GetlFaceNum(), pTemplate))
  857. {
  858. TRACE_LOG(_T("创建模版失败, ErrCode = %d"), al->m_IRecognize->GetLastError());
  859. delete[] pTemplate;
  860. return (-);
  861. }
  862. *ppTemplate = pTemplate;
  863. return al->m_pIPosition->GetlFaceNum();
  864. }
  865. static long Algo_create_template(T al, const char* lpFile, unsigned char** ppTemplate, int *iTemplateSize)
  866. {
  867. return Algo_create_template(al, const_cast<char*>(lpFile), ppTemplate, iTemplateSize, _CT_FileName_, );
  868. }
  869. //#define _tprintf
  870. static void __stdcall __TrySubmitCompareTemplate(
  871. PTP_CALLBACK_INSTANCE instance,
  872. PVOID pvctx)
  873. {
  874. I im = (I)pvctx;
  875. T al = Algo_new();
  876. R ag = al->m_lpArgs;
  877. P in = im->pipe;
  878. P out = im->pipe2;
  879. LpData_T ptr = nullptr;
  880. LpData_T ptr2 = nullptr;
  881. eOptType eOpt = im->opt;
  882. PSRWLOCK mtx_ = &im->cl->m_lpArgs->srw_;
  883. unsigned char *pTemplate = nullptr;
  884. unsigned char **tmpbuf, **vtmp, *tmp, **vtmp2;
  885. double *simibuf;
  886. long i, j, k, size, size2, pos, *length;
  887. bool result = im->result;
  888. long seq = InterlockedIncrement(&im->seq);
  889. CallbackMayRunLong(instance);
  890. for (;;)
  891. {
  892. Pipe_get(in, &ptr);
  893. if (ptr == nullptr)
  894. {
  895. Pipe_put(in, nullptr); //_tprintf(_T("ptr %d == nullptr\r\n"),i);
  896. if (result)
  897. {
  898. Pipe_put(out, nullptr);
  899. }
  900. break;
  901. }
  902. vtmp = ptr->result2.img;
  903. vtmp2 = im->ready2.tmp;
  904. size = ptr->result2.size;
  905. size2 = im->ready2.size2;
  906. pos = ptr->result2.pos;
  907. simibuf = &((double*)im->pvResult)[pos];
  908. for (i = , k = ; i < size; ++i)
  909. {
  910. tmpbuf = &vtmp[pos + i];
  911. pTemplate = tmpbuf[];
  912. for (j = ; j < size2; ++j, ++k)
  913. {
  914. tmp = vtmp2[j];
  915. simibuf[k] = k;
  916. #ifndef _DEBUG
  917. al->m_IRecognize->CompareTemplate(pTemplate, tmp, );
  918. #endif
  919. // printf("simibuf[%d]= %f\r\n",k+pos, simibuf[k]);
  920. }
  921. }
  922. if (result)
  923. {
  924.  
  925. }
  926. else
  927. {
  928.  
  929. free(ptr);
  930. }
  931. }
  932. Algo_free(&al);
  933. assert(im->ref_signal >= );
  934. if (InterlockedDecrement(&im->ref_signal) == )
  935. {
  936. SetEventWhenCallbackReturns(instance, im->event);
  937. //_tprintf(_T("%s: SetEventWhenCallbackReturns\r\n"), __FUNCTION__);
  938. }
  939. //_tprintf(_T("%s[%d] - Type[%d] :Exit\r\n"), __FUNCTION__,seq, im->opt);
  940. }
  941. static void __stdcall __TrySubmitCreateTemplate(
  942. PTP_CALLBACK_INSTANCE instance,
  943. PVOID pvctx)
  944. {
  945. I im = (I)pvctx;
  946. T al = Algo_new();
  947. R ag = al->m_lpArgs;
  948. P in = im->pipe, out = im->pipe2;
  949. LpData_T ptr = nullptr;
  950. LpData_T ptr2 = nullptr;
  951. eOptType eOpt = im->opt;
  952. PSRWLOCK mtx_ = &ag->srw_;
  953. unsigned char *pTemplate = nullptr;
  954. int iTemplateSize = ;
  955. bool result = im->result;
  956. long seq = InterlockedIncrement(&im->seq);
  957. CallbackMayRunLong(instance);
  958. for (;;)
  959. {
  960. Pipe_get(in, &ptr);
  961. if (ptr == nullptr)
  962. {
  963. Pipe_put(in, nullptr); //_tprintf(_T("ptr %d == nullptr\r\n"),i);
  964. if (result)
  965. {
  966. Pipe_put(out, nullptr);
  967. }
  968. break;
  969. }
  970. switch (eOpt)
  971. {
  972. case eNewTemplate:
  973. {
  974. LpList_T *list = &im->list;
  975. char* file = ptr->result.file;
  976. #ifndef _DEBUG
  977. Algo_create_template(al,file , &pTemplate, &iTemplateSize);
  978. #else
  979. _tprintf(_T(" %s iTemplateSize %d\r\n"), file,iTemplateSize);
  980. pTemplate = (unsigned char *)ptr->result.file;
  981. #endif
  982. if (result)
  983. {
  984. ptr->pvResult = pTemplate;
  985. Pipe_put(out, ptr);
  986. }
  987. else
  988. {
  989. AcquireSRWLockExclusive(mtx_);
  990. *list = List_push(*list, pTemplate);
  991. *list = List_push(*list, file);
  992. ReleaseSRWLockExclusive(mtx_);
  993. free(ptr);
  994. }
  995. }
  996. break;
  997. case eNewTemplate2:
  998. {
  999. unsigned char **r_pvbuf, **pvTemplate, **img = ptr->result2.img;
  1000. const char* imgtype = ptr->result2.imgtype;
  1001. long* length = ptr->result2.length, size = ptr->result2.size;
  1002. long pos = ptr->result2.pos, i = ;
  1003. pvTemplate = &((unsigned char **)im->pvResult)[pos];
  1004. for (; i < size; ++i)
  1005. {
  1006. r_pvbuf = &img[i];
  1007. #ifndef _DEBUG
  1008. Algo_create_template(al, (char *)r_pvbuf[],&pTemplate, &iTemplateSize, _CT_FileData_, length[i]);
  1009. #else
  1010. pTemplate = r_pvbuf[];
  1011. #endif
  1012. pvTemplate[i] = pTemplate;
  1013. }
  1014. if (result)
  1015. {
  1016. ptr->vTemplate.seq = pos;
  1017. ptr->vTemplate.size = size;
  1018. ptr->pvResult = pvTemplate;
  1019. Pipe_put(out, ptr);
  1020. }
  1021. else
  1022. {
  1023. free(ptr);
  1024. }
  1025. }
  1026. default:
  1027. break;
  1028. }//switch
  1029. }// for
  1030. assert(im->ref_signal >= );
  1031. Algo_free(&al);
  1032. if (InterlockedDecrement(&im->ref_signal) == )
  1033. {
  1034. SetEventWhenCallbackReturns(instance, im->event);
  1035. // _tprintf(_T("______________________ SetEventWhenCallbackReturns[%d]:Exit\r\n"),seq);
  1036. }
  1037. // _tprintf(_T("__ThreadCreateTemplate[%d]:Exit\r\n"), seq);
  1038. }
  1039. static void __stdcall __TrySubmitResultThread(
  1040. PTP_CALLBACK_INSTANCE instance,
  1041. PVOID pvctx)
  1042. {
  1043. I im = (I)pvctx;
  1044. P pi = im->pipe2;
  1045. T al = im->cl;
  1046. eOptType eOpt = im->opt;
  1047. LpData_T ptr = nullptr;
  1048. PSRWLOCK mtx_ = &al->m_lpArgs->srw_;
  1049. unsigned char *pTemplate = nullptr;
  1050. long seq = InterlockedIncrement(&im->seq);
  1051. CallbackMayRunLong(instance);
  1052. switch (seq)
  1053. {
  1054. case :
  1055. for (;;)
  1056. {
  1057. Pipe_get(pi, &ptr);
  1058. if (ptr == nullptr)
  1059. {
  1060. Pipe_put(pi, nullptr);
  1061. break;
  1062. }
  1063. switch (eOpt)
  1064. {
  1065. case eNewTemplate:
  1066. {
  1067. LpList_T *list = &im->list;
  1068. AcquireSRWLockExclusive(mtx_);
  1069. *list = List_push(*list, ptr->pvResult);
  1070. *list = List_push(*list, ptr->result.file);
  1071. ReleaseSRWLockExclusive(mtx_);
  1072. }break;
  1073. case eNewTemplate2:
  1074. {
  1075. unsigned char **pvTemplate = (unsigned char **)im->pvResult;
  1076. //
  1077. }break;
  1078. case eCmprTemplate:
  1079. {
  1080. double *vsimi = (double *)im->pvResult;
  1081. vsimi[ptr->vTemplate.seq] = ptr->vTemplate.simi;
  1082. }
  1083. default:
  1084. break;
  1085. } // switch
  1086. free(ptr);
  1087. } // for
  1088. default:
  1089. break;
  1090. } // switch
  1091. assert(im->ref_signal >= );
  1092. if (InterlockedDecrement(&im->ref_signal) == )
  1093. {
  1094. SetEventWhenCallbackReturns(instance, im->event);
  1095. // _tprintf(_T("+++++++++++++SetEventWhenCallbackReturns[%d]:Exit\r\n"), seq);
  1096. }
  1097. //_tprintf(_T("__TrySubmitThread[%d] - Type[%d] :Exit\r\n"), seq, im->opt);
  1098. }
  1099. static void ReaySubmitThread(I im, PTP_SIMPLE_CALLBACK __pfTrySubmit)
  1100. {
  1101. T al = (T)im->cl;
  1102. P out = im->pipe;
  1103. eOptType eOpt = im->opt;
  1104. long i, block, size, *length = nullptr;
  1105. long nThrd = ;
  1106. im->num_thread = ;
  1107. im->ref_signal = im->num_thread;
  1108. if (im->result)
  1109. {
  1110. ++nThrd;
  1111. TrySubmitThreadpoolCallback(__TrySubmitResultThread, im, NULL);
  1112. // _tprintf(_T("__TrySubmitResultThread :Start\r\n"));
  1113. }
  1114. for (; nThrd < im->ref_signal; ++nThrd)
  1115. {
  1116. TrySubmitThreadpoolCallback(__pfTrySubmit, im, NULL);
  1117. // _tprintf(_T("__TrySubmitCreateTemplate :Start\r\n"));
  1118. }
  1119. switch (eOpt)
  1120. {
  1121. case eNewTemplate:
  1122. GetSubDir(im->ready.srcpath, im->ready.wildcard, out);
  1123. break;
  1124. case eNewTemplate2:
  1125. length = im->ready2.length;
  1126. case eCmprTemplate:
  1127. {
  1128. unsigned char** img = im->ready2.img;
  1129. const char* imgtype = im->ready2.imgtype;
  1130. size = im->ready2.size;
  1131. block = size / max(, nThrd);
  1132. i = ;
  1133. if (block >= nThrd)
  1134. {
  1135. for (; i < nThrd; ++i)
  1136. {
  1137. LpData_T ptr = (LpData_T)malloc(sizeof(*ptr));
  1138. ptr->opt = eOpt;
  1139. ptr->result2.imgtype = imgtype;
  1140. ptr->result2.size = block;
  1141. ptr->result2.length = eCmprTemplate != eOpt ? &length[i] : nullptr;
  1142. ptr->result2.pos = block * i;
  1143. ptr->result2.img = &img[block * i];
  1144. Pipe_put(out, ptr);
  1145. }
  1146. size = im->ready2.size % max(, nThrd);
  1147. i = block * i;
  1148. size += i;
  1149. img = &img[i];
  1150. }
  1151. for (; i < size; ++i)
  1152. {
  1153. LpData_T ptr = (LpData_T)malloc(sizeof(*ptr));
  1154. ptr->opt = eOpt;
  1155. ptr->result2.imgtype = imgtype;
  1156. ptr->result2.size = ;
  1157. ptr->result2.pos = i;
  1158. ptr->result2.length = length ? &length[i] : nullptr;
  1159. ptr->result2.img = &img[i];
  1160. Pipe_put(out, ptr);
  1161. }
  1162. Pipe_put(out, nullptr);
  1163. }
  1164. default:
  1165. break;
  1166. }
  1167. WaitForSingleObject(im->event, INFINITE);
  1168. // _tprintf(_T("ReaySubmitThread :End\r\n"));
  1169. //_tprintf(_T("CloseHandle()[%d]\r\n"), InterlockedDecrement(&watch_1));
  1170. //IdleCpu_put(nThreadNum);
  1171. }
  1172. void Algo_free(T *al)
  1173. {
  1174. R ag = (*al)->m_lpArgs;
  1175. if (!Algo_put(*al))
  1176. {
  1177. ComObjectRelease(*al, _IComImageAll);
  1178. delete (*al);
  1179. (*al) = nullptr;
  1180. CoUninitialize();
  1181. }
  1182. Args_free(&ag);
  1183. }
  1184. long Algo_template_size(T al)
  1185. {
  1186. assert(al);
  1187. if (!(al->nIptrFlag & _IRecognize))
  1188. {
  1189. ComObjectInstance(al, _IRecognize);
  1190. }
  1191. if (!(al->nIptrFlag & _IRecognize))
  1192. {
  1193. return (-);
  1194. }
  1195. return al->m_lpArgs->lTemplateSize;
  1196. }
  1197. long Algo_template_type(T al, long type)
  1198. {
  1199. R ag;
  1200. HRESULT hr;
  1201. enumTemplateType etype;
  1202. assert(al);
  1203. if (!(al->nIptrFlag & _IRecognize))
  1204. {
  1205. ComObjectInstance(al, _IRecognize);
  1206. }
  1207. if (!(al->nIptrFlag & _IRecognize))
  1208. {
  1209. return (-);
  1210. }
  1211. ag = al->m_lpArgs;
  1212. assert(ag);
  1213. switch (type) {
  1214. case : etype = TEMPLATE_TYPE_SIMPLE; break;
  1215. case : etype = TEMPLATE_TYPE_GENERAL; break;
  1216. case : etype = TEMPLATE_TYPE_COMPLEX; break;
  1217. default:
  1218. return (-);
  1219. }
  1220. if (FAILED(hr = al->m_IRecognize->SetModelType((enumFrameModelType)etype)))
  1221. {
  1222. TRACE_LOG(_T("_IRecognize::SetModelType:ErrCode = %d"), al->m_IRecognize->GetLastError());
  1223. }
  1224. else
  1225. {
  1226. enumTemplateType retv = ag->eTemplateType;
  1227. ag->eTemplateType = etype;
  1228. switch (retv) {
  1229. case TEMPLATE_TYPE_SIMPLE : return ;
  1230. case TEMPLATE_TYPE_GENERAL : return ;
  1231. case TEMPLATE_TYPE_COMPLEX : return ;
  1232. default:
  1233. return (-);
  1234. }
  1235. }
  1236. }
  1237. unsigned char** Algo_create_template(T al, const char* path,long* size, const char* file, const char *ward )
  1238. {
  1239. I im = Item_new();
  1240. unsigned char** pvTemplate;
  1241. assert(al);
  1242. im->ready.srcpath = path;// lpPath;
  1243. im->ready.wildcard = ward;
  1244. im->ready.dstfile = file;
  1245. im->opt = eNewTemplate;
  1246. im->cl = al;
  1247. im->list = nullptr;
  1248. im->result = file && file[] != '\0';
  1249. ReaySubmitThread(im, __TrySubmitCreateTemplate);
  1250. AcquireSRWLockExclusive(&al->m_lpArgs->srw_);
  1251. *size = List_length(im->list) / ;
  1252. pvTemplate = (unsigned char**)List_toArray(im->list, nullptr);
  1253. List_free(&im->list);
  1254. ReleaseSRWLockExclusive(&al->m_lpArgs->srw_);
  1255. Item_free(&im);
  1256. return pvTemplate;
  1257. }
  1258. unsigned char** Algo_create_template(T al, unsigned char* img[], long length[], long size, const char* file, const char* imgtype)
  1259. {
  1260. I im = Item_new();
  1261. unsigned char** pvTemplate;
  1262. assert(al);
  1263. pvTemplate = new unsigned char* [size];
  1264. memset(pvTemplate, , size * sizeof *pvTemplate);
  1265. im->ready2.img = img;// lpPath;
  1266. im->ready2.length = length;
  1267. im->ready2.size = size;
  1268. im->ready2.imgtype = imgtype;
  1269. im->pvResult = pvTemplate;
  1270. im->opt = eNewTemplate2;
  1271. im->cl = al;
  1272. im->result = file && file[] != '\0' ;
  1273. ReaySubmitThread(im, __TrySubmitCreateTemplate);
  1274. Item_free(&im);
  1275. // _tprintf(_T("free(lpItem)[]\r\n"));
  1276. return pvTemplate;
  1277. }
  1278. double* Algo_compare_template(T al, unsigned char* vtmp[], long size, unsigned char* vtmp2[], long size2)
  1279. {
  1280. I im = Item_new();
  1281. double * vsimi = nullptr;
  1282. assert(al && vtmp2 && vtmp);
  1283. vsimi = new double[size * size2];
  1284. memset(vsimi, , size * size2 * sizeof *vsimi);
  1285. im->ready2.img = vtmp;// lpPath;
  1286. im->ready2.length = nullptr;
  1287. im->ready2.size = size;
  1288. im->ready2.size2 = size2;
  1289. im->ready2.imgtype = "";
  1290. im->ready2.tmp = vtmp2;
  1291. im->pvResult = vsimi;
  1292. im->opt = eCmprTemplate;
  1293. im->cl = al;
  1294. ReaySubmitThread(im, __TrySubmitCompareTemplate);
  1295. Item_free(&im);
  1296. //_tprintf(_T("free(lpItem)[]\r\n"));
  1297. return vsimi;
  1298. }

windows线程池的更多相关文章

  1. 第11章 Windows线程池(2)_Win2008及以上的新线程池

    11.2 Win2008以上的新线程池 (1)传统线程池的优缺点: ①传统Windows线程池调用简单,使用方便(有时只需调用一个API即可) ②这种简单也带来负面问题,如接口过于简单,无法更多去控制 ...

  2. 第11章 Windows线程池(1)_传统的Windows线程池

    第11章 Windows线程池 11.1 传统的Windows线程池及API (1)线程池中的几种底层线程 ①可变数量的长任务线程:WT_EXECUTELONGFUNCTION ②Timer线程:调用 ...

  3. windows线程池四种情形(win核心读书笔记)

    windows线程池四种情形(win核心读书笔记) Mircosoft从Windows2000引入线程池API,并在Vista后对线程池重新构架,引入新的线程池API.以下所有线程池函数均适用于Vis ...

  4. Windows核心编程:第11章 Windows线程池

    Github https://github.com/gongluck/Windows-Core-Program.git //第11章 Windows线程池.cpp: 定义应用程序的入口点. // #i ...

  5. 《Windows核心编程系列》十一谈谈Windows线程池

    Windows线程池 上一篇博文我们介绍了IO完成端口.得知IO完成端口可以非常智能的分派线程.但是IO完成端口仅对等待它的线程进行分派,创建和销毁线程的工作仍然需要我们自己来做. 我们自己也可以创建 ...

  6. 利用 Windows 线程池定制的 4 种方式完成任务(Windows 核心编程)

    Windows 线程池 说起底层的线程操作一般都不会陌生,Windows 提供了 CreateThread 函数来创建线程,为了同步线程的操作,Windows 提供了事件内核对象.互斥量内核对象.关键 ...

  7. 第11章 Windows线程池(3)_私有的线程池

    11.3 私有的线程池 11.3.1 创建和销毁私有的线程池 (1)进程默认线程池 当调用CreateThreadpoolwork.CreateThreadpoolTimer.CreateThread ...

  8. 【转】一个windows线程池实现

    #ifndef _ThreadPool_H_ #define _ThreadPool_H_ #pragma warning(disable: 4530) #pragma warning(disable ...

  9. windows线程池之I/O完成端口(IOCP)

    对于这个学习主要参考博客 http://blog.csdn.net/neicole/article/details/7549497

随机推荐

  1. ignore_user_abort(true); set_time_limit(0);程序在本地测试可以一直运行,上传服务器只能运行10-15分钟

    当PHP运行在安全模式下时此函数无效.除了关闭安全模式或者在php.ini程序中修改最大运行时间没有其他办法让此函数运行. php.ini 中缺省的最长执行时间是 30 秒,这是由 php.ini 中 ...

  2. 下载工具axel 和 mwget

    axel, yum安装或者apt-get安装 但有时axel不行,需要上wget,但单线程的太慢,需要安装mwget.apt-get -y install intltoolwget http://ja ...

  3. idea快捷键使用

    idea                                 eclipse project                           workspace module     ...

  4. #WEB安全基础 : HTTP协议 | 0x2 HTTP有关协议通信

    IP,TCP,DNS协议与HTP协议密不可分 IP(网际协议)位于网络层,几乎所有使用网络的系统都会用到IP协议 IP协议的作用:把数据包发送给对方,要保证确实传送到对方那里,则需要满足各类条件.两个 ...

  5. ListView的BeginUpdate()和EndUpdate()的用处

    许多Windows 窗体控件(例如,ListView 和 TreeView 控件)实现了 BeginUpdate 和EndUpdate 方法,至于为何要这样用简单说明一下. 当我们向一个Listvie ...

  6. WxWidgets笔记

    关于环境变量的配置:解压wxwidgets的压缩包之后要新建名为 WXWIN 的环境变量,变量的值为 解压得到的目录,不知为何要使用此环境变量 编译时使用的命令:mingw32-make -j1 -f ...

  7. jqueryd的post传递表单以及取消表单的默认传递

    //取消表单的默认传递: <form method="post" onsubmit="return false;"> 在FORM属性里添加 onsu ...

  8. liunx 常用命令学习笔记

    通过linux 命令pwd:显示当前所在的目录ls:显示当前目录下的文件cd:切换路径 cd..返回上一级路径mkdir:新建目录rmdir:删除目录 touch:新建文件rm:删除文件 gedit: ...

  9. kafka消费者实时消费数据存入hdfs java scalca 代码

    hadoop-client依赖很乱 调试很多次cdh版本好多jar没有 用hadoop2.7.3可以 自定义输出流的池子进行流管理 public void writeLog2HDFS(String p ...

  10. hisicv200 exfat支持

    由于项目中需要128Gsd卡支持.所以内核里面需要支持exfat 1.exfat 由于版权问题,所以linux kernel一直都没法支持,由于某些公司在linux kernel 3.9版本开源exf ...