int GetFaceGroupCnt(int Group) { TSearchHandle sh; TUser gUser; int Cnt=0; // int start=GetTickCount1(); sh.ContentType=FCT_USER; sh.buffer=(char*)&gUser; SearchFirst(&sh); while(!SearchNext(&sh)) { if(gUser.PIN>0&&gUser.Group==Group) { if(FDB_GetFaceRecord(gUser.PIN, 0 , NULL)) Cnt++; } } // printf("Get Group =%d , cnt=%d , : %dms \n", Group, Cnt, GetTickCount1()-start); return Cnt; }
int FDB_LoadUserFaceTmps(int pin, void* Handle) { TSearchHandle sh; sh.ContentType=FCT_FACEPOS; TFacePos gFacepos; char id[32]; int cnt=0; sh.buffer=(char *)&gFacepos; SearchFirst(&sh); while(!SearchNext(&sh)) { if(gFacepos.PIN==pin) { ReadFaceTmpData((char*)&gFacetmp, sizeof(TFaceTmp), gFacepos.RecordNum*sizeof(TFaceTmp)); memset(id,0,sizeof(id)); if(gFacetmp.FaceID >= FACE_LEARN_ID) sprintf(id, "%d_%06d_%02d", 4,gFacetmp.PIN, gFacetmp.FaceID); else sprintf(id, "%d_%06d_%02d", gFacetmp.FaceID%3,gFacetmp.PIN, gFacetmp.FaceID); ZKFaceCacheSet(Handle, id, gFacetmp.Face); cnt++; } } return cnt; }
U32 FDB_GetFaceRecord(U16 UID, char FaceID , PFacePos tmp) { TSearchHandle sh; sh.ContentType=FCT_FACEPOS; TFacePos gFacepos; if(tmp) sh.buffer=(char *)tmp; else sh.buffer=(char *)&gFacepos; SearchFirst(&sh); while(!SearchNext(&sh)) { if (sh.datalen==0) { if (UID==0) return sh.bufferlen; else continue; } if(((PFacePos)sh.buffer)->PIN==UID && ((PFacePos)sh.buffer)->FaceID==FaceID) { return sh.datalen; } } return 0; }
int ChangeFaceRecordData(PFacePos Facepos) { TSearchHandle sh; sh.ContentType=FCT_FACEPOS; TFacePos gFacepos; sh.buffer=(char *)&gFacepos; SearchFirst(&sh); while(!SearchNext(&sh)) { if(gFacepos.PIN==Facepos->PIN && gFacepos.FaceID == Facepos->FaceID) { lseek(fdfacepos, -1*sizeof(TFacePos), SEEK_CUR); if (write(fdfacepos, (void*)Facepos, sizeof(TFacePos))== sizeof(TFacePos)) { fsync(fdfacepos); return FDB_OK; } else return FDB_ERROR_IO; } } lseek(fdfacepos, 0, SEEK_END); if (write(fdfacepos, (void*)Facepos, sizeof(TFacePos))== sizeof(TFacePos)) { fsync(fdfacepos); return FDB_OK; } return FDB_ERROR_IO; }
/* TextEditor::replaceAll * Replaces all occurrences of [find] in the text with [replace]. * Returns the number of occurrences replaced *******************************************************************/ int TextEditor::replaceAll(string find, string replace, int flags) { // Check search string if (find.IsEmpty()) return false; // Start at beginning SetSelection(0, 0); // Loop of death int replaced = 0; while (true) { SearchAnchor(); int found = SearchNext(flags, find); if (found < 0) break; // No matches, finished else { // Replace text & increment counter Replace(found, found + find.length(), replace); replaced++; // Continue from end of replaced text SetSelection(found + find.length(), found + find.length()); } } // Return number of instances replaced return replaced; }
/* TextEditor::findNext * Finds the next occurrence of the [find] after the caret position, * selects it and scrolls to it if needed. Returns false if the * [find] was invalid or no match was found, true otherwise *******************************************************************/ bool TextEditor::findNext(string find, int flags) { // Check search string if (find.IsEmpty()) return false; // Get current selection int sel_start = GetSelectionStart(); int sel_end = GetSelectionEnd(); // Search forwards from the end of the current selection SetSelection(GetCurrentPos(), GetCurrentPos()); SearchAnchor(); int found = SearchNext(flags, find); if (found < 0) { // Not found, loop back to start SetSelection(0, 0); SearchAnchor(); found = SearchNext(flags, find); if (found < 0) { // No match found in entire text, reset selection SetSelection(sel_start, sel_end); return false; } } // Set caret to the end of the matching text // (it defaults to the start for some dumb reason) // and scroll to the selection SetSelection(found, found + find.length()); EnsureCaretVisible(); return true; }
int VerifyFaceTemps(char* SFace, int size, PUser user) { TSearchHandle sh; sh.ContentType=FCT_FACEPOS; TFacePos gFacepos; int Count=0; int pin=user->PIN; int result=0; int score=0; FaceVScore=0; sh.buffer=(char *)&gFacepos; SearchFirst(&sh); while(!SearchNext(&sh)) { if(gFacepos.PIN==pin) { ReadFaceTmpData((char*)&gFacetmp, sizeof(TFaceTmp), gFacepos.RecordNum*sizeof(TFaceTmp)); result=ZKFaceVerify((void*)FaceHandle[0].Handle,(unsigned char*)gFacetmp.Face,(unsigned char*)SFace); // printf("ddd 1:1 score: %d id=%d \n",result,gFacetmp.FaceID); if(result > score) score =result; if(score >= gOptions.FaceMThreshold) break; Count++; if( Count >= FACETEMPS_NUM) break; } } // printf("ddddd 1:1 verify \t FaceLearnThreshold=%d score=%d pin=%d group=%d \n",FaceLearnThreshold, score,user->PIN,user->Group); if(score >= FaceLearnThreshold) { FDB_AddLearnFaceTemplate(pin, user, SFace, size); } if (score >= gOptions.FaceVThreshold) { if(admflag && score < AdminFaceScore) return 0; FacePin=pin; FaceVScore=score; return FacePin; } return 0; }
U32 FDB_DelUserFaceRecords(U16 UID) { TSearchHandle sh; sh.ContentType=FCT_FACEPOS; TFacePos gFacepos; sh.buffer=(char *)&gFacepos; SearchFirst(&sh); while(!SearchNext(&sh)) { if(((PFacePos)sh.buffer)->PIN==UID) { DeleteFaceRecordData(&gFacepos); } } return FDB_OK; }
U32 FDB_DelFaceRecord(U16 UID, char FaceID) { TSearchHandle sh; sh.ContentType=FCT_FACEPOS; TFacePos gFacepos; sh.buffer=(char *)&gFacepos; SearchFirst(&sh); while(!SearchNext(&sh)) { if(((PFacePos)sh.buffer)->PIN==UID && ((PFacePos)sh.buffer)->FaceID==FaceID) { return DeleteFaceRecordData(&gFacepos); } } return 0; }
int FDB_GetUserFaceTemps(int pin, char*buf) { PFaceTmp face=(PFaceTmp)buf; TFacePos gFacepos; int Count=0; TSearchHandle sh; sh.ContentType=FCT_FACEPOS; sh.buffer=(char *)&gFacepos; SearchFirst(&sh); while(!SearchNext(&sh)) { if(gFacepos.PIN == pin) { ReadFaceTmpData((char*)&face[Count], sizeof(TFaceTmp), gFacepos.RecordNum*sizeof(TFaceTmp)); Count++; } } return Count; }
bool Edit::FindText(int &found_start, int &found_end, bool find_next) { const int flags = m_FindData.GetFlags(); const bool find_down = (flags & wxFR_DOWN) ? true : false; const wxString find_string = m_FindData.GetFindString(); found_start = found_end = -1; if (find_next) { GotoPos(find_down ? GetCurrentPos() : GetCurrentPos() - find_string.size()); } SearchAnchor(); // search up/down found_start = find_down ? SearchNext(flags, find_string) : SearchPrev(flags, find_string); // found if (found_start > -1) { found_end = found_start + find_string.size(); GotoPos(found_start); return true; } return false; }
int FDB_LoadFaceTmpByGroup(int Group, void* Handle) { TSearchHandle sh; PFacePos gFacepos; TUser gUser; char* buf=NULL; char id[32]; int len=0; int Cnt=0; int cuser=0; int i; int lface=0; if(Group <= 0 || Group > gFaceGroupNum ) return -1; // int start=GetTickCount1(); lseek(fdfacepos,0,SEEK_SET); len=lseek(fdfacepos,0,SEEK_END); if(len<=0) return 0; buf=MALLOC(len); if(buf==NULL) return 0; lseek(fdfacepos,0,SEEK_SET); if(read(fdfacepos,(void*)buf, len) != len) { FREE(buf); printf(" Load Face Template flailed Group=%d \n",Group); return 0; } Cnt=len/sizeof(TFacePos); gFacepos=(PFacePos)buf; ZKFaceCacheReset(Handle); len=0; cuser=0; sh.ContentType=FCT_USER; sh.buffer=(char*)&gUser; SearchFirst(&sh); while(!SearchNext(&sh)) { if(gUser.Group==Group) { lface=0; for(i=0;i<Cnt; i++) { if(gFacepos[i].PIN==gUser.PIN) { ReadFaceTmpData((char*)&gFacetmp, sizeof(TFaceTmp), gFacepos[i].RecordNum*sizeof(TFaceTmp)); memset(id,0,sizeof(id)); if(gFacetmp.FaceID >= FACE_LEARN_ID) sprintf(id, "%d_%06d_%02d", 4,gFacetmp.PIN, gFacetmp.FaceID); else sprintf(id, "%d_%06d_%02d", gFacetmp.FaceID%3,gFacetmp.PIN, gFacetmp.FaceID); ZKFaceCacheSet(Handle, id, gFacetmp.Face); len++; lface=1; } } if(lface) cuser++; if(Group == gOptions.DefFaceGroup && cuser >= gFaceDefGroupCnt) break; else if(Group != gOptions.DefFaceGroup && cuser >= gFaceGroupCnt) break; } } FREE(buf); ZKFaceCacheSort(Handle, 1); // printf("Load Group %d , face template %d Cnt=%d : %dms \n", Group, len,Cnt, GetTickCount1()-start); return len; }
/******************************** * mode =0 find pin2 and face group * mode=1 find group * mode=2 find pin2 * *****************************/ int GetUserFreePINAndFaceGroup(char* Freepin2, int* FreeGroup,int mode) { TSearchHandle sh; PUserCash pCacheUser= NULL; TUser gUser; int cuser=0;; int i=0,testpin=0; int bSign=TRUE, group=0,Cnt=0; char pin2[24]; // int start=GetTickCount1(); sh.ContentType=FCT_USER; sh.buffer=(char*)&gUser; SearchFirst(&sh); i=lseek(sh.fd, 0,SEEK_END); cuser=i/sizeof(TUser); i= cuser*sizeof(TUserCash); pCacheUser = MALLOC(i); if(NULL == pCacheUser) { memset(Freepin2,0,24); *FreeGroup=0; return -1; } memset(pCacheUser, 0, i); *FreeGroup=0; group=0; i=0; SearchFirst(&sh); while(!SearchNext(&sh)) { if(sh.datalen>0) { memcpy(pCacheUser[i].PIN2, gUser.PIN2, 24); pCacheUser[i].Group=gUser.Group; i++; } } if(mode ==0 || mode == 1) { group=1; for(i=0;i<cuser;i++) { if((pCacheUser[i].Group ==group)) //find group { Cnt++; if(group == gOptions.DefFaceGroup && Cnt >= gFaceDefGroupCnt) { group++; Cnt=0; i=0; continue; } else if(group != gOptions.DefFaceGroup && Cnt >= gFaceGroupCnt) { group++; Cnt=0; i=0; continue; } } } if(group>0) *FreeGroup=group; } if(mode ==0 || mode == 2) { testpin=0; do { bSign=1; testpin++; sprintf(pin2, "%d",testpin); for (i=0;i<cuser;i++) { if(strncmp(pCacheUser[i].PIN2,pin2,24)==0) { bSign=0; break; } } }while(!bSign); memcpy(Freepin2,pin2,24); } FREE(pCacheUser); // printf("find pin2=%s find Group %d , %dms \n", pin2, group, GetTickCount1()-start); return 1; }
int FDB_LoadAllFaceTmp(void) { TSearchHandle sh; PFacePos gFacepos; TUser gUser; char* buf=NULL; char id[32]; unsigned char UGroup[FACE_MAX_GROUP]; int Num[FACE_GROUP_NUM]; int flag[FACE_GROUP_NUM]; int len=0; int Cnt=0; int index=0; int lface=0; int i,j; if(!FaceInit) { printf(" InitFaceDB Failed No Licence ! \n"); return 0; } //int start=GetTickCount1(); /******** read face **********/ len=lseek(fdfacepos,0,SEEK_END); if(len<=0) return 0; buf=MALLOC(len); if(buf==NULL) return 0; lseek(fdfacepos,0,SEEK_SET); if(read(fdfacepos,(void*)buf, len) != len) { FREE(buf); printf(" Load Face Template flailed ! \n"); return 0; } Cnt=len/sizeof(TFacePos); gFacepos=(PFacePos)buf; for(i=0;i<FACE_GROUP_NUM;i++) { ZKFaceCacheReset(FaceHandle[i].Handle); FaceHandle[i].Count=0; FaceHandle[i].Group=0; Num[i]=0; flag[i]=0; } sh.ContentType=FCT_USER; sh.buffer=(char*)&gUser; /******** find group **********/ memset(UGroup,0,sizeof(UGroup)); SearchFirst(&sh); while(!SearchNext(&sh)) { for(i=0;i<Cnt; i++) { if(gFacepos[i].PIN==gUser.PIN) { UGroup[gUser.Group-1]++; break; } } } for(j=0;j<FACE_GROUP_NUM;j++) { lface=UGroup[0]; index=0; for(i=1; i< FACE_MAX_GROUP ;i++) { if(lface < UGroup[i]) { lface=UGroup[i]; index=i; } } UGroup[index]=0; if(lface >0) { FaceHandle[j].Count=lface; FaceHandle[j].Group=index+1; } } lface=FaceHandle[0].Count; index=0; for(i=1; i< FACE_GROUP_NUM ;i++) { if(FaceHandle[i].Count > lface) index=i; } if(index>0) { lface=FaceHandle[index].Count; FaceHandle[index].Count=FaceHandle[0].Count; FaceHandle[0].Count=lface; lface=FaceHandle[index].Group; FaceHandle[index].Group=FaceHandle[0].Group; FaceHandle[0].Group=lface; } MulGroup=0; for(i=1; i< FACE_GROUP_NUM; i++) { if(FaceHandle[i].Count > 0) { MulGroup=1; break; } } CurFaceGroup=FaceHandle[0].Group; #if 0 for(i=0;i<FACE_GROUP_NUM; i++) { printf("load face temp: \t count=%d ,Group=%d \n", FaceHandle[i].Count,FaceHandle[i].Group); } #endif /******** load face template **********/ memset(Num,0,sizeof(Num)); memset(flag,0,sizeof(flag)); SearchFirst(&sh); while(!SearchNext(&sh)) { for(j=0; j< FACE_GROUP_NUM ; j++) { if(gUser.Group==FaceHandle[j].Group && !flag[j]) { lface=0; for(i=0;i<Cnt; i++) { if(gFacepos[i].PIN==gUser.PIN) { ReadFaceTmpData((char*)&gFacetmp, sizeof(TFaceTmp), gFacepos[i].RecordNum*sizeof(TFaceTmp)); memset(id,0,sizeof(id)); if(gFacetmp.FaceID >= FACE_LEARN_ID) { sprintf(id, "%d_%06d_%02d", 4,gFacetmp.PIN, gFacetmp.FaceID); //printf("%s : group=%d\n",id,gUser.Group); } else sprintf(id, "%d_%06d_%02d", gFacetmp.FaceID%3,gFacetmp.PIN, gFacetmp.FaceID); ZKFaceCacheSet(FaceHandle[j].Handle, id, gFacetmp.Face); lface=1; } } if(lface) Num[j]++; if(FaceHandle[j].Group == gOptions.DefFaceGroup && Num[j] >= gFaceDefGroupCnt) flag[j]=1; else if(FaceHandle[j].Group != gOptions.DefFaceGroup && Num[j] >= gFaceGroupCnt) flag[j]=1; } } } FREE(buf); for(j=0; j< FACE_GROUP_NUM ; j++) ZKFaceCacheSort(FaceHandle[j].Handle, 1); //printf(" Load all Group face template Cnt=%d %dms \n", Cnt, GetTickCount1()-start); if(CurFaceGroup == 0) CurFaceGroup=gOptions.DefFaceGroup; return Cnt; }