コード例 #1
0
ファイル: rectpic.cpp プロジェクト: nctan/quneiform
Bool32 SearchRectanglePictures(CCOM_handle hCCOM, CCOM_handle hCCOM_big, Handle hCPAGE) {
	uint32_t i, j;
	CCOM_comp pic;
	CCOM_comp * comp;
	uint16_t pLocalHystogram[MaxHeightOfLetter];
	uint32_t nLocalComps;
	uint32_t MaxLocal, nMaxLocal;
	uint32_t Result1, Result2, Result3, Result4, tmp1, tmp2;
	Rect32 rect;
	int32_t LengthTotal, LengthByIntervals;
	Handle BlockType;
	RecRaster rec;
	RecVersions vs;
	int16_t Language;
	RPIC_Comp_Rect CompRect;

	BlockType = CPAGE_GetInternalType("pic's to letters boxes");

	for (i = 0; i < nPics; i++) {
		pic = pPics[i];
		my_upper = pic.upper;
		my_left = pic.left;
		my_bottom = pic.upper + pic.h;
		my_right = pic.left + pic.w;

		//Additional parameter - local distribution of heights
		//in case of local fragment with different (from main) height
		nLocalComps = 0;
		for (j = 0; j < MaxHeightOfLetter; j++) {
			pLocalHystogram[j] = 0;
		}

		//stepa_am
		comp = CCOM_GetFirst(hCCOM_big, &MyFiltrateIn);
		while (comp) {
			if ((comp->h < MaxHeightOfLetter) && (comp->h > MinHeightOfLetter)) {
				pLocalHystogram[comp->h]++;
				nLocalComps++;
			}
			comp = CCOM_GetNext(comp, &MyFiltrateIn);
		}
		//end stepa_am

		comp = CCOM_GetFirst(hCCOM, &MyFiltrateIn);
		while (comp) {
			if ((comp->h < MaxHeightOfLetter) && (comp->h > MinHeightOfLetter)) {
				pLocalHystogram[comp->h]++;
				nLocalComps++;
			}
			comp = CCOM_GetNext(comp, &MyFiltrateIn);
		}

		if (nLocalComps != 0) {
			MaxLocal = pLocalHystogram[0];
			for (j = 0; j < MaxHeightOfLetter; j++) {
				if (pLocalHystogram[j] > MaxLocal) {
					MaxLocal = pLocalHystogram[j];
					nMaxLocal = j;
				}
			}

			Result1 = 0;
			Result2 = 0;
			sprintf(tmp_str, " %i Result1 (must be 0)\n", Result1);
			LDPUMA_FPuts(logFile_comp, tmp_str);
			sprintf(tmp_str, " %i Result2 (must be 0)\n", Result2);
			LDPUMA_FPuts(logFile_comp, tmp_str);
			sprintf(tmp_str, " %i (nComps)\n", nComps);
			LDPUMA_FPuts(logFile_comp, tmp_str);

			//stepa_am
			comp = CCOM_GetFirst(hCCOM_big, &MyFiltrateIn);
			while (comp) {
				//sprintf(tmp_str, " %i  (comp)\n", comp);
				//LDPUMA_FPuts(hFile,tmp_str);
				if ((comp->h < MaxHeightOfLetter - 1) && (comp->h
						> MinHeightOfLetter)) {

					sprintf(tmp_str, " %i  (comp->h)\n", comp->h);
					LDPUMA_FPuts(logFile_comp, tmp_str);
					sprintf(tmp_str, " %i  (pHystogram[comp->h])\n",
							pHystogram[comp->h]);
					LDPUMA_FPuts(logFile_comp, tmp_str);

					//Result1 += OVERALL*pHystogram[comp->h];
					Result1 += pHystogram[comp->h] / 20 + pHystogram[comp->h
							- 1] / 20 + pHystogram[comp->h + 1] / 20;
					if (comp->h - nMaxLocal < DIFFERENCE1) {
						//Result2 += LOCAL*pLocalHystogram[comp->h];
						Result2 += pLocalHystogram[comp->h]
								+ pLocalHystogram[comp->h - 1]
								+ pLocalHystogram[comp->h + 1];
					}
				}
				comp = CCOM_GetNext(comp, &MyFiltrateIn);
			}
			//end stepa_am

			comp = CCOM_GetFirst(hCCOM, &MyFiltrateIn);
			while (comp) {
				//sprintf(tmp_str, " %i  (comp)\n", comp);
				//LDPUMA_FPuts(hFile,tmp_str);
				if ((comp->h < MaxHeightOfLetter - 1) && (comp->h
						> MinHeightOfLetter)) {

					sprintf(tmp_str, " %i  (comp->h)\n", comp->h);
					LDPUMA_FPuts(logFile_comp, tmp_str);
					sprintf(tmp_str, " %i  (pHystogram[comp->h])\n",
							pHystogram[comp->h]);
					LDPUMA_FPuts(logFile_comp, tmp_str);

					//Result1 += OVERALL*pHystogram[comp->h];
					Result1 += pHystogram[comp->h] / 20 + pHystogram[comp->h
							- 1] / 20 + pHystogram[comp->h + 1] / 20;
					if (comp->h - nMaxLocal < DIFFERENCE1) {
						//Result2 += LOCAL*pLocalHystogram[comp->h];
						Result2 += pLocalHystogram[comp->h]
								+ pLocalHystogram[comp->h - 1]
								+ pLocalHystogram[comp->h + 1];
					}
				}
				comp = CCOM_GetNext(comp, &MyFiltrateIn);
			}

			//Result1 = Result1/nComps;
			Result1 = Result1 / 10;
			//Result2 = Result2/nLocalComps;
			Result2 = Result2 / 20;

			sprintf(tmp_str, " Picture %i (i)\n", i);
			LDPUMA_FPuts(logFile_comp, tmp_str);
			sprintf(tmp_str, " %i (Result1)\n", Result1);
			LDPUMA_FPuts(logFile_comp, tmp_str);
			sprintf(tmp_str, " %i (Result2)\n", Result2);
			LDPUMA_FPuts(logFile_comp, tmp_str);

			if (Result1 + Result2 > CONDITION1) {
				DeleteFromPics(i);
				//i--;
				continue;
			}
		}

		/**************************************************************************/
		/*                      Analys by comp's count of begins&ends             */
		/**************************************************************************/

		CCOM_USER_BLOCK uBlock;
		uBlock.code = CCOM_UB_BEGENDS;
		if (CCOM_GetUserBlock(&pPics[i], &uBlock)) {
			if (*(uchar*) uBlock.data > 100) {
				continue;
			}
		}

		/**************************************************************************/
		/*                      Analys by comp's intervals                        */
		/**************************************************************************/

		//CCOM_USER_BLOCK uBlock;
		uBlock.code = CCOM_UB_DENSITY;
		if (CCOM_GetUserBlock(&pPics[i], &uBlock)) {
			LengthByIntervals = *(int32_t*) uBlock.data;
			LengthTotal = pPics[i].h * pPics[i].w;

			if (LengthByIntervals == 0) {
				return FALSE;
			}

			if (LengthTotal / LengthByIntervals > CONDITION2) {
				DeleteFromPics(i);
				//i--;
			}
		}

	}

	/************** final union all crossed and included pictures ******************/
	CCOM_comp common;
	for (i = 0; i < nPics; i++) {
		if (pPics[i].large & CCOM_LR_KILLED) {
			continue;
		}
		for (j = 0; j < nPics; j++) {
			if (pPics[j].large & CCOM_LR_KILLED) {
				continue;
			}
			if ((pPics[i].upper < pPics[j].upper) && (pPics[i].left
					< pPics[j].left) && (pPics[i].left + pPics[i].w
					> pPics[j].left + pPics[j].w) && (pPics[i].upper
					+ pPics[i].h > pPics[j].upper + pPics[j].h)) {
				if ((pPics[i].type != CCOM_CH_LETTER) || (pPics[j].type
						!= CCOM_CH_LETTER)) {
					pPics[i].type = CCOM_CH_MERGE;
				}
				DeleteFromPics(j);
				//j--;
			}
		}
	}

	for (i = 0; i < nPics; i++) {
		if (pPics[i].large & CCOM_LR_KILLED) {
			continue;
		}
		for (j = 0; j < nPics; j++) {
			if (pPics[j].large & CCOM_LR_KILLED) {
				continue;
			}
			if (i == j)
				continue;
			if ((pPics[i].upper < pPics[j].upper + pPics[j].h)
					&& (pPics[i].left < pPics[j].left + pPics[j].w)
					&& (pPics[i].left + pPics[i].w > pPics[j].left)
					&& (pPics[i].upper + pPics[i].h > pPics[j].upper)) {
				common = pPics[i];
				if (pPics[i].upper >= pPics[j].upper)
					common.upper = pPics[j].upper;
				if (pPics[i].left >= pPics[j].left)
					common.left = pPics[j].left;
				if (pPics[i].upper + pPics[i].h < pPics[j].upper + pPics[j].h)
					common.h = pPics[j].upper + pPics[j].h - pPics[i].upper;
				if (pPics[i].left + pPics[i].w < pPics[j].left + pPics[j].w)
					common.w = pPics[j].left + pPics[j].w - pPics[i].left;
				common.h += pPics[i].upper - common.upper;
				common.w += pPics[i].left - common.left;
				pPics[i] = common;
				/*
				 if((pPics[i].type!=CCOM_CH_LETTER)||(pPics[j].type!=CCOM_CH_LETTER))
				 {
				 pPics[i].type = CCOM_CH_MERGE;
				 }
				 */
				pPics[i].type = CCOM_CH_NOTLTR;
				DeleteFromPics(j);
				//j=0;
				//i=0;
			}
		}
	}

	for (i = 0; i < nPics; i++) {
		if (pPics[i].large & CCOM_LR_KILLED) {
			continue;
		}
		pic = pPics[i];
		my_upper = pic.upper;
		my_left = pic.left;
		my_bottom = pic.upper + pic.h;
		my_right = pic.left + pic.w;
		/*
		 Deleting from Pics, in case of Titles and "Bukvica", zero version,
		 planing CHECK (by Oleg) for Letters in case of Bukvica, else check for
		 comps with compatible heights in local area (horizontal).
		 */
		if (pPics[i].scale <= 3) {
			rect.top = pPics[i].upper;
			rect.left = pPics[i].left + pPics[i].w;
			rect.bottom = pPics[i].upper + pPics[i].h;
			rect.right = pPics[i].left + pPics[i].w + pPics[i].h;
			CheckAreaForComps(hCCOM, hCCOM_big, rect, nAverageHeight, &Result1,
					&Result2);

			if ((Result1 > 10) && (pPics[i].type != CCOM_CH_NOTLTR)) {
				if (CCOM_GetRaster(&pPics[i], &rec) && CCOM_GetLanguage(hCCOM,
						&Language) && RSTR_RecogOneLetter(&rec, (uchar)(
						Language), &vs)) {

					if ((vs.lnAltCnt > 0) && (vs.Alt[0].Prob > 240)
							&& (vs.Alt[0].Code != 'i') && (vs.Alt[0].Code
							!= '1') && (vs.Alt[0].Code != 'I')
							&& (vs.Alt[0].Code != 'l')) {
						pPics[i].type = CCOM_CH_LETTER;
						CompRect.upper = pPics[i].upper;
						CompRect.left = pPics[i].left;
						CompRect.h = pPics[i].h;
						CompRect.w = pPics[i].w;
						CPAGE_CreateBlock(hCPAGE, BlockType, 0, 0, &CompRect,
								sizeof(CompRect));

						DeleteFromPics(i);
						//i--;
						continue;
					}
				}
			}

			rect.top = pPics[i].upper - (int32_t)(0.3 * (double) (pPics[i].h));
			rect.left = pPics[i].left - 12* pPics [i].h;
			rect.bottom = pPics[i].upper + (int32_t)(1.3
					* (double) (pPics[i].h));
			//rect.right = pPics[i].left + pPics[i].w;
			rect.right = pPics[i].left;
			CheckAreaForComps(hCCOM, hCCOM_big, rect, pPics[i].h, &Result1,
					&Result2);
			if (Result2 > 7) {
				rect.top = pPics[i].upper - (int32_t)(0.3
						* (double) (pPics[i].h));
				rect.left = pPics[i].left - (int32_t)(1.5
						* (double) (pPics[i].h));
				rect.bottom = pPics[i].upper + (int32_t)(1.3
						* (double) (pPics[i].h));
				rect.right = pPics[i].left;
				CheckAreaForComps(hCCOM, hCCOM_big, rect, pPics[i].h, &tmp1,
						&tmp2);
				if (tmp2 == 0)
					Result2 = 0;
			}
			if ((Result1 > 3) || (Result2 > 7)) {
				pPics[i].type = CCOM_CH_LETTER;
				CompRect.upper = pPics[i].upper;
				CompRect.left = pPics[i].left;
				CompRect.h = pPics[i].h;
				CompRect.w = pPics[i].w;
				CPAGE_CreateBlock(hCPAGE, BlockType, 0, 0, &CompRect,
						sizeof(CompRect));

				DeleteFromPics(i);
				//i--;
				continue;
			}

			rect.top = pPics[i].upper - (int32_t)(0.3 * (double) (pPics[i].h));
			rect.left = pPics[i].left + pPics[i].w;
			rect.bottom = pPics[i].upper + (int32_t)(1.3
					* (double) (pPics[i].h));
			rect.right = pPics[i].left + pPics[i].w + 12* pPics [i].h;
			CheckAreaForComps(hCCOM, hCCOM_big, rect, pPics[i].h, &Result3,
					&Result4);
			if (Result4 > 0) {
				rect.top = pPics[i].upper - (int32_t)(0.3
						* (double) (pPics[i].h));
				rect.left = pPics[i].left + pPics[i].w;
				rect.bottom = pPics[i].upper + (int32_t)(1.3
						* (double) (pPics[i].h));
				rect.right = pPics[i].left + pPics[i].w + (int32_t)(1.5
						* (double) (pPics[i].h));
				CheckAreaForComps(hCCOM, hCCOM_big, rect, pPics[i].h, &tmp1,
						&tmp2);
				if (tmp2 == 0)
					Result4 = 0;
			}
			if ((Result3 > 3) || (Result4 > 7) || (Result1 + Result3 > 3)
					|| (Result2 + Result4 > 7)) {
				pPics[i].type = CCOM_CH_LETTER;
				CompRect.upper = pPics[i].upper;
				CompRect.left = pPics[i].left;
				CompRect.h = pPics[i].h;
				CompRect.w = pPics[i].w;
				CPAGE_CreateBlock(hCPAGE, BlockType, 0, 0, &CompRect,
						sizeof(CompRect));

				DeleteFromPics(i);
				//i--;
				continue;
			}
		}
	}

	return TRUE;
}
コード例 #2
0
void NegRecog(Handle hCPage,NegList** proot,int& nRC,int skew)
{
 uint32_t code_recd=512<<19;
 uint32_t code_resd=(512<<19)+(512<<16);
 CCOM_handle hNegCCOM;
 CCOM_comp * pcomp;
 Rect16* pN;
 Rect16* pRc;
 int i,j,r;
 int medium_w;
 int nN=0;
 int len_neg_mas=100;
 int add_len_mas=50;
 Bool vertical;
 char Alf[256];
 Bool nomem=FALSE;
 NegList* root=(*proot);
 NegList* now=root;
 NegList* temp;
 uchar Prob[3];
 double neg_str_control;
 int len_result;
 double prec;
 double prob0[2], prob1[2];

 for(i=1;i<nRC;i++)
	 now=now->next;

 NegSetAlf(Alf);

 while(now)
 {
  if((now->neg).rot.pmasp)
  {
	  if((now->neg).nRc>10)
	  {
		  delete[] (now->neg).rot.hi;
		  (now->neg).rot.hi= new int[(now->neg).nRc];
	  }
	  RSELSTR_UnRotateRect(-skew,(now->neg).pRc,(now->neg).nRc,(now->neg).rot.Rc,(now->neg).rot.begx,(now->neg).rot.movey,(now->neg).rot.flmovey,(now->neg).rot.hi);
  }

  pRc=(now->neg).pRc;
  vertical=FALSE;

  if(!((pRc[(now->neg).nRc-1].bottom-pRc[0].top)*2<(pRc[0].right-pRc[0].left)))
  {
   vertical=TRUE;
  }

  for(i=(now->neg).nRc-1;i>=0;i--)
  {

   nomem=FALSE;
   len_neg_mas=100;
   nN=0;

   hNegCCOM=0;
   hNegCCOM=GetNegCCOM(hCPage,pRc,i);
   if(!hNegCCOM)
	   continue;

   if(i<MAX_STR)
	   now->neg.hCCOM[i]=hNegCCOM;

   pcomp = CCOM_GetFirst (hNegCCOM, NULL);
   if(pcomp==NULL)
   {
	  NegMoveMas((now->neg).pRc,(now->neg).nRc,i);
	  NegMoveMas(now->neg.hCCOM,now->neg.nRc,i);
	  if(i==0)
	  {
       (now->neg).p_rec/=(double)((now->neg).nRc);
	   (now->neg).p_str/=(double)((now->neg).nRc);
	   (now->neg).p=((now->neg).p_rec+(now->neg).p_str)/2.;
       if(dpPrintResConsole)
	   {
	    LDPUMA_ConsoleN("");
	    LDPUMA_Console("Ќегатив с веро¤тностью :");
	    LDPUMA_ConsoleN("");
	    LDPUMA_Console("по внутренней структуре ");
	    NegPrintConsol((now->neg).p_str);
	    LDPUMA_Console("по результатам распозновани¤ ");
	    NegPrintConsol((now->neg).p_rec);
	    LDPUMA_Console("итого ");
        NegPrintConsol((now->neg).p);
        LDPUMA_ConsoleN("площадь=%d",(int)((now->neg).pRc[0].right-(now->neg).pRc[0].left+1)*(int)((now->neg).pRc[0].bottom-(now->neg).pRc[(now->neg).nRc-1].top+1));
	   }
	   if(dpNegResD )
	   {
        Rect16 Rect;
        Rect.bottom=(now->neg).pRc[0].bottom;
		Rect.left=(now->neg).pRc[0].left;
		Rect.right=(now->neg).pRc[0].right+1;
		Rect.top=(now->neg).pRc[(now->neg).nRc-1].top-1;
		LDPUMA_DrawRect (MainWindowD, &(Rect),0,RGB(0,0,255), 1,code_resd );
        LDPUMA_WaitUserInput (NegResD,MainWindowD);
        LDPUMA_DeleteRects (MainWindowD,code_resd);
	   }
	  }
   }
   if(pcomp==NULL)
	  continue;



   if(!(InitNegMas(&pN,len_neg_mas)))
    continue;

   InitRc(pN,nN,pcomp);

   nN++;
   for(;;)
   {
    pcomp = CCOM_GetNext (pcomp, NULL);
    if (pcomp==NULL)
	 break;
    if (nN>=len_neg_mas)
    {
		 AddLenNegMas(&pN,len_neg_mas,add_len_mas);

    }
    InitRc(pN,nN,pcomp);

    nN++;
   }

   if(i>=MAX_STR)
      CCOM_DeleteContainer(hNegCCOM);

   if((now->neg).rot.pmasp)
   {
    RSELSTR_CleanStr(pN,NULL,nN,pRc[i].top,pRc[i].left,(now->neg).rot.hi[i],pRc[i].right-pRc[i].left+1,skew,FALSE);
   }
   if(!nN)
	  DelNegMas(&pN);
   if(!nN)
	   continue;

  /*ѕрорисовка компонент в негативе*/

   if(nN>0)
   {
    if(dpNegRecD)
    {
     for(j=0;j<nN;j++)
      NegDrawRect(MainWindowD,code_recd,RGB(0,0,255),pN[j]);
     LDPUMA_WaitUserInput (NegRecD,MainWindowD);
     if(LDPUMA_Skip (NegRecDC) )
      LDPUMA_DeleteRects (MainWindowD,code_recd);
    }
   }

   SortLetter(pN,nN,vertical);

   neg_str_control=NegStrControl(pN,nN,vertical,&(now->neg.pRc[i]));
   (now->neg).p_str+=neg_str_control;
   RecVersions* vs;
   UniVersions* uvs;

   if(!(InitNegMas(&vs,nN)))
   {
    nomem=TRUE;
    DelNegMas(&pN);
   }
   if(nomem==TRUE)
	  continue;

   if(!(InitNegMas(&uvs,nN)))
   {
    nomem=TRUE;
    DelNegMas(&pN);
    DelNegMas(vs);
   }
   if(nomem==TRUE)
	  continue;

   RecRaster rec;
   int16_t Language;
   int turn;

  if(neg_str_control/2.>inf_prob-.5)
  {
   if( !(CCOM_GetLanguage(hNegCCOM, &Language)) )
	 Language=7;
   for(j=0; j<2; j++)
   {
       prob0[j] = 0;
       prob1[j] = 0;
   }

   Bool32 ShowNegByOne = !LDPUMA_Skip(hShowNegComps);
   Handle comp_window = NULL;

   for(j=0;j<nN;j++)
   {
    if( NegGetRaster(hCPage,pN[j],&rec,vertical) )
    {
     if(!dpRecOneLetter)
	 {
//         if (vertical) TurnOverNeg(&rec);
         for(turn=0; turn<2; turn++)
         {

//-----------------------------------------------------------
            if (ShowNegByOne/* && vertical*/)
            {
               BITMAPINFOHEADER   lpBI;     // Pointer to DIB info structure
               RGBQUAD            Palette1;
               RGBQUAD            Palette2;
	           uint32_t              bfSize, dwDIBSize;
	           HANDLE             hDIB;
	           uchar*              pDIB;
	           uchar*              pTmpDIB;
	           uchar*              pTmpBuffer;
               uint16_t               Height, Width, ByteWidth;
               CIMAGEBITMAPINFOHEADER image_info = {0};

               Height    = (uint16_t)rec.lnPixHeight;
               Width     = (uint16_t)rec.lnPixWidth;

               ByteWidth = (Width+7)/8;
               dwDIBSize = 64 * Height;
               bfSize    = dwDIBSize + sizeof(BITMAPINFOHEADER) + 2*sizeof(RGBQUAD);

               /////////////////  Bitmap  information header   //////////////////////////////////
               lpBI.biSize           = sizeof(BITMAPINFOHEADER);
               lpBI.biWidth          = 64;
               lpBI.biHeight         = Height;
               lpBI.biPlanes         = 0x1;
               lpBI.biBitCount       = 0x1;
               lpBI.biCompression    = 0;
               lpBI.biSizeImage      = dwDIBSize;
               CIMAGE_GetImageInfo((puchar)PUMA_IMAGE_USER, &image_info);
               lpBI.biXPelsPerMeter  = image_info.biXPelsPerMeter;
               lpBI.biYPelsPerMeter  = image_info.biYPelsPerMeter;
               lpBI.biClrUsed        = 0;
               lpBI.biClrImportant   = 0;

               ///////////////    Palette   ///////////////////////////////////////////////////////////
               Palette1.rgbBlue      = 0xFF;
               Palette1.rgbGreen     = 0xFF;
               Palette1.rgbRed       = 0xFF;
               Palette1.rgbReserved  = 0;

               Palette2.rgbBlue      = 0;
               Palette2.rgbGreen     = 0;
               Palette2.rgbRed       = 0;
               Palette2.rgbReserved  = 0;

               hDIB = calloc(1, bfSize);
 	           if (hDIB != 0)
               {
                    pDIB = static_cast<uchar*> (hDIB);
                    pTmpDIB = pDIB;

                    /////////  filling Dib   ///////////////////////////////////////////////////////////

                    memcpy(pTmpDIB, &lpBI, sizeof(BITMAPINFOHEADER));
                    pTmpDIB += sizeof(BITMAPINFOHEADER);

                    memcpy(pTmpDIB, &Palette1, sizeof(RGBQUAD));
                    pTmpDIB += sizeof(RGBQUAD);

                    memcpy(pTmpDIB, &Palette2, sizeof(RGBQUAD));
                    pTmpDIB += sizeof(RGBQUAD);

                    pTmpBuffer = rec.Raster;
					uchar* pTempDib = pTmpDIB;

                    for(int i=0; i<Height; i++ )
                    {
                        memcpy(pTmpDIB, pTmpBuffer, 8);
                        pTmpDIB += 8;
                        pTmpBuffer += 8;
                    }

					TurnOverNeg(rec, pTempDib);

                    const char *pText;
                    pText = turn ? "Component up-down" : "Component down-up";
                    comp_window = LDPUMA_CreateWindow(pText, pDIB);
//                    LDPUMA_WaitUserInput(hShowNegComps, comp_window);
                    free(hDIB);
               }
            }
//----------------------------------------------------------------------

        	  if( !(RSTR_RecogOneLetter_all (&rec,Alf, &(vs[j]),(int32_t)(1)) ) )
                Prob[1]=0;
	          else
              {
		        if (!turn) Prob[1]=vs[j].Alt[0].Prob;
                prob1[turn] += NegRecControl((int)vs[j].Alt[0].Prob);

				if (ShowNegByOne)
					LDPUMA_ConsoleN("handprint symbol: %c , probability = %d", (char)vs[j].Alt[0].Code, vs[j].Alt[0].Prob);
              }
//	  if( !(RSTR_RecogOneLetter_all (&rec,Alf, &(vs[j]),(int32_t)(2)) ) )
//            Prob[2]=0;
//	  else
//		  Prob[2]=vs[j].Alt[0].Prob;
	          if( !(RSTR_RecogOneLetter_all (&rec,Alf, &(vs[j]),(int32_t)(0)) ) )
                Prob[0]=0;
	          else
              {
		        if (!turn) Prob[0]=vs[j].Alt[0].Prob;
                prob0[turn] += NegRecControl((int)vs[j].Alt[0].Prob);

				if (ShowNegByOne)
					LDPUMA_ConsoleN("print symbol: %c , probability = %d", (char)vs[j].Alt[0].Code, vs[j].Alt[0].Prob);
              }

			 if (ShowNegByOne)
				LDPUMA_WaitUserInput(hShowNegComps, comp_window);

             if (!vertical) break;
             if (!turn) TurnRaster(&rec);
         }


         vs[j].Alt[0].Prob=(uchar)( ((int)(Prob[0])+(int)(Prob[1])/*+(int)(Prob[2])*/)/2/*3*/);


	  /*else
	  {
		  vs[j].lnAltMax =uvs[j].lnAltMax;
		  vs[j].lnAltCnt=uvs[j].lnAltCnt;
		  for(int alt=0;alt<uvs[j].lnAltCnt;alt++)
		  {
			  vs[j].Alt[alt].Code=uvs[j].Alt[alt].Code[0];
              vs[j].Alt[alt].Prob=uvs[j].Alt[alt].Prob;
		  }

	  }*/

	 }
     else
	 {

	  if( !(RSTR_RecogOneLetter (&rec, (uchar)(Language), &(vs[j])) ) )
       vs[j].Alt[0].Prob=0;

	 }
    }
    else
       vs[j].Alt[0].Prob=0;
   }
  }

   if(vertical)
	  ToHoriz(pN,nN);


   medium_w=GetMediumW(pN,nN);
   int medium_h=GetMediumH(pN,nN);

   uchar* result=NULL;
   if(!(result=new uchar[nN*2]))
   {
    nomem=TRUE;
    DelNegMas(&pN);
    DelNegMas(vs);
    DelNegMas(uvs);
   }
   if(nomem==TRUE)
	  continue;

   len_result=0;
   NegPutLetter(result,len_result,vs[0].Alt[0],FALSE);
  if(neg_str_control/2.>inf_prob-.5)
  {
   prec=NegRecControl(vs[0].Alt[0].Prob);
   for(j=1;j<nN;j++)
   {
    prec+=NegRecControl(vs[j].Alt[0].Prob);
/*    if( (pN[j].left-pN[j-1].right)>(medium_w/2)*3+2)
	{
		NegPutLetter(result,len_result,vs[j].Alt[0],TRUE);
		if( (pN[j].right-pN[j].left+1>(pN[j].bottom-pN[j].top+1)*2) && (pN[j].bottom-pN[j].top+1<medium_h/2) )
			result[len_result-1]='-';
		if( (pN[j].top<pN[j-1].top) && (pN[j].bottom-pN[j].top+1<medium_h/2) )
		{
				len_result--;
				if( IfExistI(vs[j-1]) )
				 result[len_result-1]=256+'…';
		}
		if((pN[j].bottom-pN[j].top+1<(medium_h/3)*2)&&( (result[len_result-1]=='I')||(result[len_result-1]=='|')||((result[len_result-1]=='?') && (IfExistDef(vs[j]))) ) )
			result[len_result-1]=',';
	}
    else
	{
		NegPutLetter(result,len_result,vs[j].Alt[0],FALSE);
		if( (pN[j].right-pN[j].left+1>(pN[j].bottom-pN[j].top+1)*2) && (pN[j].bottom-pN[j].top+1<medium_h/2) )
			result[len_result-1]='-';
		if( (pN[j].top<pN[j-1].top) && (pN[j].bottom-pN[j].top+1<medium_h/2) )
		{
				len_result--;
				if( IfExistI(vs[j-1]) )
				 result[len_result-1]=256+'…';
		}
		if((pN[j].bottom-pN[j].top+1<(medium_h/3)*2)&&( (result[len_result-1]=='I')||(result[len_result-1]=='|')||((result[len_result-1]=='?') && (IfExistDef(vs[j]))) ) )
			result[len_result-1]=',';
	}*/
   }
   r=1;
   (now->neg).p_rec+=prec/(double)(nN);
  }

/*   for(j=1;j<nN;j++)
   {

    if(result[r]!='?')
    {
	  if(result[r]!=' ')
	  {
       if(result[r]=='|')
		   result[r]='I';
	   if(Language==7)
	   {
		   if( ((result[r-1]==256+'ь')||(result[r-1]==256+'№'))&&((result[r]=='I' )||(result[r]=='i')||(result[r]=='1')||(result[r]=='l')) )
		   {
			   if(result[r-1]==256+'ь')
				   result[r-1]=256+'ы';
			   else
				   result[r-1]=256+'џ';
			   NegMoveResult(result,len_result,r);
			   r--;
		   }
		   if( (result[r-1]!=' ')&&(result[r-1]!='?')&&(!(IfGl(result[r-1])))&&(result[r]==256+'ƒ') )
		   {
		    if(IfExistA(vs[j]))
			{
			 if(j<nN-1)
			 {
				if(!(IfGl(result[r+1])))
				result[r]=256+'ј';
			 }
			 else
				 result[r]=256+'ј';
			}
		   }
       }

	    if( (pN[j].right-pN[j].left+1>pN[j].bottom-pN[j].top+1) && (result[r]=='I') )
		   result[r]='-';
        r++;

	  }
      else
	  {
		  j--;
		  r++;
	  }
    }
    else
	   r++;
   }
*/
//Andrey
  (now->neg).Flags = 0;
  if (vertical)
  {
	if(dpPrintResConsole)
    {
      LDPUMA_Console("\n down-up print:");
      NegPrintConsol((double)prob0[0]/nN);
      LDPUMA_Console("down-up handprint:");
      NegPrintConsol((double)prob1[0]/nN);
      LDPUMA_Console("up-down print:");
      NegPrintConsol((double)prob0[1]/nN);
      LDPUMA_Console("up-down handprint:");
      NegPrintConsol((double)prob1[1]/nN);
    }
      double down_up = (prob0[0]+prob1[0])/2;
      double up_down = (prob0[1]+prob1[1])/2;
      (now->neg).Flags |= FlVert;
      if (down_up > up_down) (now->neg).Flags |= FlDown2Up;
  }

  if(i==(now->neg).nRc-1)
   {
	if(dpPrintResConsole)
	  NegPrintConsol(pRc[0].left,pRc[(now->neg).nRc-1].top,pRc[0].right,pRc[0].bottom);
   }

   if(dpPrintResConsole)
    NegPrintConsol(result,len_result);

   if(i==0)
   {
	(now->neg).p_rec/=(double)((now->neg).nRc);
	(now->neg).p_str/=(double)((now->neg).nRc);
	(now->neg).p=((now->neg).p_rec+(now->neg).p_str)/2.;
    if(dpPrintResConsole)
	{
	  LDPUMA_ConsoleN("");
	  LDPUMA_Console("Ќегатив с веро¤тностью :");
	  LDPUMA_ConsoleN("");
	  LDPUMA_Console("по внутренней структуре ");
	  NegPrintConsol((now->neg).p_str);
	  LDPUMA_Console("по результатам распозновани¤ ");
	  NegPrintConsol((now->neg).p_rec);
	  LDPUMA_Console("итого ");
      NegPrintConsol((now->neg).p);
      LDPUMA_ConsoleN("площадь=%d",(int)((now->neg).pRc[0].right-(now->neg).pRc[0].left+1)*(int)((now->neg).pRc[0].bottom-(now->neg).pRc[(now->neg).nRc-1].top+1));
	}
   }

   if(i==0)
   {
    if(dpNegResD)
    {
        Rect16 Rect;
        Rect.bottom=(now->neg).pRc[0].bottom;
		Rect.left=(now->neg).pRc[0].left;
		Rect.right=(now->neg).pRc[0].right+1;
		Rect.top=(now->neg).pRc[(now->neg).nRc-1].top-1;
		LDPUMA_DrawRect (MainWindowD, &(Rect),0,RGB(0,0,255), 1,code_resd );
        LDPUMA_WaitUserInput (NegResD,MainWindowD);
        LDPUMA_DeleteRects (MainWindowD,code_resd);
    }
   }

   DelNegMas(vs);
   DelNegMas(uvs);
   delete[] result;
   DelNegMas(&pN);
  }
//  if((now->neg).rot.pmasp)
//   DeleteRotateMas(&((now->neg).rot.pmasp),&((now->neg).rot.begx),&((now->neg).rot.movey),&((now->neg).rot.flmovey),&((now->neg).rot.hi));
  if(!(now->neg).nRc)
  {
	  temp=now;
	  if(!temp->prev)
		  root=temp->next;
       now=now->prev;
	   delete temp;
	   nRC--;
  }
  else
   now=now->prev;
 }

 (*proot)=root;

}