Beispiel #1
0
Handle GetNegCCOM(Handle hCPage,Rect16* pRc,int i)
{
 int min_h,min_w,max_h,max_w;
 ExcControl Control;
 int j;
 uchar Name[CPAGE_MAXNAME];
 for (j=0; j<CPAGE_MAXNAME; j++)
		Name[j] = ImageName[j];
 Handle lpDIB;
 if(!CIMAGE_ReadDIB(Name,&lpDIB,1))
	 return 0;
 if( pRc[i].bottom-pRc[i].top > pRc[i].right-pRc[i].left )
 {
	  min_h=min_let_w;
	  min_w=min_let_h;
	  max_w=pRc[i].right-pRc[i].left+1;
	  max_h=max_w*2;

 }
 else
 {
      min_h=min_let_h;
	  min_w=min_let_w;
	  max_h=pRc[i].bottom-pRc[i].top+1;
	  max_w=max_h*2;
 }
 Control.MinCompHei=min_h;
 Control.MinCompWid=min_w;
 Control.MaxCompHei=max_h;
 Control.MaxCompWid=max_w;
 Control.MaxScale=1;
 Control.Control=Ex_ExtraComp|Ex_DisableCut|Ex_Invert;

 if(REXCExtraDIB(Control,(uchar*)(lpDIB),pRc[i].left,pRc[i].top,pRc[i].right-pRc[i].left+1,pRc[i].bottom-pRc[i].top+1))
    return REXCGetContainer();
 return 0;
/*
 uchar* pmasp;
 if(!GetMasP(&(pRc[i]),&pmasp))
	 return 0;

 if( pRc[i].bottom-pRc[i].top > pRc[i].right-pRc[i].left )
 {
	  min_h=min_let_w;
	  min_w=min_let_h;
	  max_w=pRc[i].right-pRc[i].left+1;
	  max_h=max_w*2;

 }
 else
 {
      min_h=min_let_h;
	  min_w=min_let_w;
	  max_h=pRc[i].bottom-pRc[i].top+1;
	  max_w=max_h*2;
 }

 int bytewide=(pRc[i].right-pRc[i].left+8)/8;
 Bool fotomet=FALSE;
 Bool RevOv=TRUE;

 Control.MinCompHei=min_h;
 Control.MinCompWid=min_w;
 Control.MaxCompHei=max_h+1;
 Control.MaxCompWid=bytewide*8;
 Control.MaxScale=0;
 Control.Control=Ex_ExtraComp|Ex_EvnRecog;


 if(REXCExtra(Control,pmasp,bytewide,RevOv,bytewide*8,pRc[i].bottom-pRc[i].top+1,(DPIX*10000)/254,(DPIY*10000)/254,0,0,0,0,fotomet))
    return REXCGetContainer();
 return 0;
 */
}
//////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Выделение компонент
Bool32  ExtractComponents( Bool32 bIsRotate, Handle * prev_ccom, puchar name, PRSPreProcessImage Image)
{
	Bool32 rc = TRUE;
	ExcControl      exc = {0};
//	RSGETMODULEPATH  pGetModulePath;
//	RSSETUPDATE      pSetUpdate;
//
//	if ( ProgressPoints.pGetModulePath && ProgressPoints.pSetUpdate)
//	{
//		pGetModulePath = (RSGETMODULEPATH)ProgressPoints.pGetModulePath;
//		pSetUpdate     = (RSSETUPDATE)ProgressPoints.pSetUpdate;
//	}
//	else
//	{
//		return false;
//	}

    if(prev_ccom)
    {
        *prev_ccom = *Image->phCCOM ? *Image->phCCOM: NULL;
        *Image->phCCOM=NULL;
    }
    else
    {
        CCOM_DeleteContainer((CCOM_handle)*Image->phCCOM);
        *Image->phCCOM=NULL;
    }

	if(!REXC_SetImportData(REXC_ProgressStep, (void*)rexcProgressStep))
	{
		SetReturnCode_rstuff(REXC_GetReturnCode());
		return FALSE;
	}

	// будет распознавания эвентами
	//Andrey: опознавалка вынесена в отдельный модуль RRecCom
	exc.Control  = Ex_ExtraComp|/*Ex_EvnRecog|*/Ex_Picture;
    //exc.Control |= Ex_NetRecog;

	//Andrey: orientation is obtained from new library RNORM
    //exc.Control |= ( bIsRotate ? Ex_Orient : 0 );

//Andrey: without flag Ex_PictureLarge big comps aren't extracted which may cause loss of big negatives
//    if( Image->gnPictures )
        exc.Control |= Ex_PictureLarge;
/*//Andrey: опознавалка вынесена в отдельный модуль RRecCom
	if(rc && !REXC_SetEVNProperties(exc, GetModulePath(),(uchar)Image->gnLanguage) )
	{ // инициализировать распознавание по эвентам и задать алфавит
		SetReturnCode_rstuff(REXC_GetReturnCode());
		rc = FALSE;
	}
	else
*/	{
		uchar w8 = (uchar)Image->gbDotMatrix;
			REXC_SetImportData(REXC_Word8_Matrix,&w8);

		w8 = (uchar)Image->gbFax100;
			REXC_SetImportData(REXC_Word8_Fax1x2,&w8);
	}

//exc.Control ^= Ex_EvnRecog;
/*
	if(rc && !REXCExtraDIB( exc, lpdata,0,0,0,0) ) // поиск компонент в DIB-e
*/
    CIMAGEIMAGECALLBACK clbk;
    if(rc && !CIMAGE_GetCallbackImage(name, &clbk))
    {
		SetReturnCode_rstuff(CIMAGE_GetReturnCode());
        rc = FALSE;
    }
    if( rc && !REXCExtracomp3CB(exc, // поиск компонент by 3CallBacks
        (TImageOpen)clbk.CIMAGE_ImageOpen,
        (TImageClose)clbk.CIMAGE_ImageClose,
        (TImageRead)clbk.CIMAGE_ImageRead)
        )
		{
		SetReturnCode_rstuff(REXC_GetReturnCode());
		rc = FALSE;
		}

	if(rc)
	{
		*Image->phCCOM = (Handle)REXCGetContainer();
		if(*Image->phCCOM==0)
		{
			SetReturnCode_rstuff(REXC_GetReturnCode());
			rc = FALSE;
		}

		RRecComControl rec_control;
		memset(&rec_control, 0, sizeof(RRecComControl));
		rec_control.flags = RECOG_EVN;

		if (!RRECCOM_Recog(*(Image->phCCOM), rec_control, GetModulePath(), (uchar)Image->gnLanguage))
		{
			SetReturnCode_rstuff(RRECCOM_GetReturnCode());
			rc = FALSE;
		}
	}
	if(rc)
		SetUpdate(FLG_UPDATE_NO,FLG_UPDATE_CCOM);
	return rc ;
}
Bool32 RemoveLines(PRSPreProcessImage Image, puchar * lppDIB)
{
	Handle hccom = *Image->phCCOM;
	Handle hcpage = Image->hCPAGE;
	Handle *hLinesCCOM = Image->phLinesCCOM;

	puchar hDIB = NULL;
	Bool32 rc = TRUE;
    *hLinesCCOM = NULL;
    CCOM_comp   *victim[100];
    int32_t       nvict,i;
    Bool32      yes_victim = FALSE;
	//
	// Удалим линии
	//
	if(!LDPUMA_Skip(ObvKillLines)||(LDPUMA_Skip(hNewLine)&&LDPUMA_Skip(Image->hDebugCancelVerifyLines)))
		rc=DeleteLines(hcpage,Image->phCLINE,PUMA_IMAGE_DELLINE);
	else
	{
	 if(rc && !RLINE_DeleteLines(hcpage,PUMA_IMAGE_DELLINE))
	 {
		SetReturnCode_rstuff(RLINE_GetReturnCode());
		rc = FALSE;
	 }
     if (rc && LDPUMA_Skip(NotKillPointed) && LDPUMA_Skip(Image->hDebugCancelSearchDotLines))
         rc = DeleteDotLines(Image->phCLINE, PUMA_IMAGE_DELLINE);
	}

	LDPUMA_Skip(hPrep2);
	//
	// Получим изображение с удаленными линиями
	//
	if(rc && !CIMAGE_ReadDIB((puchar)PUMA_IMAGE_DELLINE,(Handle*)&hDIB,TRUE))
	{
		SetReturnCode_rstuff(CIMAGE_GetReturnCode());
		rc = FALSE;
	}
	if(hDIB)
	{
		//
		// Удалим компоненты и выделим их заново.
		//
		*lppDIB = (puchar)hDIB;
		if(rc)
		{
		//if( CCOM_GetContainerVolume((CCOM_handle)*Image->phCCOM)>30000 )
		//	CCOM_CompressContatiner((CCOM_handle)*Image->phCCOM);
        if( CCOM_GetContainerVolume((CCOM_handle)*Image->phCCOM)<60000 &&
            MyGetZher ((void**)victim, &nvict, 100, hcpage) && nvict )
            yes_victim = TRUE;

        if( !yes_victim )
            {
            CCOM_DeleteContainer((CCOM_handle)*Image->phCCOM);
            *Image->phCCOM = 0;
            }

		if(!ExtractComponents(FALSE, hLinesCCOM, (puchar)PUMA_IMAGE_DELLINE, Image))
		{
				rc = FALSE;
		}
        else
        {
            PAGEINFO inf = {0};
            GetPageInfo(Image->hCPAGE,&inf);
            strcpy((char*)inf.szImageName,PUMA_IMAGE_DELLINE);
			inf.Images|=IMAGE_DELLINE;
            SetPageInfo(Image->hCPAGE,inf);
        }

		if(rc)
		{

			*Image->phCCOM = (Handle)REXCGetContainer();
			if(*Image->phCCOM == 0)
			{
				SetReturnCode_rstuff(REXC_GetReturnCode());
				rc = FALSE;
			}
			hccom = *Image->phCCOM;
            if( *hLinesCCOM )
                {
                //
                // Refersh CCOM
                //
                CCOM_comp   *exa=CCOM_GetFirst((CCOM_handle)*hLinesCCOM,NULL);

                if( yes_victim )
                {
                /*
                Rect16 rect1;
	            uint32_t key = 111;
                for(i=0;i<nvict;i++)
                    {
                    exa = victim[i];
                    rect1.top = exa->upper;
		            rect1.left = exa->left;
		            rect1.bottom = exa->upper+exa->h;
		            rect1.right = exa->left+exa->w;
		            LDPUMA_DrawRect(NULL, &rect1, 0, 23635, 1, key);
                    }

                if(!LDPUMA_Skip(hShowCheckLetters))
	                {
		                LDPUMA_Console("Puma_Коробки жертв  \n");
		                LDPUMA_WaitUserInput(NULL, NULL);
		                LDPUMA_DeleteRects(NULL, key);
	                }
                    */
                for(i=0;i<nvict;i++)
                    {
                    exa = victim[i];
                    if( remove_overlayed(exa,(CCOM_handle)*Image->phCCOM) )
                        {
                        CCOM_comp   *dup=CCOM_New((CCOM_handle)*Image->phCCOM,exa->upper,exa->left,exa->w,exa->h);
                        if( dup )
                            {
                            CCOM_Store(dup,0,
                                exa->size_linerep,
                                exa->linerep,  exa->nl,
                                exa->begs, exa->ends,
                                exa->vers,   NULL);
                            dup->scale= exa->scale;
                            dup->type = exa->type;
                            dup->cs   = exa->cs;
                            }
                        }
                    }
                }
                CCOM_DeleteContainer((CCOM_handle)*hLinesCCOM);
                }
			}
			else
				LDPUMA_Console("Пропущен этап выделения компонент после удаления линий.\n");
		}
	}
return rc;
}
Beispiel #4
0
CCOM_handle GetStrCCOM(Handle hCPage, uchar* ImageName, Rect16 Rc, Bool neg, Bool vertical,
        RecRaster* rast, int min_h) {
    int min_w, max_h, max_w;
    // int j;
    PAGEINFO info;
    // uchar Name[CPAGE_MAXNAME];
    GetPageInfo(hCPage, &info);

    // if(ImageName)
    // {
    //	 for (j=0; j<CPAGE_MAXNAME; j++)
    //		Name[j] = ImageName[j];
    // }
    // else
    // {
    // for (j=0; j<CPAGE_MAXNAME; j++)
    //		Name[j] = info.szImageName[j];
    // }
    // Handle lpDIB;
    // if(!CIMAGE_ReadDIB(Name,&lpDIB,1))
    //	 return 0;
    ExcControl Control;
    if (vertical) {
        min_h = 2;
        min_w = 2;
        max_w = Rc.right - Rc.left + 1;
        max_h = max_w * 2;

    } else {
        min_w = 2;
        max_h = Rc.bottom - Rc.top + 1;
        max_w = Rc.right - Rc.left + 1;
    }

    int bytewide = ((rast->lnPixWidth + 63) / 64) * 8;
    Bool fotomet = FALSE;
    Bool RevOv = FALSE;

    Control.MinCompHei = min_h;
    Control.MinCompWid = min_w;
    Control.MaxCompHei = rast->lnPixHeight + 1;
    Control.MaxCompWid = bytewide * 8;
    Control.MaxScale = 0;
    Control.Control = Ex_ExtraComp/*|Ex_EvnRecog*/;//Andrey: опознавалка вынесена в отдельный модуль RRecCom, и кроме того, не вызвана функция REXC_SetEVNProperties для опознавания методом "Event"

    if (REXCExtra(Control, rast->Raster, bytewide, RevOv, bytewide * 8, rast->lnPixHeight,
            (info.DPIX * 10000) / 254, (info.DPIY * 10000) / 254, 0, 0, 0, 0, fotomet)) {
        /* 	 //Andrey: здесь как раз и идет опознавалка
         RRecComControl rcontrol;
         rcontrol.MinCompHei=min_h;
         rcontrol.MinCompWid=min_w;
         rcontrol.MaxCompHei=rast->lnPixHeight+1;
         rcontrol.MaxCompWid=bytewide*8;
         rcontrol.MaxScale=0;
         rcontrol.flags = RECOG_EVN;

         Handle hCCOM = (Handle)REXCGetContainer();

         if (hCCOM)
         //Andrey: вообще-то так делать нельзя (в смысле передавать последними 2мя параметрами то, что передается), но пока я не знаю, как здесь получить язык распознавания, поэтому вот таким образом пропускается инициализация
         if (!RRECCOM_Recog(hCCOM, rcontrol, NULL, -1))
         LDPUMA_ConsoleN(RRECCOM_GetReturnString(RRECCOM_GetReturnCode()));

         return (int32_t)hCCOM;
         */return REXCGetContainer();
    }
    return 0;
}