Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Friday, October 13, 2017 2:24:31 PM(UTC)

Walter  
Walter

Groups: Tech Support
Posts: 366

Thanks: 1 times
Was thanked: 4 time(s) in 4 post(s)

Attached is a Visual Studio 2010 project written in C++ to illustrate how to use LEADTOOLS MRC segmentation. This simplified demo uses LEADTOOLS MRC segmentation to identify different areas of a bitmap to compress out as separate files. Typically with MRC files, all of this would be wrapped up in a TIFF or PDF file. This demo just explodes the typical output into many smaller files.

The main method of the application loops through each page in a file, starts the segmentation process, and then uses a callback to enumerate the different segments found:
Code:
   for(int i = 0; i < myData.nPagesCount; i++)
   {
      nRet = myData.bitmap.Load(0, ORDER_RGB, i, &(myData.fInfo));
      if(nRet != SUCCESS) 
         goto cleanup;

      // Start the segmentation process
      nRet = segment.Start(&myData,i+1);
      if(nRet == SUCCESS) 
      {

         /* do the auto-segmentation*/ 
         nRet = segment.FindSegments(&myData); 

         if(nRet == SUCCESS) 
         { 
            segment.EnableCallBack  (TRUE); 
            nRet = segment.MrcEnumSegments (0); 
            segment.EnableCallBack(FALSE); 
         } 
         /* end the segmentation process */ 
         nRet = segment.Stop();

         if(nRet != SUCCESS) 
            goto cleanup;
      } 
      else 
         goto cleanup;
   }


The magic happens in the MrcEnumSegmentsCallBack(). A lot of the code written for this was to generate a new file name each time, and then check the pSegmentData->uType to see what type of segment was identified. Based on this, different raster compressions would be used to save out the individual segments.

Code:
   // Figure out the type of file to save
   if(pSegmentData->uType == SEGTYPE_BACKGROUND)
   {
      fileFormat = FILE_TIFLZW;
   }
   else if(pSegmentData->uType == SEGTYPE_ONECOLOR)
   {
      bitsPerPixel = 1;
      fileFormat = FILE_PNG;
      szFileExtension = L_TEXT(".png");
   }
   else if(pSegmentData->uType == SEGTYPE_TEXT_1BIT_BW)
   {
      bitsPerPixel = 1;
      fileFormat = FILE_JBIG2;
      szFileExtension = L_TEXT(".jb2");
   }
   else if(pSegmentData->uType == SEGTYPE_TEXT_1BIT_COLOR)
   {
      bitsPerPixel = 1;
      fileFormat = FILE_PNG;
      szFileExtension = L_TEXT(".png");
   }
   else if(pSegmentData->uType == SEGTYPE_TEXT_2BITBW || pSegmentData->uType == SEGTYPE_TEXT_2BIT_COLOR || pSegmentData->uType == SEGTYPE_GRAYSCALE_2BIT)
   {
      bitsPerPixel = 2;
      fileFormat = FILE_TIFLZW;
      szFileExtension = L_TEXT(".tif");
   }
   else if(pSegmentData->uType == SEGTYPE_GRAYSCALE_8BIT)
   {
      bitsPerPixel = 8;
      fileFormat = FILE_JPEG;
      szFileExtension = L_TEXT(".jpg");
   }
   else if(pSegmentData->uType == SEGTYPE_PICTURE)
   {
      bitsPerPixel = 24;
      fileFormat = FILE_JPEG;
      szFileExtension = L_TEXT(".jpg");
   }

   ...

   // Save the segment to file
   if(m_DemoData != NULL)
   {
      LBitmapBase tempBitmap;
      tempBitmap.CopyRect(m_DemoData->bitmap, pSegmentData->rcBitmapSeg);
      tempBitmap.Save(szOutputFileName, fileFormat, bitsPerPixel, QUALITY_FACTOR, SAVE_FLAGS);
   }


The code targets the LEADTOOLS 19 VC10 binaries. To run this project, please do the following:
1.) Extract the project to the following directory:
C:\LEADTOOLS 19\Examples\posts\t12327\
2.) In Main.cpp, update Developer license and key on lines 18 & 19
3.) (Optional) In DemoData.cpp, update the input file on line 4 and output directory on line 11
File Attachment(s):
C_MRC_SaveIndividualSegments.zip (40kb) downloaded 171 time(s).
Walter Bates
Senior Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.049 seconds.