void PageMarker::linePass3() { if (LDPUMA_Skip(hDebugLinePass3) && LDPUMA_Skip(hDebugVerifLine) && LDPUMA_Skip(hDebugLinePass2)) RLINE_LinesPass3(image_data_->hCPAGE, image_data_->hCLINE, image_data_->hCCOM, (uchar) image_data_->gnLanguage); }
Bool32 Close_Res_Log( void ) { if (logFile_comp!=NULL) { LDPUMA_FClose(logFile_comp ); logFile_comp=NULL; } if (resFile_comp!=NULL) { LDPUMA_FClose(resFile_comp ); resFile_comp=NULL; } if (logFile_pict!=NULL) { LDPUMA_FClose(logFile_pict ); logFile_pict=NULL; } if (resFile_pict!=NULL) { LDPUMA_FClose(resFile_pict ); resFile_pict=NULL; } if (logFile_blocks!=NULL) { LDPUMA_FClose(logFile_blocks ); logFile_blocks=NULL; } if (resFile_blocks!=NULL) { LDPUMA_FClose(resFile_blocks ); resFile_blocks=NULL; } if(f_cut_str) fclose(f_cut_str); if(!LDPUMA_Skip(DifferenCutToHistory)) { if(f_temp_cut) fclose(f_temp_cut); if(f_old_cut) fclose(f_old_cut); } if(f_cut_comp) fclose(f_cut_comp); if(!LDPUMA_Skip(DifferenCutToHistory)) { if(f_temp_cut_comp) fclose(f_temp_cut_comp); if(f_old_cut_comp) fclose(f_old_cut_comp); } return TRUE; }
Bool32 SearchLines ( PRSPreProcessImage Image ) { Bool32 rc = TRUE; if(LDPUMA_Skip(Image->hDebugCancelSearchLines)) { Bool32 b32 = !Image->gbDotMatrix; RLINE_SetImportData(RLINE_Bool32_NOFILLGAP3,&b32); b32 = TRUE; RLINE_SetImportData(RLINE_Bool32_NOHBORDER,&b32); RLINE_SetImportData(RLINE_Bool32_NOVBORDER,&b32); if(!RLINE_SearchLines(Image->hCPAGE,Image->phCLINE)) { //SetReturnCode_rstuff(RLINE_GetReturnCode()); //rc = FALSE; *Image->pgrc_line = FALSE; LDPUMA_Console("ПРЕДУПРЕЖДЕНИЕ: RLINE(0x%X) %s\n",RLINE_GetReturnCode(),RLINE_GetReturnString(RLINE_GetReturnCode())); } } else LDPUMA_Console("Пропущен этап поиска линий.\n"); return rc; }
///////////////////////////////////////////////////////////////////////////////////////////////////// // удаляем линии Bool32 KillLines(PRSPreProcessImage Image) { Bool32 rc = TRUE; if(!ProgressStepLines(1/*,GetResourceString(IDS_REMOVELINE)*/,30)) rc = FALSE; if( rc && *Image->pgrc_line && *Image->pgneed_clean_line) { if(LDPUMA_Skip(Image->hDebugCancelRemoveLines) ) { puchar pDIB = NULL; PRGTIME prev = StorePRGTIME(30, 40); rc = RemoveLines(Image, &pDIB); if(rc) { *Image->pgpRecogDIB = pDIB; LDPUMA_CreateWindow(NAME_IMAGE_DELLINE,*Image->pgpRecogDIB); } RestorePRGTIME(prev); } else LDPUMA_Console("Пропущен этап снятия линий.\n"); } return rc; }
Handle LDPUMA_FOpen(const char * lpName,const char * lpMode) { Handle hFile = NULL; if(fFOpen && !LDPUMA_Skip(hWriteFile)) hFile = fFOpen(lpName,lpMode); return hFile; }
Bool32 SearchNewLines( PRSPreProcessImage Image ) { Bool32 ret = TRUE; bool searchlines = LDPUMA_Skip(Image->hDebugCancelSearchDotLines) && !LDPUMA_Skip(hDotLine); Handle hSaveImage = CPAGE_CreateBlock(Image->hCPAGE, RSL_VERLINE, 0, 0, Image, sizeof (RSPreProcessImage)); if(LDPUMA_Skip(Image->hDebugCancelVerifyLines)) { ret=RLINE_LinesPass1(Image->hCPAGE,*(Image->phCCOM),Image->phCLINE,Image->pgneed_clean_line, searchlines, (uchar)Image->gnLanguage); if (ret && !gbRSLT) ret = RLINE_LinesPass2(*(Image->phCCOM),Image->phCLINE, Image->hCPAGE); } CPAGE_DeleteBlock(Image->hCPAGE, hSaveImage); return ret; }
void PageMatrixBuild(void) { PageMatrixInit(3000, 3000);//DDD PageMatrixPutRoots(); # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 4) if (!LDPUMA_Skip(hPageMatrix)) LT_GraphicsPageMatrixOutput ("After put roots"); # endif PageMatrixHorzGlue(); # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 4) if (!LDPUMA_Skip(hPageMatrix)) LT_GraphicsPageMatrixOutput ("After horz glue"); # endif PageMatrixVertGlue(); # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 4) if (!LDPUMA_Skip(hPageMatrix)) LT_GraphicsPageMatrixOutput ("After vert glue"); # endif PageMatrixExcludeIntersections(); # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 4) if (!LDPUMA_Skip(hPageMatrix)) LT_GraphicsPageMatrixOutput ("After excluding intersections"); # endif PageMatrixPutSeparators(FALSE); //Bool bConvertToRealCoords:=FALSE # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 4) if (!LDPUMA_Skip(hPageMatrix)) LT_GraphicsPageMatrixOutput ("After put separators"); # endif }
Bool32 VerifyLines ( PRSPreProcessImage Image ) { Bool32 rc = TRUE; #ifdef _USE_RVERLINE_ if( *Image->pgrc_line ) { if(LDPUMA_Skip(Image->hDebugCancelVerifyLines)) { Regime_VerifyLines val = Image->gnTables ? RVL_FutuTablCorr:RVL_Default; if( !RVERLINE_SetImportData(RVERLINE_DTRVERLINE_RegimeOfVerifyLines,&val)|| !RVERLINE_MarkLines(*Image->phCCOM, Image->hCPAGE)) { SetReturnCode_rstuff(RVERLINE_GetReturnCode()); rc = FALSE; } else { Bool32 BadScan = FALSE; int32_t ScanQual= 0; // RVERLINE_AboutLines(Image->hCPAGE,*Image->phCCOM, Image->pgneed_clean_line, &BadScan, &ScanQual); } AboutLines(Image, &BadScan, &ScanQual); } if(!*Image->pgneed_clean_line) LDPUMA_Console("Предупреждение: RSTUFF говорит, что снимать линии не надо.\n"); } else LDPUMA_Console("Пропущен этап оценки линий.\n"); //// if(LDPUMA_Skip(hDebugCancelVerifyLines)) //// { //// Regime_VerifyLines val = gnTables ? RVL_FutuTablCorr:RVL_Default; //// //// if( !RLTABLE_SetImportData(RLTABLE_DTRLTABLE_RegimeOfVerifyLines,&val)|| //// !RLTABLE_MarkLines(hCCOM, hCPAGE)) //// { //// SetReturnCode_rstuff(RLTABLE_GetReturnCode()); //// rc = FALSE; //// } //// else //// { //// Bool32 BadScan = FALSE; //// int32_t ScanQual= 0; //// RLTABLE_AboutLines(hCPAGE,hCCOM, &gneed_clean_line, &BadScan, &ScanQual); } //// if(!gneed_clean_line) //// LDPUMA_Console("Предупреждение: RLTABLE_AboutLines говорит, что снимать линии не надо.\n"); //// } //// else //// LDPUMA_Console("Пропущен этап оценки линий.\n"); } #endif //_USE_RVERLINE_ return rc; }
RSL_FUNC(Bool32) RSL_SetImportData(uint32_t dwType, void * pData) { Bool32 rc = RESULT; if (dwType != RSL_HANDLE) return FALSE; Handle* phCPage = (Handle*) pData; RSPreProcessImage IImage; PRSPreProcessImage Image = &IImage; uint32_t nTeor = sizeof (RSPreProcessImage); Handle hPage = CPAGE_GetHandlePage(CPAGE_GetCurrentPage()); Handle VerifyN = CPAGE_GetBlockFirst (*phCPage, RSL_VERLINE);//hPage, RSL_VERLINE); uint32_t nReal = CPAGE_GetBlockData (*phCPage, VerifyN, RSL_VERLINE, Image, nTeor); // uint32_t err32 = CPAGE_GetReturnCode (); // if (err32) // return FALSE; if( *Image->pgrc_line ) { if(LDPUMA_Skip(Image->hDebugCancelVerifyLines)) { Regime_VerifyLines val = Image->gnTables ? RVL_FutuTablCorr:RVL_Default; if( !RVERLINE_SetImportData(RVERLINE_DTRVERLINE_RegimeOfVerifyLines,&val)|| !RVERLINE_MarkLines(*Image->phCCOM, Image->hCPAGE)) { SetReturnCode_rshelllines((uint16_t)RVERLINE_GetReturnCode()); rc = FALSE; } else { Bool32 BadScan = FALSE; int32_t ScanQual= 0; AboutLines(Image, &BadScan, &ScanQual); } if(!*Image->pgneed_clean_line) LDPUMA_Console("Warning: RSL said that the lines don't need to be erased from the picture.\n"); } else LDPUMA_Console("Missing stage of the evaluation lines.\n"); } //CPAGE_DeleteBlock(&phCPage, VerifyN); return rc; }
Bool32 ModulesDone(Handle ghStorage) { Bool32 rc = TRUE; ROUT_Done(); CED_Done(); //#ifdef _DEBUG if( !LDPUMA_Skip(hDebugEnableSaveJtl) ) { My_SJTL_close(); } //#endif My_SJTL_Done(); RCORRKEGL_Done(); RPIC_Done(); RIMAGE_Done(); RFRMT_Done(); RSL_Done(); REXC_Done(); RLINE_Done(); RMARKER_Done(); RBLOCK_Done(); RSELSTR_Done(); RSTR_Done(); CSTR_Done(); CCOM_Done(); CPAGE_Done(); CIMAGE_Done(); CLINE_Done(); RPSTR_Done(); RSTUFF_Done(); RRECCOM_Done(); #ifdef _USE_RVERLINE_ RVERLINE_Done(); #endif //_USE_RVERLINE_ #ifdef _USE_RMSEGMENT_ RMSEGMENT_Done(); #endif //_USE_RMSEGMENT_ /* if(ghStorage) CloseStorage(ghStorage,CS_ALL); */ CFIO_Done(); return rc; }
// если пылевых блоков столько же, сколько основных -- // то считается "высота среднего блока". // иначе считается величина, смысл которой туманен. // могу только сказать, что в определении нет непрерывности // при nDust->nRoots (ибо среднее стремится к нулю). void BlockSetAverageHeight (BLOCK *p) { if(!LDPUMA_Skip(hSetTrivAverHeight)) { // вычисление средних по стандарной формуле if (p -> nRoots == 0) p -> nAverageHeight = 1; else p -> nAverageHeight = MAX (p -> nHeightesSum / p -> nRoots, 1); // хотя.. если считать, что пыль образована из осколков // букв, то среднее разумно чуть увеличить.. только вот -- // -- почему пропорционально nRoots/(nRoots-nDust) ? } else // старый вариант по умолчанию: { if (p -> nRoots - p -> nDust == 0) { if (p -> nRoots == 0) p -> nAverageHeight = 1; else p -> nAverageHeight = MAX (p -> nHeightesSum / p -> nRoots, 1); } else { // меня смущает, что при превышении числом пылинок // числа основных блоков среднее будет отрицательно. p -> nAverageHeight = MAX (p -> nHeightesSum / (p -> nRoots - p -> nDust), 1); // то есть добавляя пылинку (точку), я почему-то // увеличиваю среднюю высоту. я (GF) отказываюсь это понимать. // хотя.. если считать, что пыль образована из осколков // букв, то среднее разумно чуть увеличить.. только вот -- // -- почему пропорционально nRoots/(nRoots-nDust) ? } } }
Bool TrySpecialHorizontalCutting (BLOCK *p) /* Debugging not completed */ { int nBlockWidth = p -> Rect.xRight - p -> Rect.xLeft + 1; int nBlockHeight = p -> Rect.yBottom - p -> Rect.yTop + 1; ROOT *pRoot; int iLeftColumn, iRightColumn; int yTop, yBottom; int i; int nMaximum; int iLeftMaximum; int iRightMaximum; int iMinBreakingPoint; # ifdef LT_DEBUG if (p -> pHorzHystogram == NULL) ErrorInternal ("pHorzHystogram not builded in TrySpecialHorizontalCutting"); # endif if (p -> nAverageHeight == 0) return (FALSE); if (p -> nActualHeight / p -> nAverageHeight < 10 || nBlockWidth / p -> nAverageHeight < 30) { return (FALSE); } /* * Hystogram building */ nHystColumns = nBlockWidth + 1; for (i = 0; i < nHystColumns; i++) { pHystogram [i] = 0; pHystTops [i] = nBlockHeight; pHystBottoms [i] = -1; } for (pRoot = p -> pRoots; pRoot != NULL; pRoot = pRoot -> u1.pNext) { iLeftColumn = pRoot -> xColumn - p -> Rect.xLeft; iRightColumn = iLeftColumn + pRoot -> nWidth - 1; yTop = pRoot -> yRow - p -> Rect.yTop; yBottom = yTop + pRoot -> nHeight - 1; for (i = iLeftColumn; i <= iRightColumn; i++) { pHystogram [i]++; if (yTop < pHystTops [i]) pHystTops [i] = yTop; if (yBottom > pHystBottoms [i]) pHystBottoms [i] = yBottom; } } /* * Finding maximums in hystogram */ nMaximum = 0; for (i = 0; i < nHystColumns; i++) { if (pHystogram [i] > nMaximum) nMaximum = pHystogram [i]; } for (i = 0; i < nHystColumns && pHystogram [i] < nMaximum * 3 / 4; i++) ; if (i == nHystColumns) ErrorInternal ("i == nHystColumns in TrySpecialHorizontalCutting"); iLeftMaximum = i; for (i = nHystColumns - 1; i >= 0 && pHystogram [i] < nMaximum * 3 / 4; i--) ; if (i == -1) ErrorInternal ("i == -1 in TrySpecialHorizontalCutting"); iRightMaximum = i; # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 1) if(!LDPUMA_Skip(hBlocksBreaking)) { pDebugBlock = p; LT_GraphicsSpecialCuttingOutput ("Special cutting condition"); } # endif /* * Finding minimum break point */ iMinBreakingPoint = -1; for (i = iLeftMaximum + 1; i < iRightMaximum; i++) { if (pHystogram [i] > nMaximum / 6) continue; if (pHystTops [i] == -1) continue; if (pHystTops [i] < nBlockHeight * 5 / 6) continue; if (p -> pHorzHystogram [pHystTops [i] - 1] != 0) continue; if (iMinBreakingPoint == -1 || pHystTops [i] > pHystTops [iMinBreakingPoint]) { iMinBreakingPoint = i; } } if (iMinBreakingPoint == -1) return (FALSE); return (BlockBreakOnHorizontal ( p, NULL, NULL, pHystTops [iMinBreakingPoint] - 1 + p -> Rect.yTop )); }
void BlocksBreak (void) { BLOCK *p; int i; int nRootsInNotBreakedBlocks; if (!HystogramAllocateBody ()) return; nRootsInNotBreakedBlocks = 0; AGAIN: # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 4) if(!LDPUMA_Skip(hBlocksBreaking)) LT_GraphicsBlocksOutput ("Blocks while breaking: again"); # endif for (p = pBlocksList; p != NULL; p = p -> pNext) { if (p -> uFlags & BF_NOT_BREAK_BLOCK) continue; for (i = 0; i < nSeps; i++) { switch (pSeps [i].Type) { default: break; case SEP_VERT: //if (TryCutBlockByVerticalSeparator (p, i)) goto AGAIN; if (TryCutBlockByVerticalSeparator (p, i, TRUE)) goto AGAIN; break; case SEP_HORZ: if (TryCutBlockByHorizontalSeparator (p, i)) goto AGAIN; break; case SEP_RECT: if (TryCutBlockByRectangleSeparator (p, i)) goto AGAIN; break; } } //if (TryCutBlockOnVertical (p,0)) goto AGAIN; if (TryCutBlockOnVertical (p,0, FALSE)) goto AGAIN; if (bOptionSpecialHorizontalCutting && TrySpecialHorizontalCutting (p)) goto AGAIN; if (TryCutBlockOnHorizontal (p)) goto AGAIN; if (bOptionSmartBreaking && TrySmartBreaking (p)) goto AGAIN; if ( bOptionBusinessCardsLayout && TryCutBlockOnVertical (p,1, FALSE)) goto AGAIN; // Rom //Handle hNotWholeLine = NULL; //Handle hHystogramNull = NULL; if(LDPUMA_Skip(hNotWholeLine)) { for (i = 0; i < nSeps; i++) { switch (pSeps [i].Type) { default: break; case SEP_VERT: if (TryCutBlockByVerticalSeparator (p, i, FALSE)) goto AGAIN; break; /* case SEP_HORZ: if (TryCutBlockByHorizontalSeparator (p, i)) goto AGAIN; break; */ } } } /* Rom */ if(LDPUMA_Skip(hHystogramNull)) { if (TryCutBlockOnVertical (p,0, TRUE)) goto AGAIN; } p -> uFlags |= BF_NOT_BREAK_BLOCK; nRootsInNotBreakedBlocks += p -> nRoots; progress_set_percent (nRootsInNotBreakedBlocks * 100 / nRoots); # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 4) if(!LDPUMA_Skip(hBlocksBreaking)) LT_GraphicsBlocksOutput ("Blocks while breaking: set not break"); # endif } if (bOptionWhiteStripsBreaking) WhiteStripsBreaking (); HystogramFreeData (); }
Bool32 CheckAreaForComps(CCOM_handle hCCOM, CCOM_handle hCCOM_big, Rect32 rect, int32_t Height, uint32_t *Result1, uint32_t *Result2) { CCOM_comp * comp; uint32_t i; comp = NULL; Rect16 rect1; uint32_t key = 111; uint32_t color = 23000; Handle MainWindowD = NULL; MainWindowD = LDPUMA_GetWindowHandle("Изображение после разворота"); if (!MainWindowD) MainWindowD = LDPUMA_GetWindowHandle("Main"); *Result1 = 0; *Result2 = 0; if (!LDPUMA_Skip(hShowCheckLetters)) { rect1.top = (uint16_t) rect.top; rect1.left = (uint16_t) rect.left; rect1.bottom = (uint16_t) rect.bottom; rect1.right = (uint16_t) rect.right; LDPUMA_DrawRect(MainWindowD, &rect1, 0, 23635, 4, key); } //stepa_am comp = CCOM_GetFirst(hCCOM_big, NULL); while (comp) { if (comp->h < Height / 6) goto lNextComp_big; if (comp->h > Height * 1.5) goto lNextComp_big; if (comp->upper < rect.top) goto lNextComp_big; if (comp->left < rect.left) goto lNextComp_big; if (comp->upper + comp->h > rect.bottom) goto lNextComp_big; if (comp->left + comp->w > rect.right) goto lNextComp_big; if ((comp->h < Height / 3) && (comp->upper < rect.top)) goto lNextComp_big; for (i = 0; i < nPics; i++) { if ((comp->upper >= pPics[i].upper) && (comp->left >= pPics[i].left) && (comp->upper + comp->h < pPics[i].upper + pPics[i].h) && (comp->left + comp->w <= pPics[i].left + pPics[i].w)) { goto lNextComp_big; } } if ((comp->h > Height * 0.5) && (comp->h < Height * 1.5)) { (*Result1)++; if (!LDPUMA_Skip(hShowCheckLetters)) { rect1.left = comp->left; rect1.top = comp->upper; rect1.right = comp->left + comp->w; rect1.bottom = comp->upper + comp->h; LDPUMA_DrawRect(MainWindowD, &rect1, 0, color, 8, key); } goto lNextComp_big; } if ((comp->h > Height / 3 * 0.5) && (comp->h < Height / 3* 1.5 )) { (*Result2)++; if (!LDPUMA_Skip(hShowCheckLetters)) { rect1.left = comp->left; rect1.top = comp->upper; rect1.right = comp->left + comp->w; rect1.bottom = comp->upper + comp->h; LDPUMA_DrawRect(MainWindowD, &rect1, 0, color, 2, key); } goto lNextComp_big; } lNextComp_big: comp = CCOM_GetNext(comp, NULL); } //end stepa_am comp = CCOM_GetFirst(hCCOM, NULL); while (comp) { if (comp->h < Height / 6) goto lNextComp; if (comp->h > Height * 1.5) goto lNextComp; if (comp->upper < rect.top) goto lNextComp; if (comp->left < rect.left) goto lNextComp; if (comp->upper + comp->h > rect.bottom) goto lNextComp; if (comp->left + comp->w > rect.right) goto lNextComp; if ((comp->h < Height / 3) && (comp->upper < rect.top)) goto lNextComp; for (i = 0; i < nPics; i++) { if ((comp->upper >= pPics[i].upper) && (comp->left >= pPics[i].left) && (comp->upper + comp->h < pPics[i].upper + pPics[i].h) && (comp->left + comp->w <= pPics[i].left + pPics[i].w)) { goto lNextComp; } } if ((comp->h > Height * 0.5) && (comp->h < Height * 1.5)) { (*Result1)++; if (!LDPUMA_Skip(hShowCheckLetters)) { rect1.left = comp->left; rect1.top = comp->upper; rect1.right = comp->left + comp->w; rect1.bottom = comp->upper + comp->h; LDPUMA_DrawRect(MainWindowD, &rect1, 0, color, 8, key); } goto lNextComp; } if ((comp->h > Height / 3* 0.5 )&&(comp->h < Height/3*1.5)) { (*Result2)++; if(!LDPUMA_Skip(hShowCheckLetters)) { rect1.left = comp->left; rect1.top = comp->upper; rect1.right = comp->left + comp->w; rect1.bottom = comp->upper + comp->h; LDPUMA_DrawRect(MainWindowD, &rect1, 0, color, 2, key); } goto lNextComp; } lNextComp: comp = CCOM_GetNext(comp,NULL); } if(!LDPUMA_Skip(hShowCheckLetters)) { LDPUMA_Console("RPIC_Анализ на заголовки \n"); LDPUMA_WaitUserInput(hShowCheckLetters, MainWindowD); LDPUMA_DeleteRects(MainWindowD, key); } return TRUE; }
void PageLayoutPart1 (void) { int i; i=0; i=i; # ifdef MA_DEBUG AllocationsAccountingOpen (); # endif # ifdef LT_DUMP pfListing = fopen ("layout.dmp", "w"); if (pfListing == NULL) ErrorInternal ("Can't open dump file"); fprintf (pfListing, "nRoots: %d\n", (int) nRoots); { int i; for (i = 0; i < nRoots; i++) { fprintf (pfListing, "x: %4d, y: %4d, w: %4d, h: %4d, block: %4d/%4d [%4x %4x] %4x\n", (int) pRoots [i].xColumn, (int) pRoots [i].yRow, (int) pRoots [i].nWidth, (int) pRoots [i].nHeight, (int) pRoots [i].nBlock, (int) pRoots [i].nUserNum, 0, //(int) pRoots [i].wSegmentPtr, 0, //(int) pRoots [i].wLength); (int) pRoots [i].bType); } } fclose (pfListing); # endif if (nRoots == 0) //ErrorInternal ("Page is empty"); return; nNextBlockNumber = FIRST_REGULAR_BLOCK_NUMBER; # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel > 0) if( !LDPUMA_Skip (hPageBeforeEditing) || !LDPUMA_Skip (hPageMatrix) || !LDPUMA_Skip (hInitialBreaking) || !LDPUMA_Skip (hInclineCalculating) || !LDPUMA_Skip (hBlocksBreaking) || !LDPUMA_Skip (hBlocksGlueing) || !LDPUMA_Skip (hFirstDustAbsorbtion) || !LDPUMA_Skip (hRemoveEmptyBlocks) || !LDPUMA_Skip (hSecondDustAbsorbtion)) { LT_GraphicsOpen (); } if (bDebugTimeFlag) tTimeTotal = clock (); # endif RootsSaveNonLayoutData (); CalculatePageParameters (); SeparatorsGet (); # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 2) if (!LDPUMA_Skip(hPageBeforeEditing)) LT_GraphicsRootsOutput ("Page"); # endif if (bOptionInitialBreakingByPageMatrix || bOptionBlocksRemovingByPageMatrix) { PageMatrixBuild (); } # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 2) if (!LDPUMA_Skip(hPageMatrix)) LT_GraphicsPageMatrixOutput ("Page matrix"); # endif // выделить в матрице страницы компоненты связности; // настроить в рутах поле nBlock на хранение этой // полезной информации; сами компоненты связности -- не хранятся. InitialBreakingProceed (); # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 3) if (!LDPUMA_Skip(hInitialBreaking)) LT_GraphicsBlocksOutput ("Initial breaking"); # endif // InclinesAccount (); RotatePageToIdeal (); // InclinesFreeData (); RootStripsCalculate (); # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 3) if(!LDPUMA_Skip(hInclineCalculating)) { LT_GraphicsRootsOutput ("Roots after page rotation"); LT_GraphicsRootStripsOutput ("Root strips"); } # endif BlocksExtract (); //BlockAnalyse(); # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 2) // LT_GraphicsBlocksOutput ("Blocks after extraction.1"); # endif /* Pit 09-27-94 03:42pm new_picture(3,5,300,500); del_picture(0); new_picture(300,500,100,100); BlocksExtract (); # ifdef LT_DEBUG if (LT_DebugGraphicsLevel >= 2) LT_GraphicsBlocksOutput ("Blocks after extraction.2"); # endif */ BlocksBreak (); # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 2) if(!LDPUMA_Skip(hBlocksBreaking)) LT_GraphicsBlocksOutput ("Blocks after breaking"); # endif BlocksAddVirtualSeparatorsBlocks (); # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 2) // LT_GraphicsBlocksOutput ("Blocks after adding separators"); # endif BlocksRemoveFrameLikeRoots (); # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 2) // LT_GraphicsBlocksOutput ("After removing frame like roots"); # endif BlocksGlue (); # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 2) if(!LDPUMA_Skip(hBlocksGlueing)) LT_GraphicsBlocksOutput ("Blocks after glueing"); # endif BlocksBuildEmbeddingLists (); # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 3) //{ // LT_GraphicsHighEmbeddingBlocksListOutput ("High embedding blocks list"); // LT_GraphicsLowEmbeddingBlocksListOutput ("Low embedding blocks list"); //} # endif BlocksAbsorbDust (); # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 2) if(!LDPUMA_Skip(hFirstDustAbsorbtion)) LT_GraphicsBlocksOutput ("After first dust absorbtion"); # endif PageMatrixExcludeSeparators (TRUE); # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 2) // LT_GraphicsPageMatrixOutput ("Matrix after excluding separators"); # endif BlocksRemoveEmptyBlocks (); # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 2) if(!LDPUMA_Skip(hRemoveEmptyBlocks)) LT_GraphicsBlocksOutput ("After removing empty blocks"); # endif BlocksAbsorbDust (); BlocksDisAbsorbBoundaryDust (); # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 2) if(!LDPUMA_Skip(hSecondDustAbsorbtion)) LT_GraphicsBlocksOutput ("After second dust absorbtion"); # endif if (cut_page_left || cut_page_right) { BlocksCutPageEdges (); # ifdef LT_DEBUG // if (LT_DebugGraphicsLevel >= 2) // LT_GraphicsBlocksOutput ("After BlocksCutPageEdges"); # endif } LayoutBackupFreeData (); }
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; }
Bool32 Open_Res_Log( void ) { logFile_comp = LDPUMA_FOpen(LOGFILENAME_COMP ,"at"); resFile_comp = LDPUMA_FOpen(RESFILENAME_COMP ,"at"); logFile_pict = LDPUMA_FOpen(LOGFILENAME_PICT ,"at"); resFile_pict = LDPUMA_FOpen(RESFILENAME_PICT ,"at"); logFile_blocks = LDPUMA_FOpen(LOGFILENAME_BLOCKS,"at"); resFile_blocks = LDPUMA_FOpen(RESFILENAME_BLOCKS,"at"); char* name; if(!LDPUMA_Skip(CutStrPrintFILE)&&!LDPUMA_Skip(hDebugCutStr)) { f_cut_str=fopen("cutstr.res","a"); if(f_cut_str==NULL) f_cut_str=fopen("cutstr.res","w+"); if(f_cut_str) { name=LDPUMA_GetFileName (NULL); fprintf(f_cut_str,"%s\n",name); } oldRoot.top=-1; oldRoot.bottom=-1; oldRoot.left=-1; oldRoot.right=-1; } if(!LDPUMA_Skip(DifferenCutToHistory)) { f_old_cut=fopen("oldcutst.res","r"); f_temp_cut=fopen("tempcut.res","w"); name=LDPUMA_GetFileName (NULL); if(f_temp_cut) fprintf(f_temp_cut,"%s\n",name); } if(!LDPUMA_Skip(CutCompPrintFILE)&&LDPUMA_Skip(hCutComp)) { f_cut_comp=fopen("cutcomp.res","a"); if(f_cut_comp==NULL) f_cut_comp=fopen("cutcomp.res","w+"); if(f_cut_comp) { name=LDPUMA_GetFileName (NULL); fprintf(f_cut_comp,"%s\n",name); } } if(!LDPUMA_Skip(DifferenCutCompToHistory)) { f_old_cut_comp=fopen("oldcutco.res","r"); f_temp_cut_comp=fopen("tempcutc.res","w"); name=LDPUMA_GetFileName (NULL); if(f_temp_cut_comp) fprintf(f_temp_cut_comp,"%s\n",name); } return TRUE; }
Bool32 ModulesInit(Handle ghStorage) { // CONTEINERS if(!CLINE_Init(PUMA_MODULE_CLINE,NULL)) { SetReturnCode_puma(CLINE_GetReturnCode()); goto lError; } if(!CFIO_Init(PUMA_MODULE_CFIO,NULL)) { SetReturnCode_puma(CFIO_GetReturnCode()); goto lError; } /* ghStorage = OpenStorage(szStorage,OS_CREATE); if(ghStorage==NULL) { SetReturnCode_puma(IDS_ERR_CREATESTORAGE); goto lError; } */ if(!CIMAGE_Init(PUMA_MODULE_CIMAGE,NULL)) { SetReturnCode_puma(CIMAGE_GetReturnCode()); goto lError; } if(!CCOM_Init(PUMA_MODULE_CCOM,NULL)) // нужна инициализация контейнера CCOM перед { // вызовом поиска компонент SetReturnCode_puma(CCOM_GetReturnCode()); goto lError; } if(!CPAGE_Init(PUMA_MODULE_CPAGE,ghStorage)) { SetReturnCode_puma(CPAGE_GetReturnCode()); goto lError; } if(!CSTR_Init(PUMA_MODULE_CSTR,ghStorage)) { SetReturnCode_puma(CSTR_GetReturnCode()); goto lError; } // RECOGNITIONS if(!REXC_Init(PUMA_MODULE_REXC,NULL)) // инициализация библиотеки поиска компонент { SetReturnCode_puma(REXC_GetReturnCode()); goto lError; } // REXC_SetImportData(REXC_OcrPath, GetModulePath()); if(!RLINE_Init(PUMA_MODULE_RLINE,ghStorage)) { SetReturnCode_puma(RLINE_GetReturnCode()); goto lError; } if(!RRECCOM_Init(PUMA_MODULE_RRECCOM,ghStorage)) { SetReturnCode_puma(RRECCOM_GetReturnCode()); goto lError; } RRECCOM_SetImportData(RRECCOM_OcrPath, GetModulePath()); if(!RSL_Init(PUMA_MODULE_RSL,ghStorage)) { SetReturnCode_puma(RSL_GetReturnCode()); goto lError; } if(!RSTUFF_Init(PUMA_MODULE_RSTUFF,ghStorage)) { SetReturnCode_puma(RSTUFF_GetReturnCode()); goto lError; } if(!RMARKER_Init(PUMA_MODULE_RBLOCK,ghStorage)) { SetReturnCode_puma(RMARKER_GetReturnCode()); goto lError; } if(!RBLOCK_Init(PUMA_MODULE_RBLOCK,ghStorage)) { SetReturnCode_puma(RBLOCK_GetReturnCode()); goto lError; } if(!RSELSTR_Init(PUMA_MODULE_RBLOCK,ghStorage)) { SetReturnCode_puma(RSELSTR_GetReturnCode()); goto lError; } RSTR_SetImportData(RSTR_OcrPath, GetModulePath()); RSTR_SetImportData(RSTR_pchar_temp_dir, GetModuleTempPath()); if(!RSTR_Init(PUMA_MODULE_RSTR,ghStorage)) { SetReturnCode_puma(RSTR_GetReturnCode()); goto lError; } if(!RFRMT_Init(PUMA_MODULE_RFRMT,ghStorage)) { SetReturnCode_puma(RFRMT_GetReturnCode()); goto lError; } if(!RIMAGE_Init(PUMA_MODULE_RIMAGE,ghStorage)) { SetReturnCode_puma(RIMAGE_GetReturnCode()); goto lError; } // Инициализируем виртуальные функции if(!RPSTR_Init(PUMA_MODULE_RPSTR,ghStorage)) { SetReturnCode_puma(RPSTR_GetReturnCode()); goto lError; } if(!RPIC_Init(PUMA_MODULE_RPIC,ghStorage)) { SetReturnCode_puma(RPIC_GetReturnCode()); goto lError; } if(!CED_Init(PUMA_MODULE_CED,ghStorage)) { SetReturnCode_puma(CED_GetReturnCode()); goto lError; } if(!ROUT_Init(PUMA_MODULE_ROUT,ghStorage)) { SetReturnCode_puma(ROUT_GetReturnCode()); goto lError; } else { if(!ROUT_LoadRec6List("rec6all.dat")) { SetReturnCode_puma(ROUT_GetReturnCode()); goto lError; } } #ifdef _USE_RVERLINE_ if(!RVERLINE_Init(PUMA_MODULE_RVERLINE,ghStorage)) { SetReturnCode_puma(RVERLINE_GetReturnCode()); goto lError; } #endif //_USE_RVERLINE_ #ifdef _USE_RMSEGMENT_ if(!RMSEGMENT_Init(PUMA_MODULE_RMSEGMENT,ghStorage)) { SetReturnCode_puma(RMSEGMENT_GetReturnCode()); goto lError; } #endif //_USE_RMSEGMENT_ if(!RCORRKEGL_Init(PUMA_MODULE_RCORRKEGL,ghStorage)) { goto lError; } //#ifdef _DEBUG My_SJTL_Init(); if( !LDPUMA_Skip(hDebugEnableSaveJtl) ) { My_SJTL_open("one.frm", "one.jtl"); } /* FIXME: could not figure out what to do with this in Linux, so disabled it. _CrtMemCheckpoint( &g_dbgMemState ); */ //#endif return TRUE; lError: ModulesDone(ghStorage); return FALSE; }
Bool16 SnpSkip( SnpTreeNode* node ) { return LDPUMA_Skip( node ? *(Handle *)node:NULL); };
void checkResolution(Handle hCCOM, Handle hCPAGE) { PAGEINFO page_info = {0}; const int min_res = 99; CCOM_comp* pcomp=NULL; unsigned int Masy[100], Masx[100], i, Jy_m = 0, My_m = 0, Jx_m = 0, Mx_m = 0, M_t; bool flag_set = false; if (!GetPageInfo(hCPAGE, &page_info)) return; if (page_info.DPIX > min_res && page_info.DPIY > min_res) return; for (i=0; i<100; i++) Masx[i] = Masy[i] = 0; pcomp = CCOM_GetFirst(hCCOM, NULL); while (pcomp) { if (pcomp->h > 9 && pcomp->h < 100) Masy[pcomp->h]++; if (pcomp->w > 9 && pcomp->w < 100) Masx[pcomp->w]++; pcomp = CCOM_GetNext(pcomp, NULL); } for (i=11; i < 99; i++) { M_t = Masy[i-1] + Masy[i] + Masy[i+1]; if (M_t > My_m) { Jy_m = i; My_m = M_t; } M_t = Masx[i-1] + Masx[i] + Masx[i+1]; if (M_t > Mx_m) { Jx_m = i; Mx_m = M_t; } } if (Jy_m > 10 && My_m > 100 && !(page_info.DPIY*22 < 2*300*Jy_m && 2*page_info.DPIY*22 > 300*Jy_m)) { page_info.DPIY = (300*Jy_m+11)/22; flag_set = true; } if (Jx_m > 10 && Mx_m > 100 && !(page_info.DPIX*22 < 2*300*Jx_m && 2*page_info.DPIX*22 > 300*Jx_m)) { page_info.DPIX = (300*Jx_m+11)/22; flag_set = true; } if (flag_set) { SetPageInfo(hCPAGE, page_info); if (!LDPUMA_Skip(hDebugPrintResolution)) LDPUMA_ConsoleN("новое разрешение: DPIX=%d, DPIY=%d", page_info.DPIX, page_info.DPIY); } }
///////////////////////////////////////////////////////////////////////////////////////////////////// // //Bool32 AboutLines(PRSPreProcessImage Image, Bool32 *BadScan, int32_t *ScanQual) //{ // return TRUE; //} ///////////////////////////////////////////////////////////////////////////////////////////////////// // Bool32 CalcIncline(PRSPreProcessImage Image) { int SizeWork,SizeMain; char Str[256]; Bool ret, WasLine, ManyComp; Bool CalcMuchSkew, TalkMuchSkew; uint16_t Code; int32_t SkewReg, Skew, SkewLocVerLin; Rect16 RcReg; PAGEINFO info = {0}; UN_BUFF MainBuff = {0}; void *vMain; char *cWork; Handle hCPage=Image->hCPAGE; CLINE_handle hCLINE=*((CLINE_handle*)Image->phCLINE); GetPageInfo(hCPage,&info); /* 2. Инициализация. */ /*** переменные ***/ WasLine = 0; /*** организация памяти ***/ GiveMainBuff (&vMain, &SizeMain); MainBuff.vBuff = vMain; MainBuff.SizeBuff = SizeMain; MainBuff.vCurr = MainBuff.vBuff; MainBuff.SizeCurr = MainBuff.SizeBuff; GiveWorkBuff (&cWork, &SizeWork); /*** линии ***/ // if(!LDPUMA_Skip(hUseCLine)) ret=LoadLinesVP_rv(hCLINE,UN_LD_LinesVP2,&MainBuff,Str,&Code); // else // ret = LoadLinesVP_rv (hCPage, UN_LD_LinesVP, (void *)(&MainBuff), Str, &Code); if ((ret!=RV_TRUE)&&(ret!=RV_EMPTY)) { SetReturnCode_rstuff (Code); return ret; } WasLine = (ret==RV_TRUE); /*** компоненты ***/ ret = LoadComps_rv (*(Image->phCCOM), (void *)(&MainBuff), Str, 0); //t-e-d if (ret==RV_DOUBT) { SetReturnCode_rstuff (Code); CleanLastDataPart ((void *)(&MainBuff)); } ManyComp = (ret==RV_TRUE)&&(MainBuff.nPartUnits[MainBuff.nPart-1]>10000); if (ManyComp) { CleanLastDataPart ((void *)(&MainBuff)); } if (ret==RV_DOUBT||ManyComp) { ret = LoadComps_rv (*(Image->phCCOM), (void *)(&MainBuff), Str, 3); //t-e-d if (ret==RV_DOUBT) { SetReturnCode_rstuff (Code); CleanLastDataPart ((void *)(&MainBuff)); } } if (ret!=RV_TRUE) { return ret; } RcReg.left=0; RcReg.right=(int16_t)info.Width; RcReg.top=0; RcReg.bottom=(int16_t)info.Height; SkewReg=0; Bool ContWarn = 0; SkewLocVerLin = 0; CalcMuchSkew = (!LDPUMA_Skip(hCalcMuchSkew)); TalkMuchSkew = (!LDPUMA_Skip(hTalkMuchSkew)); // 5.1 Определяем угол наклона страницы (ее заполнения в целом). // if(!LDPUMA_Skip(hUseCLine)) ret=ConvertLinesToAM_rv (UN_LD_LinesVP2, UN_LD_LinesAM, (void *)(&MainBuff) ,(int *)cWork, SizeWork / sizeof (int), &RcReg, SkewReg, Str, ContWarn); // else // ret = ConvertLinesToAM_rv (UN_LD_LinesVP, UN_LD_LinesAM, (void *)(&MainBuff) // ,(int *)cWork, SizeWork / sizeof (int), &RcReg, SkewReg, Str, ContWarn); // f-t-e-d if (ret==RV_DOUBT) { SetReturnCode_rstuff (Code); } if (ret!=RV_TRUE) return ret; SMetric_SetImportData(SMetric_ResolX, (void *)info.DPIX); SMetric_SetImportData(SMetric_ResolY, (void *)info.DPIY); ret = SMetric_FindMainSkew ((void *)(&MainBuff), cWork, SizeWork, &Skew , &SkewLocVerLin, &RcReg, SkewReg, Str, CalcMuchSkew, TalkMuchSkew); if (ret!=RV_TRUE) return ret; info.Incline2048 = Skew*2; info.SkewLocVerLin2048 = SkewLocVerLin*2; if(!CPAGE_SetPageData(Image->hCPAGE,PT_PAGEINFO,&info,sizeof(PAGEINFO))) { SetReturnCode_rstuff(CPAGE_GetReturnCode()); return FALSE; } return TRUE; }
//////////////////////////////////////////////////////////////////////////////// // Нормализация сырь // (07.07.2000) Изначально взято из puma.dll без изменений Bool32 Normalise( PRSPreProcessImage Image) { Bool32 rc; LDPUMA_Skip(hPrep); rc = PreProcessImage( Image ); LDPUMA_Skip(hDebugAutoTemplate); // if( rc ) // rc = AutoTemplate( Image ); // rc = RNORM_AutoTemplate( Image ); LDPUMA_Skip(hSearchLine); if ( rc ) rc = SearchLines( Image ); LDPUMA_Skip(hCalcIncline); if( rc ) rc = CalcIncline( Image ); LDPUMA_Skip(hOrto); if (rc) rc = OrtoMove( Image ); LDPUMA_Skip(hContBigComp); if(rc) rc= CreateContainerBigComp( Image ); LDPUMA_Skip(hVerOrNewLine); /* if (rc && // В Турецком зазря удаляются точки над буквами. 02.07.2002 E.P.. Image->gnLanguage != LANG_TURKISH && LDPUMA_Skip(hDotLine) && LDPUMA_Skip(Image->hDebugCancelSearchDotLines) ) // if (rc && LDPUMA_Skip(hDotLine) && LDPUMA_Skip(Image->hDebugCancelSearchDotLines)) rc = SLINEDOT_SearchDotLines(*(Image->phCCOM), Image->hCPAGE, Image->phCLINE);//Almi 0822 // SLINEDOT_SearchDotLines(*(Image->phCCOM), Image->hCPAGE, Image->phCLINE);*/ if ( rc ) rc = SearchNewLines( Image ); LDPUMA_Skip(hKillLine); // снятие линий if ( rc ) rc = KillLinesN( Image ); LDPUMA_Skip(hKillLineAfter); // убиваем остатки линии после сняти if ( rc && LDPUMA_Skip(Image->hDebugCancelRemoveLines)) // rc = //almi 28.11.00 LineKiller(Image); LDPUMA_Skip(hEnd); return rc; }
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; }
Bool32 DeleteLines(Handle hCPage,void* phCLINE, const char* ImageDelLines) { // LDPUMA_ConsoleN("Активизируется функция тривиального удаления линий"); int time=clock(); CLINE_handle* pCLINE=(CLINE_handle*)phCLINE; MyLine* pHorLines=NULL; MyLine* pVerLines=NULL; int nHorLines=0; int nVerLines=0; int len_hor_mas=0; int len_ver_mas=0; int add_len_mas=50; uint32_t size_lineinfo=sizeof(LineInfo); if(!LDPUMA_Skip(NotKillPointed)) fl_not_kill_pointed=TRUE; else fl_not_kill_pointed=FALSE; dphNotTestAlik=!LDPUMA_Skip(hNotTestAlik); CIMAGEIMAGECALLBACK cbk; CIMAGEIMAGECALLBACK cbk1; // LinesTotalInfo lti; // LineInfo linfo; // собственно, что и надо PAGEINFO info = {0}; // Описание страницы // Handle pBlock; // uint32_t size32; int i; // uint32_t HorType; // uint32_t VerType; Bool fl_cont; uchar ImageName[CPAGE_MAXNAME]; // Получаем PAGEINFO текущей страницы GetPageInfo(hCPage,&info); // Копируем в pImage из PInfo указатель на изображение, // связанное со страницей for(i=0;i<CPAGE_MAXNAME;i++) ImageName[i]=info.szImageName[i]; if (!CIMAGE_GetCallbackImage(ImageName,&cbk)) return FALSE; cbk1.CIMAGE_ImageOpen = cbk.CIMAGE_ImageOpen; cbk1.CIMAGE_ImageRead = cbk.CIMAGE_ImageRead; cbk1.CIMAGE_ImageClose = cbk.CIMAGE_ImageClose; if (!CIMAGE_WriteCallbackImage((uchar*)ImageDelLines,cbk1)) { return FALSE; } Handle lpDIB; if(!CIMAGE_ReadDIB((uchar*)ImageDelLines,&lpDIB,1)) { CIMAGE_DeleteImage((uchar*)ImageDelLines); return FALSE; } CTDIB* ctdib = new CTDIB; if(!ctdib) { CIMAGE_DeleteImage((uchar*)ImageDelLines); return FALSE; } ctdib->SetDIBbyPtr (lpDIB); const int bytewide=ctdib->GetLineWidthInBytes(); int num_str=ctdib->GetLinesNumber (); // int bytesize=ctdib->GetImageSizeInBytes (); uchar* pmasp=(uchar*)(ctdib->GetPtrToBitFild()); // uchar* pos=(uchar*)(ctdib->GetPtrToPixel (pHorLines[0].begx,pHorLines[0].begy)); // uchar* pos2=(uchar*)(ctdib->GetPtrToPixel (pHorLines[0].begx,pHorLines[0].begy)); uint32_t size_line_com=sizeof(LINE_COM); CLINE_handle hline; if(LDPUMA_Skip(ObvKillLines)) { for(hline=CLINE_GetFirstLine(*pCLINE);hline;hline=CLINE_GetNextLine(hline)) { DelLineFromInside(pmasp,bytewide,num_str,hline); } } else//тривиальное снятие линий { // if(!LDPUMA_Skip(hUseCLine)) // { hline = CLINE_GetFirstLine(*pCLINE); nHorLines=0; len_hor_mas=50; nVerLines=0; len_ver_mas=50; if(!InitLineMas(&pHorLines,len_hor_mas)) { ctdib->ResetDIB (); delete ctdib; CIMAGE_DeleteImage((uchar*)ImageDelLines); return FALSE; } if(!InitLineMas(&pVerLines,len_ver_mas)) { DelLineMas(pHorLines); ctdib->ResetDIB (); delete ctdib; CIMAGE_DeleteImage((uchar*)ImageDelLines); return FALSE; } while(hline) { CPDLine cpdata; fl_cont=FALSE; cpdata=CLINE_GetLineData(hline); if(!cpdata) hline=CLINE_GetNextLine(hline); else { if((cpdata->Flags & LI_IsTrue)&&(!fl_not_kill_pointed||(fl_not_kill_pointed&&cpdata->Type!=NR_DT_LinePointed))) { if(cpdata->Dir==LD_Horiz) { if(nHorLines>=len_hor_mas) { if(!AddLenLineMas(&pHorLines,len_hor_mas,add_len_mas)) { fl_cont=TRUE; hline=CLINE_GetNextLine(hline); } } if(!fl_cont) { pHorLines[nHorLines].begx=cpdata->Line.Beg_X; pHorLines[nHorLines].begy=cpdata->Line.Beg_Y; pHorLines[nHorLines].endx=cpdata->Line.End_X; pHorLines[nHorLines].endy=cpdata->Line.End_Y; pHorLines[nHorLines].wide10=cpdata->Line.Wid10; nHorLines++; hline=CLINE_GetNextLine(hline); } } else { if(nVerLines>=len_ver_mas) { if(!AddLenLineMas(&pVerLines,len_ver_mas,add_len_mas)) { fl_cont=TRUE; hline=CLINE_GetNextLine(hline); } } if(!fl_cont) { pVerLines[nVerLines].begx=cpdata->Line.Beg_X; pVerLines[nVerLines].begy=cpdata->Line.Beg_Y; pVerLines[nVerLines].endx=cpdata->Line.End_X; pVerLines[nVerLines].endy=cpdata->Line.End_Y; pVerLines[nVerLines].wide10=cpdata->Line.Wid10; nVerLines++; hline=CLINE_GetNextLine(hline); } } } else hline=CLINE_GetNextLine(hline); } } /* } else { pBlock=NULL; pBlock = CPAGE_GetBlockFirst (hCPage, RLINE_BLOCK_TYPE ); if( pBlock==NULL) { info.Images|=IMAGE_DELLINE; SetPageInfo(hCPage,info); ctdib->ResetDIB (); delete ctdib; return TRUE; } size32 = CPAGE_GetBlockData(hCPage, pBlock, RLINE_BLOCK_TYPE, <i, sizeof(LinesTotalInfo)); if (size32 != sizeof(LinesTotalInfo) ) { ctdib->ResetDIB (); delete ctdib; CIMAGE_DeleteImage((uchar*)ImageDelLines); return FALSE; } HorType = (uint32_t)lti.Hor.Lns; VerType = (uint32_t)lti.Ver.Lns; ///////////////////////////////////////////////////////////////////////////////////////////// nHorLines=0; len_hor_mas=50; if(!InitLineMas(&pHorLines,len_hor_mas)) { ctdib->ResetDIB (); delete ctdib; CIMAGE_DeleteImage((uchar*)ImageDelLines); return FALSE; } pBlock=NULL; pBlock = CPAGE_GetBlockFirst(hCPage,HorType); while (pBlock) { fl_cont=FALSE; size32 = CPAGE_GetBlockData(hCPage,pBlock,HorType,&linfo,size_lineinfo); if(size32!=size_lineinfo) { fl_cont=TRUE; pBlock = CPAGE_GetBlockNext(hCPage,pBlock,HorType); } if(fl_cont) continue; if(!(linfo.Flags&LI_IsTrue)||(fl_not_kill_pointed&&(linfo.Flags&LI_Pointed))) { fl_cont=TRUE; pBlock = CPAGE_GetBlockNext(hCPage,pBlock,HorType); } if(fl_cont) continue; if(nHorLines>=len_hor_mas) { if(!AddLenLineMas(&pHorLines,len_hor_mas,add_len_mas)) { fl_cont=TRUE; pBlock = CPAGE_GetBlockNext(hCPage,pBlock,HorType); } } if(fl_cont) continue; pHorLines[nHorLines].begx=linfo.A.x; pHorLines[nHorLines].begy=linfo.A.y; pHorLines[nHorLines].endx=linfo.B.x; pHorLines[nHorLines].endy=linfo.B.y; pHorLines[nHorLines].wide10=(linfo.Thickness)*10; nHorLines++; pBlock = CPAGE_GetBlockNext(hCPage,pBlock,HorType); } ///////////////////////////////////////////////////////////////////////////////////////////// nVerLines=0; len_ver_mas=50; pBlock=NULL; pBlock = CPAGE_GetBlockFirst(hCPage,VerType); if(!InitLineMas(&pVerLines,len_ver_mas)) { ctdib->ResetDIB (); delete ctdib; CIMAGE_DeleteImage((uchar*)ImageDelLines); DelLineMas(pHorLines); return FALSE; } while (pBlock) { fl_cont=FALSE; size32 = CPAGE_GetBlockData(hCPage,pBlock,VerType,&linfo,size_lineinfo); if(size32!=size_lineinfo) { fl_cont=TRUE; pBlock = CPAGE_GetBlockNext(hCPage,pBlock,VerType); } if(fl_cont) continue; if(!(linfo.Flags&LI_IsTrue)||(fl_not_kill_pointed&&(linfo.Flags&LI_Pointed))) { fl_cont=TRUE; pBlock = CPAGE_GetBlockNext(hCPage,pBlock,VerType); } if(fl_cont) continue; if(nVerLines>=len_ver_mas) { if(!AddLenLineMas(&pVerLines,len_ver_mas,add_len_mas)) { fl_cont=TRUE; pBlock = CPAGE_GetBlockNext(hCPage,pBlock,VerType); } } if(fl_cont) continue; pVerLines[nVerLines].begx=linfo.A.x; pVerLines[nVerLines].begy=linfo.A.y; pVerLines[nVerLines].endx=linfo.B.x; pVerLines[nVerLines].endy=linfo.B.y; pVerLines[nVerLines].wide10=(linfo.Thickness)*10; nVerLines++; pBlock = CPAGE_GetBlockNext(hCPage,pBlock,VerType); } } */ ///////////////////////////////////////////////////////////////////////////////////////////// int time_hor=clock(); for(i=0;i<nHorLines;i++) { if(pHorLines[i].begx>pHorLines[i].endx) DelOneHorLine(pmasp,bytewide,num_str,pHorLines[i].endx,pHorLines[i].endy,pHorLines[i].begx,pHorLines[i].begy,pHorLines[i].wide10); else DelOneHorLine(pmasp,bytewide,num_str,pHorLines[i].begx,pHorLines[i].begy,pHorLines[i].endx,pHorLines[i].endy,pHorLines[i].wide10); } time_hor=clock()-time_hor; // LDPUMA_ConsoleN("Time hor=%d",time_hor); int time_ver=clock(); for(i=0;i<nVerLines;i++) { if(pVerLines[i].begy>pVerLines[i].endy) DelOneVerLine(pmasp,bytewide,num_str,pVerLines[i].endx,pVerLines[i].endy,pVerLines[i].begx,pVerLines[i].begy,pVerLines[i].wide10); else DelOneVerLine(pmasp,bytewide,num_str,pVerLines[i].begx,pVerLines[i].begy,pVerLines[i].endx,pVerLines[i].endy,pVerLines[i].wide10); } time_ver=clock()-time_ver; // LDPUMA_ConsoleN("Time ver=%d",time_ver); DelLineMas(pHorLines); DelLineMas(pVerLines); }//конец тривиального удаления ctdib->ResetDIB (); delete ctdib; info.Images|=IMAGE_DELLINE; SetPageInfo(hCPage,info); time=clock()-time; // LDPUMA_ConsoleN("Time work=%d",time); return TRUE; }
Bool TryCutBlockOnVertical (BLOCK *p, int bcr_cut, Bool32 SecondStage) { ROOT *pRoot; int iLeftColumn, iRightColumn; int iColumn; int nMaximum; int nLowLevel; int nSpaceWidth; int iSpace; int nHystSum; Bool bNotSpace; int iLeftLimit; int iRightLimit; int iBestPointSizeBreakingColumn; int nPointSizeDifference; int nBestPointSizeDifference = 0; /* To avoid warning on MPW C/C++ */ int nSum; int nAverage; int nColumns; BLOCK *q, *r; # ifdef LT_DEBUG if (p -> pHorzHystogram == NULL) ErrorInternal ("pHorzHystogram not builded in TryCutBlockOnVertical"); # endif nHystColumnWidth = p -> nStartColumnWidth; while (nHystColumnWidth >= p -> nConditionalMinColumnWidth) { /* Build vertical hystogram */ nHystColumns = (p -> Rect.xRight - p -> Rect.xLeft + 1) / nHystColumnWidth + 1; //memset (pHystogram, 0, nHystColumns * sizeof (int)); memset (pHystogram, 0, (nHystColumns + 1) * sizeof (int));// Piter 08.07.99 for (pRoot = p -> pRoots; pRoot != NULL; pRoot = pRoot -> u1.pNext) { iLeftColumn = (pRoot -> xColumn - p -> Rect.xLeft) / nHystColumnWidth; iRightColumn = (pRoot -> xColumn + pRoot -> nWidth - 1 - p -> Rect.xLeft) / nHystColumnWidth; pHystogram [iLeftColumn] ++; pHystogram [iRightColumn + 1] --; } nMaximum = 0; nHystSum = 0; for (iColumn = 0; iColumn < nHystColumns; iColumn++) { nHystSum += pHystogram [iColumn]; pHystogram [iColumn] = nHystSum; if (pHystogram [iColumn] > nMaximum) nMaximum = pHystogram [iColumn]; } nLowLevel = VERT_HYST_LOW_LEVEL (nMaximum); /* Rom */ if (SecondStage) { nSum = 0; for (iColumn = 0; iColumn < nHystColumns; iColumn++) { nSum += pHystogram [iColumn]; } if(nHystColumns!= 0) { nAverage = nSum/nHystColumns; } nSum = 0; nColumns = 0; for (iColumn = 0; iColumn < nHystColumns; iColumn++) { if(pHystogram [iColumn] > nAverage) { nSum += pHystogram [iColumn]; nColumns++; } } if(nColumns!= 0) { nAverage = nSum/nColumns; } for (iColumn = 0; iColumn < nHystColumns; iColumn++) { if(pHystogram [iColumn] < nAverage / 10) { pHystogram [iColumn] = 0; } } } /* Rom */ # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 4) if(!LDPUMA_Skip(hBlocksBreaking)) { pDebugBlock = p; // Piter 02-10-98 LT_GraphicsHystogramOutput ("Hystogram for vertical breaking"); } # endif bNotSpace = FALSE; for (iColumn = 0; iColumn < nHystColumns; iColumn++) { if (pHystogram [iColumn] == 0) { if (! bNotSpace) continue; if (nHystColumnWidth < p -> nUnconditionalMinColumnWidth && ! CorrectCondition (iColumn)) { continue; } nSpaceWidth = 0; for (iSpace = iColumn; iSpace < nHystColumns && pHystogram [iSpace] == 0; iSpace++) { nSpaceWidth += nHystColumnWidth; } if (iSpace == nHystColumns) break; if (BlockBreakOnVertical (p, NULL, NULL, iColumn * nHystColumnWidth + p -> Rect.xLeft, nSpaceWidth)) { return (TRUE); } iColumn += nSpaceWidth; } else { bNotSpace = TRUE; } } for (iColumn = 0; iColumn < nHystColumns; iColumn++) { if (pHystogram [iColumn] < nLowLevel) { nHystColumnWidth /= 2; break; } } if (iColumn == nHystColumns) break; } /* * Analysis with font accounting */ if (! (bOptionPointSizeAnalysis && bOptionBusinessCardsLayout)) return (FALSE); if (!bcr_cut) return (FALSE); // 940228 /* Build vertical hystogram */ if (nHystColumnWidth != 1) { nHystColumns = p -> Rect.xRight - p -> Rect.xLeft + 1; memset (pHystogram, 0, nHystColumns * sizeof (int)); for (pRoot = p -> pRoots; pRoot != NULL; pRoot = pRoot -> u1.pNext) { iLeftColumn = pRoot -> xColumn - p -> Rect.xLeft; iRightColumn = pRoot -> xColumn + pRoot -> nWidth - 1 - p -> Rect.xLeft; pHystogram [iLeftColumn] ++; pHystogram [iRightColumn + 1] --; } nHystSum = 0; for (iColumn = 0; iColumn < nHystColumns; iColumn++) { nHystSum += pHystogram [iColumn]; pHystogram [iColumn] = nHystSum; } } BlockBuild_HystVertHeightesSum (p); HystogramMakeIntegral (pHystInt1, pHystogram, nHystColumns); HystogramMakeIntegral (pHystInt2, pHystVertHeightesSum, nHystColumns); iLeftLimit = nHystColumns / 10; iRightLimit = nHystColumns - nHystColumns / 10; iBestPointSizeBreakingColumn = 0; for (iColumn = iLeftLimit; iColumn < iRightLimit; iColumn++) { int nAverageHeightBefore; int nAverageHeightAfter; if (pHystogram [iColumn] != 0) continue; if (pHystInt1 [iColumn] == 0 || pHystInt1 [nHystColumns - 1] - pHystInt1 [iColumn] == 0) { continue; } nAverageHeightBefore = pHystInt2 [iColumn] / pHystInt1 [iColumn]; nAverageHeightAfter = (pHystInt2 [nHystColumns - 1] - pHystInt2 [iColumn]) / (pHystInt1 [nHystColumns - 1] - pHystInt1 [iColumn]); if (nAverageHeightBefore == 0 || nAverageHeightAfter == 0) continue; if (! (nAverageHeightBefore >= nAverageHeightAfter * 2 || nAverageHeightAfter >= nAverageHeightBefore * 3)) { continue; } nPointSizeDifference = MAX (nAverageHeightBefore * 1000 / nAverageHeightAfter, nAverageHeightAfter * 1000 / nAverageHeightBefore); if (iBestPointSizeBreakingColumn == 0 || nPointSizeDifference > nBestPointSizeDifference) { iBestPointSizeBreakingColumn = iColumn; nBestPointSizeDifference = nPointSizeDifference; } } if (iBestPointSizeBreakingColumn != 0 && BlockBreakOnVertical (p, &q, &r, iBestPointSizeBreakingColumn + p -> Rect.xLeft, 0)) { # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 3) if(!LDPUMA_Skip(hBlocksBreaking)) { pDebugBlock = q; LT_GraphicsBlockOutput2 ("Block was breaked using " "Vert PointSizeAnalysis"); pDebugBlock = r; LT_GraphicsBlockOutput2 ("Block was breaked using " "Vert PointSizeAnalysis"); LT_Getch (); LT_GraphicsClearScreen (); } # endif return (TRUE); } return (FALSE); }
Bool32 RPIC_SearchPictures(CCOM_handle hCCOM, CCOM_handle hCCOM_big, Handle hCPAGE) { CCOM_comp * comp = NULL; CCOM_comp common; PAGEINFO pInfo; POLY_ block; uint32_t i, j; Rect16 rect; uint32_t key; uint32_t color; uint32_t tmp_comp = 0; Handle MainWindowD = NULL; MainWindowD = LDPUMA_GetWindowHandle("Изображение после разворота"); if (!MainWindowD) MainWindowD = LDPUMA_GetWindowHandle("Main"); OpenLogRes(); file_name = (char*) LDPUMA_GetFileName(NULL); //color = 23650; color = 200; key = 111; nPics = 0; if (pPics) { free(pPics); pPics = NULL; } nComps = 0; CPAGE_GetPageData(hCPAGE, PT_PAGEINFO, (void*) &pInfo, sizeof(pInfo)); for (i = 0; i < MaxHeightOfLetter; i++) { pHystogram[i] = 0; } //LDPUMA_FPuts(hFile, (char*)&pInfo.szImageName); LDPUMA_FPuts(logFile_comp, "*******************************************************\n"); LDPUMA_FPuts(logFile_comp, "new_file \n"); if ((pInfo.Angle == 90) || (pInfo.Angle == 270)) { uint32_t tmp; tmp = pInfo.Width; pInfo.Width = pInfo.Height; pInfo.Height = tmp; } //stepa_am comp = CCOM_GetFirst(hCCOM_big, NULL); while (comp) { tmp_comp++; if ((comp->h > MinHeightOfLetter) && (comp->h < MaxHeightOfLetter)) { nComps++; pHystogram[comp->h]++; } if (comp->scale < 1) goto lNextComp_big; /* if( comp->cs == 255) { comp->type = CCOM_CH_LETTER; goto lNextComp; } */ if (IsNotGoodComp(pInfo, comp)) { if (!LDPUMA_Skip(hShowAllCancelledGreat)) { rect.left = comp->left; rect.top = comp->upper; rect.right = comp->left + comp->w; rect.bottom = comp->upper + comp->h; LDPUMA_DrawRect(MainWindowD, &rect, 0, color, 4, key); } goto lNextComp_big; } if (nPics % PICS_QUANTUM == 0) { pPics = (CCOM_comp *) realloc(pPics, (size_t) ((nPics / PICS_QUANTUM + 1) * PICS_QUANTUM * sizeof(CCOM_comp))); } pPics[nPics++] = *comp; lNextComp_big: comp = CCOM_GetNext(comp, NULL); } //end stepa_am comp = CCOM_GetFirst(hCCOM, NULL); while (comp) { tmp_comp++; if ((comp->h > MinHeightOfLetter) && (comp->h < MaxHeightOfLetter)) { nComps++; pHystogram[comp->h]++; } if ( /*comp->scale < */1) goto lNextComp; /* if( comp->cs == 255) { comp->type = CCOM_CH_LETTER; goto lNextComp; } */ if (IsNotGoodComp(pInfo, comp)) { if (!LDPUMA_Skip(hShowAllCancelledGreat)) { rect.left = comp->left; rect.top = comp->upper; rect.right = comp->left + comp->w; rect.bottom = comp->upper + comp->h; LDPUMA_DrawRect(MainWindowD, &rect, 0, color, 4, key); } goto lNextComp; } if (nPics % PICS_QUANTUM == 0) { pPics = (CCOM_comp *) realloc(pPics, (size_t) ((nPics / PICS_QUANTUM + 1) * PICS_QUANTUM * sizeof(CCOM_comp))); } pPics[nPics++] = *comp; lNextComp: comp = CCOM_GetNext(comp, NULL); } if (!LDPUMA_Skip(hShowAllCancelledGreat)) { LDPUMA_Console("RPIC_Отмененные большие компоненты \n"); LDPUMA_WaitUserInput(hShowAllCancelledGreat, MainWindowD); LDPUMA_DeleteRects(MainWindowD, key); } if (!nComps) // OLEG return TRUE; // STEPA_AM if (!nPics) return TRUE; /**************************************************/ for (i = 0; i < MaxHeightOfLetter; i++) { nAverageHeight += pHystogram[i] * i; /* sprintf(tmp_str, " %i (i)\n", i); LDPUMA_FPuts(logFile,tmp_str); sprintf(tmp_str, " %i (pHystogram[i])\n", pHystogram[i]); LDPUMA_FPuts(logFile,tmp_str); */ } nAverageHeight /= nComps; sprintf(tmp_str, "Average height %i (nAverageHeight)\n", nAverageHeight); LDPUMA_FPuts(logFile_comp, tmp_str); /**************************************************/ /************** first union all crossed and included pictures ******************/ /* for (i=0; i<nPics; i++) { for (j=0; j<nPics; j++) { 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) ) { DeleteFromPics (j); j--; } } } for (i=0; i<nPics; i++) { for (j=0; j<nPics; j++) { if (i==j) continue; if ( (pPics[i].upper - VER_BOUND_SIZE < pPics[j].upper + pPics[j].h)&& (pPics[i].left - HOR_BOUND_SIZE < pPics[j].left + pPics[j].w)&& (pPics[i].left + pPics[i].w + HOR_BOUND_SIZE > pPics[j].left)&& (pPics[i].upper + pPics[i].h + VER_BOUND_SIZE > 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; DeleteFromPics (j); j=0; i=0; } } } */ /***********************************************************************************/ color = 200; key = 111; if ((!LDPUMA_Skip(hShowAllGreat)) && nPics) { for (i = 0; i < nPics; i++) { rect.left = pPics[i].left; rect.top = pPics[i].upper; rect.right = pPics[i].left + pPics[i].w; rect.bottom = pPics[i].upper + pPics[i].h; LDPUMA_DrawRect(MainWindowD, &rect, 0, color, 2, key); } LDPUMA_Console("RPIC_Рассматриваемые большие компоненты \n"); LDPUMA_WaitUserInput(hShowAllGreat, MainWindowD); LDPUMA_DeleteRects(MainWindowD, key); } //sprintf(tmp_str, "Amount of 'letters' on the first step %i (nComps)\n", nComps); //LDPUMA_FPuts(logFile_comp,tmp_str); //sprintf(tmp_str, " <2 Н Страница = %d \n", page_count++); //LDPUMA_FPuts(resFile_comp,tmp_str); //char* str; //str = LDPUMA_GetFileName(NULL); LDPUMA_FPuts(resFile_comp, " <2 Н Страница ="); LDPUMA_FPuts(resFile_comp, file_name); LDPUMA_FPuts(resFile_comp, " \n"); //LDPUMA_FPuts(resFile_comp, " <2 Н Страница \n"); LDPUMA_FPuts(resFile_comp, " <3 Н Компоненты \n"); sprintf(tmp_str, " <4 П Перед выделением линий \n", nComps); LDPUMA_FPuts(resFile_comp, tmp_str); sprintf(tmp_str, " <4 Р %d \n", nComps); LDPUMA_FPuts(resFile_comp, tmp_str); sprintf(tmp_str, "Amount of pictures on the before first step %i (nPics)\n", nPics); LDPUMA_FPuts(logFile_comp, tmp_str); /*******************************************************************/ if (LDPUMA_Skip(hRectanglePictures)) SearchRectanglePictures(hCCOM, hCCOM_big, hCPAGE); if (LDPUMA_Skip(hPolyPictures)) SearchPolyPictures(hCCOM, hCPAGE); /*******************************************************************/ /************** final union all crossed and included pictures ******************/ for (i = 0; i < nPics; i++) { if (pPics[i].large & CCOM_LR_KILLED) { continue; } for (j = 0; j < nPics; j++) { 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; } */ if (pPics[j].large & CCOM_LR_KILLED) { // it's bad, but will work cause pPics[].large not initialised in RPIC pPics[i].large |= CCOM_LR_TAKEN; continue; } 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 - VER_BOUND_SIZE < pPics[j].upper + pPics[j].h) && (pPics[i].left - HOR_BOUND_SIZE < pPics[j].left + pPics[j].w) && (pPics[i].left + pPics[i].w + HOR_BOUND_SIZE > pPics[j].left) && (pPics[i].upper + pPics[i].h + VER_BOUND_SIZE > 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; DeleteFromPics(j); } } } LastCheck(hCCOM, hCCOM_big, hCPAGE); LDPUMA_FPuts(resFile_pict, " <2 Н Страница ="); LDPUMA_FPuts(resFile_pict, file_name); LDPUMA_FPuts(resFile_pict, " \n"); LDPUMA_FPuts(resFile_pict, " <3 Н Картинки \n"); LDPUMA_FPuts(resFile_pict, " <4 Н После первого прохода \n"); sprintf(tmp_str, " <4 Р %d %d %d \n", nPics, 0, 0); LDPUMA_FPuts(resFile_pict, tmp_str); int32_t min_image_width = (int32_t)(100 * ((double) (pInfo.DPIX + 1) / 300)); int32_t min_image_height = (int32_t)(100 * ((double) (pInfo.DPIY + 1) / 300)); for (i = 0; i < nPics; i++) { if (pPics[i].large & CCOM_LR_KILLED && !(pPics[i].large & CCOM_LR_TAKEN)) { continue; } block.com.type = TYPE_TEXT;//Текст, Картинка, Таблица; block.com.number = 0;//порядковый номер block.com.count = 4; block.com.Flags = 0; block.com.Vertex[0].rx() = pPics[i].left; block.com.Vertex[0].ry() = pPics[i].upper; block.com.Vertex[1].rx() = pPics[i].left + pPics[i].w; block.com.Vertex[1].ry() = pPics[i].upper; block.com.Vertex[2].rx() = pPics[i].left + pPics[i].w; block.com.Vertex[2].ry() = pPics[i].upper + pPics[i].h; block.com.Vertex[3].rx() = pPics[i].left; block.com.Vertex[3].ry() = pPics[i].upper + pPics[i].h; block.alphabet = 0; sprintf(tmp_str, " <4 О 1 %4d %4d %4d %4d %d \n", pPics[i].left, pPics[i].upper, pPics[i].left + pPics[i].w, pPics[i].upper, pPics[i].h); LDPUMA_FPuts(resFile_pict, tmp_str); if (pPics[i].large & CCOM_LR_TAKEN || pPics[i].w < min_image_width && pPics[i].h < min_image_height) { CPAGE_CreateBlock(hCPAGE, POSSIBLE_PICTURES, 0, 0, &block, sizeof(POLY_)); } else { CPAGE_CreateBlock(hCPAGE, TYPE_IMAGE, 0, 0, &block, sizeof(POLY_)); } } LDPUMA_FPuts(resFile_pict, " <4 К После первого прохода \n"); sprintf(tmp_str, "Amount of comps on the first step %i (tmp_comp) \n", tmp_comp); LDPUMA_FPuts(logFile_comp, tmp_str); sprintf(tmp_str, "Amount of pictures on the first step %i (nPics) \n", nPics); LDPUMA_FPuts(logFile_comp, tmp_str); LDPUMA_FPuts(logFile_comp, "*******************************************************\n"); if (pPics != NULL) { free(pPics); pPics = NULL; } nPics = 0; CloseLogRes(); Handle h = NULL; if (!LDPUMA_Skip(hShowFirstAttempt)) { h = NULL; nPics = 0; for (h = CPAGE_GetBlockFirst(hCPAGE, TYPE_IMAGE); h != NULL; h = CPAGE_GetBlockNext(hCPAGE, h, TYPE_IMAGE)) { nPics++; CPAGE_GetBlockData(hCPAGE, h, TYPE_IMAGE, &block, sizeof(block)); rect.left = block.com.Vertex[0].x(); rect.top = block.com.Vertex[0].y(); rect.right = block.com.Vertex[1].x(); rect.bottom = block.com.Vertex[2].y(); LDPUMA_DrawRect(MainWindowD, &rect, 0, color, 2, key); } if (nPics) { LDPUMA_Console("RPIC_Картинки после первого прохода \n"); LDPUMA_WaitUserInput(hShowFirstAttempt, MainWindowD); LDPUMA_DeleteRects(MainWindowD, key); } } if (!LDPUMA_Skip(hShowPossiblePics)) { h = NULL; nPics = 0; for (h = CPAGE_GetBlockFirst(hCPAGE, POSSIBLE_PICTURES); h != NULL; h = CPAGE_GetBlockNext(hCPAGE, h, POSSIBLE_PICTURES)) { nPics++; CPAGE_GetBlockData(hCPAGE, h, POSSIBLE_PICTURES, &block, sizeof(block)); rect.left = block.com.Vertex[0].x(); rect.top = block.com.Vertex[0].y(); rect.right = block.com.Vertex[1].x(); rect.bottom = block.com.Vertex[2].y(); LDPUMA_DrawRect(MainWindowD, &rect, 0, color, 2, key); } if (nPics) { LDPUMA_Console("RPIC_Неуверенные картинки после первого прохода \n"); LDPUMA_WaitUserInput(hShowPossiblePics, MainWindowD); LDPUMA_DeleteRects(MainWindowD, key); } } Handle BlockType = CPAGE_GetInternalType("pic's to letters boxes"); RPIC_Comp_Rect CompRect; if (!LDPUMA_Skip(hShowBigLetters)) { h = NULL; nPics = 0; for (h = CPAGE_GetBlockFirst(hCPAGE, BlockType); h != NULL; h = CPAGE_GetBlockNext(hCPAGE, h, BlockType)) { nPics++; CPAGE_GetBlockData(hCPAGE, h, BlockType, &CompRect, sizeof(CompRect)); rect.left = CompRect.left; rect.top = CompRect.upper; rect.right = CompRect.left + CompRect.w - 1; rect.bottom = CompRect.upper + CompRect.h - 1; LDPUMA_DrawRect(MainWindowD, &rect, 0, color, 2, key); } if (nPics) { LDPUMA_Console("RPIC_Буквицы \n"); LDPUMA_WaitUserInput(hShowBigLetters, MainWindowD); LDPUMA_DeleteRects(MainWindowD, key); } } return TRUE; }
Bool TryCutBlockOnHorizontal (BLOCK *p) { int iColumn; int iZeroEnd; Bool bNotSpace; int iBestPointSizeBreakingColumn; int nPointSizeDifference; int nBestPointSizeDifference = 0; /* To avoid warning on MPW C/C++ */ BLOCK *q, *r; # ifdef LT_DEBUG if (p -> pHorzHystogram == NULL) ErrorInternal ("pHorzHystogram not builded in TryCutBlockOnHorizontal"); # endif nHystColumnWidth = 1; nHystColumns = p -> Rect.yBottom - p -> Rect.yTop + 1; memcpy (pHystogram, p -> pHorzHystogram, nHystColumns * sizeof (int)); # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 4) if(!LDPUMA_Skip(hBlocksBreaking)) LT_GraphicsHystogramOutput ("Hystogram for horizontal breaking"); # endif bNotSpace = FALSE; for (iColumn = 0; iColumn < nHystColumns; iColumn++) { if (pHystogram [iColumn] != 0) { bNotSpace = TRUE; continue; } if (! bNotSpace) continue; for (iZeroEnd = iColumn + 1; iZeroEnd < nHystColumns && pHystogram [iZeroEnd] == 0; iZeroEnd++) { } if (iZeroEnd == nHystColumns) break; if (HorizontalBreakingCondition (p, iColumn, iZeroEnd - 1) && BlockBreakOnHorizontal (p, NULL, NULL, iColumn + p -> Rect.yTop)) { return (TRUE); } iColumn = iZeroEnd; } /* * Analysis with font accounting */ if (! bOptionPointSizeAnalysis) return (FALSE); BlockBuild_HystHorzHeightesSum (p); HystogramMakeIntegral (pHystInt1, pHystogram, nHystColumns); HystogramMakeIntegral (pHystInt2, pHystHorzHeightesSum, nHystColumns); iBestPointSizeBreakingColumn = 0; for (iColumn = 0; iColumn < nHystColumns; iColumn++) { int nAverageHeightBefore; int nAverageHeightAfter; if (pHystogram [iColumn] != 0) continue; if (pHystInt1 [iColumn] == 0 || pHystInt1 [nHystColumns - 1] - pHystInt1 [iColumn] <= 20) { continue; } nAverageHeightBefore = pHystInt2 [iColumn] / pHystInt1 [iColumn]; nAverageHeightAfter = (pHystInt2 [nHystColumns - 1] - pHystInt2 [iColumn]) / (pHystInt1 [nHystColumns - 1] - pHystInt1 [iColumn]); if (nAverageHeightBefore == 0 || nAverageHeightAfter == 0) continue; if (! ((nAverageHeightBefore-1)*2 >= nAverageHeightAfter * ZagolovokBreakingCoeff || (nAverageHeightAfter-1)*2 >= nAverageHeightBefore * ZagolovokBreakingCoeff)) { continue; } nPointSizeDifference = MAX (nAverageHeightBefore * 1000 / nAverageHeightAfter, nAverageHeightAfter * 1000 / nAverageHeightBefore); if (iBestPointSizeBreakingColumn == 0 || nPointSizeDifference > nBestPointSizeDifference) { iBestPointSizeBreakingColumn = iColumn; nBestPointSizeDifference = nPointSizeDifference; } } iColumn = iBestPointSizeBreakingColumn; if (pHystInt1 [nHystColumns - 1] - pHystInt1 [iColumn] > 0 && iColumn <= (pHystInt2 [nHystColumns - 1] - pHystInt2 [iColumn]) / (pHystInt1 [nHystColumns - 1] - pHystInt1 [iColumn]) / 2) { /* Strange case: its possibly dots above letters */ return (FALSE); } if (BlockBreakOnHorizontal (p, &q, &r, iBestPointSizeBreakingColumn + p -> Rect.yTop)) { # ifdef LT_DEBUG //if (LT_DebugGraphicsLevel >= 3) if(!LDPUMA_Skip(hBlocksBreaking)) { pDebugBlock = q; LT_GraphicsBlockOutput2 ("Block was breaked using " "Horz PointSizeAnalysis"); pDebugBlock = r; LT_GraphicsBlockOutput2 ("Block was breaked using " "Horz PointSizeAnalysis"); LT_Getch (); LT_GraphicsClearScreen (); } # endif return (TRUE); } return (FALSE); }
Bool CutComp(Handle hCPAGE, CCOM_handle hCCOM, CCOM_comp* comp, int bound, Bool fl_cut) { RecRaster rast; int ii; if (!CCOM_GetRaster(comp, &rast)) return FALSE; RecRaster rast2; for (ii = REC_MAX_RASTER_SIZE - 1; ii; ii--) rast2.Raster[ii] = 0; int rast_bound = (bound - comp->upper + 1) >> (comp->scale); int nowbyte = 0; int j = rast.lnPixHeight * 8 * ((rast.lnPixWidth + 63) / 64); Rect16 rect1; Rect16 rect2; CCOM_comp* comp1; CCOM_comp* comp2; uchar* lp = NULL; // uchar* old; // int16_t lp_size; // int16_t numcomp; for (ii = rast_bound * 8 * ((rast.lnPixWidth + 63) / 64); ii < j; ii++) { rast2.Raster[nowbyte] = rast.Raster[ii]; rast.Raster[ii] = 0; nowbyte++; } rast2.lnPixHeight = rast.lnPixHeight - rast_bound; rast2.lnPixWidth = rast.lnPixWidth; rast2.lnRasterBufSize = REC_MAX_RASTER_SIZE; rast.lnPixHeight = rast_bound; rect1.top = comp->upper; rect1.bottom = bound; rect1.left = comp->left; rect1.right = rect1.left + comp->w - 1; rect2.top = bound + 1; rect2.bottom = comp->upper + comp->h - 1; rect2.left = comp->left; rect2.right = comp->left + comp->w - 1; // CleanRaster(&rast,&rect1,comp->scale); // CleanRaster(&rast2,&rect2,comp->scale); comp1 = CCOM_New(hCCOM, rect1.top, rect1.left, rect1.right - rect1.left + 1, rect1.bottom - rect1.top + 1); if (!comp1) return FALSE; comp2 = CCOM_New(hCCOM, rect2.top, rect2.left, rect2.right - rect2.left + 1, rect2.bottom - rect2.top + 1); if (!comp2) { CCOM_Delete(hCCOM, comp1); return FALSE; } comp1->scale = comp2->scale = comp->scale; while (comp1->scale) { if (!Increase2(&rast, comp1)) break; } while (comp2->scale) { if (!Increase2(&rast2, comp2)) break; } CCOM_Delete(hCCOM, comp1); CCOM_Delete(hCCOM, comp2); CCOM_cont * hCutCCOM1 = 0; CCOM_handle hCutCCOM2 = 0; Rect16 Rc; Rc.left = comp->left; Rc.right = comp->left + comp->w - 1; Rc.top = comp->upper; Rc.bottom = bound; int min_h_1 = inf_let_h; int min_h_2 = inf_let_h; if (type_let == 1) min_h_1 = inf_dust_h; if (type_let == 2) min_h_2 = inf_dust_h; hCutCCOM1 = GetStrCCOM(hCPAGE, NULL, Rc, FALSE, FALSE, &rast, min_h_1); if (!hCutCCOM1) return FALSE; Rc.left = comp->left; Rc.right = comp->left + comp->w - 1; Rc.top = bound + 1; Rc.bottom = comp->upper + comp->h - 1; hCutCCOM2 = GetStrCCOM(hCPAGE, NULL, Rc, FALSE, FALSE, &rast2, min_h_2); if (!hCutCCOM2) { CCOM_DeleteContainer(hCutCCOM1); return FALSE; } comp1 = CCOM_GetFirst(hCutCCOM1, NULL); if (comp1 == NULL) { CCOM_DeleteContainer(hCutCCOM1); CCOM_DeleteContainer(hCutCCOM2); return FALSE; } CCOM_comp* newcomp; CCOM_comp* prev_comp = comp1; while (comp1) { newcomp = CCOM_New(hCCOM, comp1->upper + comp->upper - 1, comp1->left + comp->left, comp1->w, comp1->h); if (newcomp) { CCOM_Copy(newcomp, comp1); MyCreateComp(newcomp); } prev_comp = comp1; comp1 = CCOM_GetNext(comp1, NULL); } comp1 = prev_comp; comp2 = CCOM_GetFirst(hCutCCOM2, NULL); if (comp2) prev_comp = comp2; else prev_comp = comp1; while (comp2) { newcomp = CCOM_New(hCCOM, comp2->upper + bound, comp2->left + comp->left, comp2->w, comp2->h); if (newcomp) { CCOM_Copy(newcomp, comp2); MyCreateComp(newcomp); } prev_comp = comp2; comp2 = CCOM_GetNext(comp2, NULL); } comp2 = prev_comp; comp1->upper += comp->upper - 1; comp1->left += comp->left; if (comp2 != comp1) { comp2->upper += bound; comp2->left += comp->left; } FILE* f = NULL; if (fl_cut == 0) f = f_cut_comp; if (fl_cut == 1) f = f_cut_str; if (f) { int max_count = 6; int i; // if(oldRoot.top>comp->upper||oldRoot.bottom<comp->upper+comp->h-1||oldRoot.left>comp->left||oldRoot.right<comp->left+comp->w-1) // { fprintf(f, "Top:%d", comp1->upper); for (i = GetCountNumbers(comp1->upper); i <= max_count; i++) fprintf(f, " "); fprintf(f, "Bottom:%d", comp1->upper + comp1->h - 1); for (i = GetCountNumbers(comp1->upper + comp1->h - 1); i <= max_count; i++) fprintf(f, " "); fprintf(f, "Left:%d", comp1->left); for (i = GetCountNumbers(comp1->left); i <= max_count; i++) fprintf(f, " "); fprintf(f, "Right:%d", comp1->left + comp1->w - 1); for (i = GetCountNumbers(comp1->left + comp1->w - 1); i <= max_count; i++) fprintf(f, " "); fprintf(f, "\n"); fprintf(f, "Top:%d", comp2->upper); for (i = GetCountNumbers(comp2->upper); i <= max_count; i++) fprintf(f, " "); fprintf(f, "Bottom:%d", comp2->upper + comp2->h - 1); for (i = GetCountNumbers(comp2->upper + comp2->h - 1); i <= max_count; i++) fprintf(f, " "); fprintf(f, "Left:%d", comp2->left); for (i = GetCountNumbers(comp2->left); i <= max_count; i++) fprintf(f, " "); fprintf(f, "Right:%d", comp2->left + comp2->w - 1); for (i = GetCountNumbers(comp2->left + comp2->w - 1); i <= max_count; i++) fprintf(f, " "); fprintf(f, "\n"); /* oldRoot.top=comp->upper; oldRoot.bottom=comp->upper+comp->h-1; oldRoot.left=comp->left; oldRoot.right=comp->left+comp->w-1; } */ } FILE* f_temp = NULL; if (fl_cut == 0) f_temp = f_temp_cut_comp; if (fl_cut == 1) f_temp = f_temp_cut; if (f_temp) { int max_count = 6; int i; // if(oldRoot.top>comp->upper||oldRoot.bottom<comp->upper+comp->h-1||oldRoot.left>comp->left||oldRoot.right<comp->left+comp->w-1) // { fprintf(f_temp, "Top:%d", comp1->upper); for (i = GetCountNumbers(comp1->upper); i <= max_count; i++) fprintf(f_temp, " "); fprintf(f_temp, "Bottom:%d", comp1->upper + comp1->h - 1); for (i = GetCountNumbers(comp1->upper + comp1->h - 1); i <= max_count; i++) fprintf(f_temp, " "); fprintf(f_temp, "Left:%d", comp1->left); for (i = GetCountNumbers(comp1->left); i <= max_count; i++) fprintf(f_temp, " "); fprintf(f_temp, "Right:%d", comp1->left + comp1->w - 1); for (i = GetCountNumbers(comp1->left + comp1->w - 1); i <= max_count; i++) fprintf(f_temp, " "); fprintf(f_temp, "\n"); fprintf(f_temp, "Top:%d", comp2->upper); for (i = GetCountNumbers(comp2->upper); i <= max_count; i++) fprintf(f_temp, " "); fprintf(f_temp, "Bottom:%d", comp2->upper + comp2->h - 1); for (i = GetCountNumbers(comp2->upper + comp2->h - 1); i <= max_count; i++) fprintf(f_temp, " "); fprintf(f_temp, "Left:%d", comp2->left); for (i = GetCountNumbers(comp2->left); i <= max_count; i++) fprintf(f_temp, " "); fprintf(f_temp, "Right:%d", comp2->left + comp2->w - 1); for (i = GetCountNumbers(comp2->left + comp2->w - 1); i <= max_count; i++) fprintf(f_temp, " "); fprintf(f_temp, "\n"); /* oldRoot.top=comp->upper; oldRoot.bottom=comp->upper+comp->h-1; oldRoot.left=comp->left; oldRoot.right=comp->left+comp->w-1; } */ } if ((!LDPUMA_Skip(CutCompD) && fl_cut == 0) || (!LDPUMA_Skip(CutStrD) && fl_cut == 1)) { if (!WasCutComp && fl_cut == 0) WasCutComp = TRUE; if (!WasCut && fl_cut == 1) WasCut = TRUE; DrawRect(MainWindowD, code_comp_cut_d, RGB(255,0,0), comp1->upper, comp1->upper + comp1->h - 1, comp1->left, comp1->left + comp1->w - 1); DrawRect(MainWindowD, code_comp_cut_d, RGB(255,0,0), comp2->upper, comp2->upper + comp2->h - 1, comp2->left, comp2->left + comp2->w - 1); } CCOM_DeleteContainer(hCutCCOM1); CCOM_DeleteContainer(hCutCCOM2); MyKillComp(comp); return TRUE; // delete[] lp; }
RNEG_FUNC(void) RNEG_RecogNeg(CCOM_handle hCCOM, Handle hCPage,uchar* pImageName,int skew) { MainWindowD=NULL; MainWindowD=LDPUMA_GetWindowHandle ("Изображение после разворота"); if(!MainWindowD) MainWindowD=LDPUMA_GetWindowHandle ("Main"); dpTime=!LDPUMA_Skip(hTime); dpPrintResConsole=!LDPUMA_Skip(PrintResConsole); dpNegResD=!LDPUMA_Skip(NegResD); dpNegRecD=!LDPUMA_Skip(NegRecD); dpRecOneLetter=!LDPUMA_Skip(RecOneLetter); // LDPUMA_ConsoleN(""); if(dpTime) LDPUMA_ConsoleN("Активизируется функция поиска и разпознования негативов"); int time=clock(); if(!(LDPUMA_Skip (NegSearch)) ) return; uint32_t code_sersized=(512<<16); uint32_t code_normd=(512<<17); uint32_t code_colord=(512<<17)+(512<<16); uint32_t code_cutd=(512<<18); uint32_t code_cutstrd=(512<<18)+(512<<16); uint32_t code_sized=(512<<18)+(512<<17); #define NEGA 1<<14 #define VERTICA 1<<13 inf_neg_h=30; inf_neg_w=100; neg_cut_black=.95; neg_cut_white=.3; neg_cut_str=.8; min_let_h=2; min_let_w=2; inf_betw_str_h=10; sup_square=500000; PAGEINFO info = {0}; GetPageInfo(hCPage,&info); DPIX=info.DPIX; DPIY=info.DPIY; inf_neg_h=inf_neg_h*((int)(DPIY)+1)/300; inf_neg_w=inf_neg_w*((int)(DPIX)+1)/300; inf_betw_str_h=inf_betw_str_h*((int)(DPIY)+1)/300; sup_square=(int)(((double)sup_square*(double)(DPIY+1)*(double)(DPIX+1))/90000); min_let_w=min_let_w*((int)(DPIX)+1)/300; min_let_h=min_let_h*((int)(DPIY)+1)/300; if((info.Angle==90)||(info.Angle==270)) { Height=info.Width; Width=info.Height; } else { Height=info.Height; Width=info.Width; } NegList* root=NULL; NegList* now; NegList* temp; int nRC=0; int i; Bool fl_del_mas_neg; Bool flag_rotate; Bool flag_rimage_rotate; if(!LDPUMA_Skip(SetSkew)) skew=Skew; for(i=0;i<CPAGE_MAXNAME&&pImageName[i]!='\0';i++) ImageName[i]=pImageName[i]; if(i<CPAGE_MAXNAME) ImageName[i]='\0'; if(!InitMyImage()) return; if(dpTime) { LDPUMA_ConsoleN("Time prep=%d",clock()-time); time=clock(); } /* Осуществляется поиск кандидатов в негативы по размеру*/ if(LDPUMA_Skip (NegSearchSize) ) { fl_del_mas_neg=SearchNegBySize(hCCOM,hCPage,&root,nRC); /*Прорисовка найденных кандидатов в негативы по размерам*/ if(nRC>0) { now=root; if(!(LDPUMA_Skip (NegSearchSizeD)) ) { for(i=0;i<nRC;i++) { NegDrawRect(MainWindowD,code_sersized,RGB(0,0,255),(now->neg).pRc[0]); now=now->next; } LDPUMA_ConsoleN("По размерам"); LDPUMA_WaitUserInput (NegSearchSizeD,MainWindowD); if(LDPUMA_Skip (NegSearchSizeDC) ) LDPUMA_DeleteRects (MainWindowD,code_sersized); } } } flag_rimage_rotate=IfNeedGlobalRotate(root,skew); now=root; while(now) { while((now->neg).pRc[0].top<=0) ((now->neg).pRc[0].top)++; while(((now->neg).pRc[0].bottom+1)>Height ) ((now->neg).pRc[0].bottom)--; while((now->neg).pRc[0].left<0) ((now->neg).pRc[0].left)++; while( ((now->neg).pRc[0].right+1)>Width ) ((now->neg).pRc[0].right)--; int prewide=(((now->neg).pRc[0].right-(now->neg).pRc[0].left+8)/8)*8; if( ((now->neg).pRc[0].left+prewide)>Width ) (now->neg).pRc[0].right-=8; now=now->next; } /* Осуществляется удаление(если повезёт) грязи, т.е. приведение негатива к каноническому виду*/ if(LDPUMA_Skip (NegNorm) ) { /* Поворот (если необходим) негативов*/ flag_rotate=NegRotate(hCPage,root,nRC,skew); now=root; for(i=1;i<nRC;i++) now=now->next; i=nRC-1; while(i>=0) { temp=now->prev; NormNeg(hCPage,now,&root,nRC); i--; now=temp; } /*Обратное преобразование*/ if(flag_rotate) { now=root; while(now) { if((now->neg).rot.pmasp) { RSELSTR_UnRotateRect(-skew,&((now->neg).pRc[0]),1,(now->neg).rot.Rc,(now->neg).rot.begx,(now->neg).rot.movey,(now->neg).rot.flmovey,(now->neg).rot.hi); PostRotate(now,skew); } DeleteRotateMas(&((now->neg).rot.pmasp),&((now->neg).rot.begx),&((now->neg).rot.movey),&((now->neg).rot.flmovey),&((now->neg).rot.hi)); now=now->next; } } /* Прорисовка нормализованных кандидатов в негативы*/ if(nRC>0) { now=root; if(!(LDPUMA_Skip (NegNormD)) ) { for(i=0;i<nRC;i++) { NegDrawRect(MainWindowD,code_normd,RGB(0,255,0),(now->neg).pRc[0]); now=now->next; } LDPUMA_ConsoleN("Нормализованные"); LDPUMA_WaitUserInput (NegNormD,MainWindowD); if(LDPUMA_Skip (NegNormDC) ) LDPUMA_DeleteRects (MainWindowD,code_normd); } } } /* Резка сложных негативов*/ if(LDPUMA_Skip (NegCut) ) { /* Поворот (если необходим) негативов*/ flag_rotate=NegRotate(hCPage,root,nRC,skew); CutNeg(hCPage,&root,nRC,skew); /* Поворот (если необходим) негативов*/ flag_rotate=NegRotate(hCPage,root,nRC,skew); now=root; for(i=1;i<nRC;i++) now=now->next; i=nRC-1; while(i>=0) { temp=now->prev; NormNeg(hCPage,now,&root,nRC); i--; now=temp; } /*Обратное преобразование*/ if(flag_rotate) { now=root; while(now) { if((now->neg).rot.pmasp) { RSELSTR_UnRotateRect(-skew,&((now->neg).pRc[0]),1,(now->neg).rot.Rc,(now->neg).rot.begx,(now->neg).rot.movey,(now->neg).rot.flmovey,(now->neg).rot.hi); PostRotate(now,skew); } DeleteRotateMas(&((now->neg).rot.pmasp),&((now->neg).rot.begx),&((now->neg).rot.movey),&((now->neg).rot.flmovey),&((now->neg).rot.hi)); now=now->next; } } /* Прорисовка разрезанных негативов*/ if(nRC>0) { now=root; if(!(LDPUMA_Skip (NegCutD)) ) { for(i=0;i<nRC;i++) { NegDrawRect(MainWindowD,code_cutd,RGB(255,0,0),(now->neg).pRc[0]); now=now->next; } LDPUMA_ConsoleN("Разрезанные"); LDPUMA_WaitUserInput (NegCutD,MainWindowD); if(LDPUMA_Skip (NegCutDC) ) LDPUMA_DeleteRects (MainWindowD,code_cutd); } } } now=root; for(i=1;i<nRC;i++) now=now->next; int h; int w; Rect16 Rc; /*Отсев по размеру*/ if(LDPUMA_Skip (NegSize) ) { while(now) { h=(now->neg).pRc[0].bottom-(now->neg).pRc[(now->neg).nRc-1].top+1; w=(now->neg).pRc[0].right-(now->neg).pRc[0].left+1; if( ((h<2*w)&&(w<2*h)) || ((h*w)>sup_square) ) { temp=now; if(!temp->prev) root=temp->next; nRC--; now=now->prev; delete temp; } else now=now->prev; } /* Прорисовка отсеянных по размеру*/ if(nRC>0) { now=root; if(!(LDPUMA_Skip (NegSizeD)) ) { for(i=0;i<nRC;i++) { Rc.left=(now->neg).pRc[0].left; Rc.right=(now->neg).pRc[0].right; Rc.bottom=(now->neg).pRc[0].bottom; Rc.top=(now->neg).pRc[(now->neg).nRc-1].top; NegDrawRect(MainWindowD,code_sized,RGB(255,255,0),Rc); now=now->next; } LDPUMA_ConsoleN("Окончательная прорисовка"); LDPUMA_WaitUserInput (NegSizeD,MainWindowD); if(LDPUMA_Skip (NegSizeDC) ) LDPUMA_DeleteRects (MainWindowD,code_sized); } } } /* Поворот (если необходим) негативов*/ flag_rotate=NegRotate(hCPage,root,nRC,skew); /* Осуществляется отсев кандидатов в негативы по насыщенности чёрного цвета*/ if(LDPUMA_Skip (NegColor) ) { SearchNegByBlack(hCPage,&root,nRC); /*Прорисовка кандидатов в негативы после отсева по цветовой гамме*/ if(nRC>0) { now=root; if(!(LDPUMA_Skip (NegColorD)) ) { for(i=0;i<nRC;i++) { NegDrawRect(MainWindowD,code_colord,RGB(0,255,255),(now->neg).pRc[0]); now=now->next; } LDPUMA_ConsoleN("Отсеянные по цветовой гамме"); LDPUMA_WaitUserInput (NegColorD,MainWindowD); if(LDPUMA_Skip (NegColorDC) ) LDPUMA_DeleteRects (MainWindowD,code_colord); } } } /* Резка многострочных негативов*/ if(LDPUMA_Skip (NegCutStr) ) { CutNegStr(hCPage,&root,nRC,skew); /* Прорисовка разрезанных негативов*/ if(nRC>0) { now=root; if(!(LDPUMA_Skip (NegCutStrD)) ) { while(now) { for(i=0;i<(now->neg).nRc;i++) NegDrawRect(MainWindowD,code_cutstrd,RGB(255,0,255),(now->neg).pRc[i]); now=now->next; } LDPUMA_ConsoleN("Разрезанные на строки"); LDPUMA_WaitUserInput (NegCutStrD,MainWindowD); if(LDPUMA_Skip (NegCutStrDC) ) LDPUMA_DeleteRects (MainWindowD,code_cutstrd); } } } /*Отсев пересекающихся*/ DelIn(hCPage,&root,nRC); int time_stuff=clock(); if(dpTime) LDPUMA_ConsoleN("Time stuff=%d",time_stuff-time); /* Осуществляется распознование из массива кандидатов*/ if(flag_rimage_rotate) { UnRotateNeg(root,skew); ResetMyImage(); if(!InitMyImage()) return; CheckNega(root); if(!flag_rotate) flag_rotate=NegRotate(hCPage,root,nRC,skew); } if(LDPUMA_Skip (NegRec) ) { NegRecog(hCPage,&root,nRC,skew); } if(dpTime) LDPUMA_ConsoleN("Time recog=%d",clock()-time_stuff); if(!(LDPUMA_Skip (NegPrintFILE) )) { FILE *f; f=fopen("recneg.res","a"); if(f==NULL) f=fopen("recneg.res","w+"); if(f!=NULL) { NegPrintInFile(f,root,nRC); fclose(f); } } /* Отпись в CPage*/ now=root; if(1/*!(LDPUMA_Skip (PutToCPage) )*/) { POLY_ block={0}; uint32_t size_poly=sizeof(POLY_); while(now) { if((now->neg).p>inf_prob) { block.com.Flags=0; Rc.left=(now->neg).pRc[0].left; Rc.right=(now->neg).pRc[0].right; Rc.top=(now->neg).pRc[(now->neg).nRc-1].top; Rc.bottom=(now->neg).pRc[0].bottom; block.com.type = TYPE_TEXT; //Текст, Картинка, Таблица; block.com.count = 4; block.negative=TYPE_NEGATIVE; block.com.Flags=NEGA; //Andrey: moved from RBLOCK (keyword:TYPE_NEGATIVE) //------------------------------ block.alphabet=0; block.com.number=0; //------------------------------ //commented by Andrey /* if(Rc.bottom-Rc.top>Rc.right-Rc.left) { block.orient=TYPE_DOWNUP; block.com.Flags|=VERTICA; } else block.orient=TYPE_LEFTRIGHT; */ if ((now->neg).Flags&FlVert) { block.com.Flags |= VERTICA; block.orient = (now->neg).Flags&FlDown2Up ? TYPE_DOWNUP : TYPE_UPDOWN; } else block.orient = TYPE_LEFTRIGHT; block.com.Vertex[0].x = Rc.left; block.com.Vertex[0].y = Rc.top; block.com.Vertex[1].x = Rc.right; block.com.Vertex[1].y = Rc.top; block.com.Vertex[2].x = Rc.right; block.com.Vertex[2].y = Rc.bottom; block.com.Vertex[3].x = Rc.left; block.com.Vertex[3].y = Rc.bottom; //Andrey: create TYPE_TEXT block CPAGE_CreateBlock(hCPage, TYPE_IMAGE,0,0,&block,size_poly); // CPAGE_CreateBlock(hCPage, TYPE_TEXT,0,0,&block,size_poly); } now=now->next; } } if(!(LDPUMA_Skip (PutToCHSTR) )) { now=root; uchar Name[CPAGE_MAXNAME]; for (int j=0; j<CPAGE_MAXNAME; j++) Name[j] = ImageName[j]; if(!(LDPUMA_Skip (TestCHSTR) )) { CHSTR_Objects Hstr; Hstr.Rc.top=TOP; Hstr.Rc.bottom=BOTTOM; Hstr.Rc.left=LEFT; Hstr.Rc.right=RIGHT; Hstr.block_number=1000; Hstr.ImageName[0]='\0'; Hstr.type_neg=NEGATIVE; Hstr.type_vert=VERTICALE; RSELSTR_PutObjects(hCPage,(void*)hCCOM,&Hstr,1); } } PutTempToCPAGE(hCPage,root); if( (LDPUMA_Skip (NegSearchSize))&&(fl_del_mas_neg==TRUE) ) { while(root) { now=root; root=root->next; delete now; } } ResetMyImage(); // LDPUMA_ConsoleN("Time work RNEG=%d",clock()-time); }
//////////////////////////////////////////////////////////////////////////////// // Предварительная обработка // (07.07.2000) Изначально взято из puma.dll без изменений // сильно привязана к пуме // в начале окучиваем выделение компонент Bool32 PreProcessImage( PRSPreProcessImage Image ) { Bool32 gbAutoRotate = Image->gbAutoRotate; puchar *gpRecogDIB = Image->pgpRecogDIB; Handle hCPAGE = Image->hCPAGE; const char * glpRecogName = *Image->pglpRecogName; PCIMAGEBITMAPINFOHEADER info = (PCIMAGEBITMAPINFOHEADER)Image->pinfo; ///////////////////////////////// Bool32 rc = TRUE; //char * lpRecogName = NULL; uint32_t Angle = 0; hWndTurn = 0; if(InitPRGTIME()) ProgressStart(); if(!ProgressStep(1,5)) rc = FALSE; // Andrey 12.11.01 // Проинициализируем контейнер CPAGE // if(rc) { PAGEINFO PInfo = {0}; GetPageInfo(hCPAGE,&PInfo); strcpy((char*)PInfo.szImageName, glpRecogName); PInfo.BitPerPixel = info->biBitCount; PInfo.DPIX = info->biXPelsPerMeter*254L/10000; // PInfo.DPIX = PInfo.DPIX < 200 ? 200 : PInfo.DPIX; PInfo.DPIY = info->biYPelsPerMeter*254L/10000; // PInfo.DPIY = PInfo.DPIY < 200 ? 200 : PInfo.DPIY; PInfo.Height = info->biHeight; PInfo.Width = info->biWidth; // PInfo.X = 0; Уже установлено // PInfo.Y = 0; PInfo.Incline2048 = 0; PInfo.Page = 1; PInfo.Angle = Angle; SetPageInfo(hCPAGE,PInfo); } //////////////////////////////////////////////////////// // Выделим компоненты // if(!ProgressStep(2,65)) rc = FALSE; if(rc) { if(LDPUMA_Skip(Image->hDebugCancelComponent)/*DPumaSkipComponent()*/) { // uchar ori; PRGTIME prev = StorePRGTIME(65, 85); rc = ExtractComponents( gbAutoRotate, NULL, (puchar)glpRecogName, Image); RestorePRGTIME(prev); /* if(rc && gbAutoRotate) { //if(!REXC_GetOrient(&ori)) //if(!REXC_GetOrient(&ori) && db_spec_prj!=SPEC_PRJ_GIP ) if(!RNORM_GetOrient(&ori, *(Image->phCCOM)) && db_spec_prj!=SPEC_PRJ_GIP ) { SetReturnCode_rstuff(RNORM_GetReturnCode()); rc = FALSE; } else { //if(ori) if(ori && !(db_spec_prj==SPEC_PRJ_GIP&&ori==4)) { uint32_t dwTurn = 0; switch(ori) { case 1: Angle = 270; dwTurn = RIMAGE_TURN_270; break; case 2: Angle = 90; dwTurn = RIMAGE_TURN_90; break; case 3: Angle = 180; dwTurn = RIMAGE_TURN_180; break; } if( LDPUMA_Skip(Image->hDebugCancelTurn) /*umaSkipTurn()*/ /*) { if(!RIMAGE_Turn((puchar)glpRecogName,(puchar)PUMA_IMAGE_TURN,dwTurn,0)) { SetReturnCode_rstuff_rstuff(RIMAGE_GetReturnCode()); rc = FALSE; } else { if(!CIMAGE_ReadDIB((puchar)PUMA_IMAGE_TURN,(Handle*)gpRecogDIB,TRUE)) { SetReturnCode_rstuff_rstuff(CIMAGE_GetReturnCode()); rc = FALSE; } else { // // удалим общий контейнер // glpRecogName = PUMA_IMAGE_TURN; hWndTurn = LDPUMA_CreateWindow(PUMA_IMAGE_TURN,(*gpRecogDIB)); PRGTIME prev = StorePRGTIME(85, 100); rc = ExtractComponents( FALSE, NULL, (puchar)glpRecogName, Image); PAGEINFO info = {0}; GetPageInfo(hCPAGE,&info); info.Images|=IMAGE_TURN; // strcpy((char*)info.szImageName,PUMA_IMAGE_TURN); SetPageInfo(hCPAGE,info); RestorePRGTIME(prev); } } } } } }*/ //проверим наличие разрешения и попытаемся определить по компонентам, если его нет checkResolution(*(Image->phCCOM), hCPAGE); if(!ProgressStep(2,100)) rc = FALSE; } else LDPUMA_Console("Пропущен этап выделения компонент.\n"); } // // Переинициализируем контейнер CPAGE // if(rc) { PAGEINFO PInfo = {0}; GetPageInfo(hCPAGE,&PInfo); strcpy((char*)PInfo.szImageName, glpRecogName); PInfo.BitPerPixel = info->biBitCount; // PInfo.DPIX = info->biXPelsPerMeter*254L/10000; PInfo.DPIX = PInfo.DPIX < 200 ? 200 : PInfo.DPIX; // PInfo.DPIY = info->biYPelsPerMeter*254L/10000; PInfo.DPIY = PInfo.DPIY < 200 ? 200 : PInfo.DPIY; PInfo.Height = info->biHeight; PInfo.Width = info->biWidth; // PInfo.X = 0; Уже установлено // PInfo.Y = 0; PInfo.Incline2048 = 0; PInfo.Page = 1; PInfo.Angle = Angle; SetPageInfo(hCPAGE,PInfo); } if(DonePRGTIME()) ProgressFinish(); return rc; }