static int DiskriminatorTest(void) { RecRaster myRaster; welet *wel; int i; Bool rett; RecVersions collect; for(i=0,wel=fonbase.start; i< fonbase.inBase; i++) { if( FONGetClusterAsBW(NULL,i,0,&myRaster) < 0 ) continue; rett=DIFInit( &myRaster, TRUE, FALSE); if(rett==FALSE) continue; memset(&collect,0,sizeof(RecVersions)); collect.lnAltCnt=1; collect.Alt[0].Code=(uchar)wel->let; collect.Alt[0].Prob=255; rett = DIFPenaltyChar(&myRaster,&collect); if(rett==FALSE) continue; if(collect.Alt[0].Prob < 250) // ?? wel->solid=0; } return 0; }
int32_t GetNearestClusters (int num, welet *wel, int numWel , RecVersions *collection ) { RecRaster recRast; RECRESULT recres[REC_MAX_VERS]; int xbit; int bytesx; int ret, j; int let = wel[num].let; memset(collection, 0, sizeof(RecVersions)); j = FONGetClusterAsBW( NULL, num, 0, &recRast); if (j < 0) return 0; xbit = recRast.lnPixWidth; bytesx = ((xbit + 63) / 64) * 8; ret = RecogClu(recRast.Raster, (int16_t)bytesx, (int16_t)xbit, (int16_t)recRast.lnPixHeight, recres, (int16_t)REC_MAX_VERS, wel, numWel, -1, 0, -1024, -1024, 1 ); if (ret <= 0) return 0; for (xbit = j = 0; xbit < ret; xbit++) { if ( let == recres[xbit].name ) continue; collection->Alt[j].Code = recres[xbit].name; // for every point - add straf collection->Alt[j].Prob = recres[xbit].prob; collection->Alt[j].Info = recres[xbit].nClust + 1; j++; } collection->lnAltCnt = j; return j; }
int32_t TestClustNames(welet *wel,int numWel, int name1,int name2 ) { int i,j; RecRaster recRast; int n2,d2; int dist1=0; // distance from name2 to name1 int dist2=0; // distance from name1 to name2 int dist; FonTestInfo testInfo[4]; for(i=0;i<numWel;i++) { if( wel[i].let == name1 ) { d2=dist2; n2=name2; } else if( wel[i].let == name2 ) { d2=dist1; n2=name1; } else continue; j=FONGetClusterAsBW( NULL,i,0,&recRast); if(j<0) continue; dist= FONTestChar(&recRast,(uchar)n2,testInfo,0); if(dist <= 0 || testInfo[0].prob <= d2 ) continue; if(n2==name2) dist2=dist; else dist1=dist; } return MIN(dist1,dist2); }
Bool32 TestFontCourier(void) { #ifdef _USE_LEO_ uchar p; int32_t name; RecRaster recRast; int i,j; int nClust; int porog=0; // test !!! int numCourier,nC; RecVersions MSKres; ClustInfo clustinfo; int32_t nf=FONGetFontCount(); if( nf<1 || nf>2) return FALSE; nClust=FONGetClustCount(); if(nClust < 20 ) return FALSE; if(!HndTab) return FALSE; MSKSetAlphabet ( alphabet ); for(i=0,nC=numCourier=0;i<nClust;i++) { name=0; j=FONGetClusterAsBW(&name,i,porog,&recRast); if(j<0) continue; if( name>'9' && name<128 ) continue; clustinfo.let = 0; // from all clusters FONGetClustInfo( &clustinfo, i+1 ); if( clustinfo.weight<3 ) continue; if(0) CTB_AddRecRaster("CLUST2", &recRast,decode_ASCII_to_[name][0]); MSKres.lnAltCnt=2; MSKres.lnAltMax=REC_MAX_VERS; MSKres.Alt[0].Code=(uchar)to_upper((uchar)name); MSKres.Alt[0].Prob=255; MSKres.Alt[1].Code=(uchar)to_lower((uchar)name); MSKres.Alt[1].Prob=255; if(!MSKRecogCharExp( HndTab, &recRast, &MSKres ) ) continue; p = MAX(MSKres.Alt[0].Prob,MSKres.Alt[1].Prob); if( p> 150) numCourier++; nC++; } if(numCourier*3 > nC*2) return TRUE; #endif return FALSE; }
Bool32 TestFontProtocol(void) { #ifdef _USE_LEO_ int32_t name; int i; //,j; int nClust; int numCourier,nC; FILE *fp; LeoFieldSetup fs={0}; RecRaster rec; RecObject ro={0}; LeoPageSetup ps={0}; int jj; if( _access("c:\\met.ini",0)==-1 ) return FALSE; nClust=FONGetClustCount(); set_alphabet(alphabet1, alpha_str); LEOSetPlatform(586); fs.nStyle = LS_PRINT; memcpy(fs.AlphaTable,alphabet1,256); LEOSetupField(&fs); CTB_unlink("CLUST2"); fp=fopen(".\\clu_met.pro","wt"); for(i=0,nC=numCourier=0;i<nClust;i++) { for(jj=0;jj<3;jj++) { name=0; FONGetClusterAsBW(&name,i,jj*25,&rec); CTB_AddRecRaster("CLUST2", &rec,decode_ASCII_to_[name][0]); memset(&ro,0,sizeof(RecObject)); memcpy(&ro.recData.recRaster,&rec,REC_MAX_RASTER_SIZE); ps.nIdPage=-1; ro.recData.lwStatus=0; LEOSetupPage(&ps); fprintf(fp,"Nclu=%d(%d) let=%c tresh=%d%s\n",i,i*3+jj, name, jj,jj?"":"(default)" ); LEORecogPrintChar(&ro); print_method(fp,&ro.recResults," leo : ",1); LEORecogPrnMethod( &ro , REC_METHOD_MSK, 1); print_method(fp,&ro.recResults," msk : ",0); LEORecogCharDebug( &ro ); print_method(fp,&ro.recResults," evn+3x5 : ",1); } // end treshold fprintf(fp,"\n"); } // end clusters fclose(fp); #endif return TRUE; }
int32_t TestFontClusters(void) { #ifdef _USE_LEO_ int32_t name; int i,j; int nClust; int porog=50; // test !!! int numInvalid; LeoFieldSetup fs={0}; RecRaster rec; RecObject ro={0}; LeoPageSetup ps={0}; ClustInfo cluInfo; uchar addLet,resLet; #ifdef _SAVE_INVALID_CLU_ FILE *fp; #endif curNumFile++; nClust=FONGetClustCount(); set_alphabet(alphabet1, alpha_str); #ifdef _SAVE_INVALID_CLU_ fp=fopen("clust.tst","at"); fprintf(fp,"file %d\n",curNumFile); #endif LEOSetPlatform(LEOGetCPU()); fs.nStyle = LS_PRINT; memcpy(fs.AlphaTable,alphabet1,256); LEOSetupField(&fs); for(i=0,numInvalid=0;i<nClust;i++) { cluInfo.let = 0; j=FONGetClustInfo(&cluInfo,i+1); if(j<=0) continue; if(cluInfo.attr & CTB_PRINT_ITALIC) continue; if(cluInfo.attr & CTB_PRINT_BOLD) continue; // now - test only russian ASCII letters if(cluInfo.let < 128 || cluInfo.let >= 176 && cluInfo.let < 224 || cluInfo.let > 240 ) continue; addLet=(cluInfo.let < 144 ? cluInfo.let +32 : cluInfo.let < 160 ? cluInfo.let +80 : cluInfo.let < 176 ? cluInfo.let -32 : cluInfo.let - 80 ); name=0; FONGetClusterAsBW(&name,i,porog,&rec); memset(&ro,0,sizeof(RecObject)); memcpy(&ro.recData.recRaster,&rec,sizeof(RecRaster)); ps.nIdPage=-1; ro.recData.lwStatus=0; LEOSetupPage(&ps); LEORecogPrintChar(&ro); // ничего хорошего по LEO ? if( ro.recResults.lnAltCnt <= 0 || ro.recResults.Alt[0].Prob < 150 ) continue; for(j=0;j<ro.recResults.lnAltCnt;j++) { resLet = stdAnsiToAscii(ro.recResults.Alt[j].Code); if( resLet == cluInfo.let || resLet == addLet ) break; } if(j==0) continue; { char *qq; resLet = stdAnsiToAscii(ro.recResults.Alt[0].Code); if( !is_lower(resLet) ) resLet = to_lower(resLet); if( (qq=strchr(hasNearSame,cluInfo.let)) && NearSame[qq-(char*)hasNearSame] == resLet ) continue; } // узналось как что-то иное ? // если совсем не распозналось - бывает ('»' в sten91) if( j >= ro.recResults.lnAltCnt || ro.recResults.Alt[j].Prob < 180 || ro.recResults.Alt[j].Prob < 220 && ro.recResults.Alt[j].Prob + 25 < ro.recResults.Alt[0].Prob ) { FonTestInfo testInfo[MAXCHECKALT]; // проверим resLet = stdAnsiToAscii(ro.recResults.Alt[0].Code); j=FONTestChar(&rec,resLet,testInfo,0); if( j <=0 || testInfo[0].prob <= 215 ) { resLet=(resLet < 144 ? resLet +32 : resLet < 160 ? resLet +80 : resLet < 176 ? resLet -32 : resLet - 80 ); j=FONTestChar(&rec,resLet,testInfo,0); } if( j > 0 && testInfo[0].prob > 215 ) { numInvalid++; FONSetClusterInvalid(i+1); #ifdef _SAVE_INVALID_CLU_ fprintf(fp," invalid %d (%c -> %c(%d))\n",i+1,cluInfo.let, stdAnsiToAscii(ro.recResults.Alt[0].Code), ro.recResults.Alt[0].Prob); #endif } } // end if j } // end clusters #ifdef _SAVE_INVALID_CLU_ fclose(fp); #endif return numInvalid; #else return 0; #endif }