←Select platform

ExObjLocation Enumeration

Summary

Locations for adding to an ExObjObjectList.

Syntax
C#
Objective-C
C++/CLI
Java
Python
public enum ExObjLocation 
typedef NS_ENUM(NSUInteger, LTExObjLocation) { 
 LTExObjLocationAfter = 0,  
 LTExObjLocationBefore = 1,  
 LTExObjLocationChild = 2,  
 LTExObjLocationSibling = 3 
}; 
public final class ExObjLocation 
    extends java.lang.Enum<ExObjLocation> 
public: 
   enum class ExObjLocation sealed 
class ExObjLocation(Enum): 
   After = 0 
   Before = 1 
   Child = 2 
   Sibling = 3 
Members
Value Member Description
0 After Add to the parent list directly after the specified object
1 Before Add to the parent list directly before the specified object
2 Child Add as a child for the specified object
3 Sibling Add to the sibling list for the specified object
Remarks

When adding to Child or Sibling, if the corresponding list does not exist (ExObjObject.Children and ExObjObject.Siblings respectively), it will be created.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Core; 
 
public void ExtractObjectsCommandExample() 
{ 
   using (RasterCodecs codecs = new RasterCodecs()) 
   // Load the original image 
   using (RasterImage inputImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "demoicr2.tif"))) 
   { 
      // Setup the extraction options 
      ExtractObjectsCommand command = new ExtractObjectsCommand() 
      { 
         DetectChildren = true, 
         EightConnectivity = true, 
         Outline = true 
      }; 
 
      // Extract the objects 
      command.Run(inputImage); 
 
      using (ExObjData data = command.Data) 
      { 
         // Log the number of objects from the first list 
         ExObjObjectList objects = data[0].Objects; 
         Console.WriteLine($"Number of objects (before filtering): {objects.Count}"); 
 
         // Log the number of points around the first object (braces for scope) 
         { 
            int count = 0; 
            foreach (ExObjOutlinePoint point in objects.First().Outline) 
               count++; 
            Console.WriteLine($"First object's outline length: {count}"); 
         } 
 
         // Setup the filter options 
         ExObjFilterOptions filterOptions = new ExObjFilterOptions() 
         { 
            LargeObjectThreshold = -1, // No upper limit on size 
            SmallObjectThreshold = 10 // Remove objects smaller than 10x10 pixels 
         }; 
 
         // Filter the objects 
         data.FilterList(objects, filterOptions); 
 
         // Log the number of objects again 
         Console.WriteLine($"Number of objects (after filtering): {objects.Count}"); 
 
         // Setup the content bound options 
         ExObjContentBound contentBound = new ExObjContentBound(new LeadRect(192, 260, 323, 146)); 
         ExObjContentBoundOptions contentBoundOptions = new ExObjContentBoundOptions() 
         { 
            ObjectsOfInterest = null // Pass null to use every object in data 
         }; 
 
         // Calculate the content bounds 
         data.CalculateContentBound(new ExObjContentBound[] { contentBound }, contentBoundOptions); 
 
         // Setup the region options 
         ExObjRegionOptions regionOptions = new ExObjRegionOptions() 
         { 
            Horizontal = true 
         }; 
 
         // Calculate each object's region 
         data.CalculateRegion(objects, regionOptions); 
 
         // Create an output image 
         using (RasterImage outputImage = RasterImage.Create(inputImage.Width, inputImage.Height, 24, inputImage.XResolution, RasterColor.White)) 
         { 
            // Fill the output image with white 
            new FillCommand(RasterColor.White).Run(outputImage); 
 
            // Draw the content bound rects for the first word. Red for the input, green for the output. 
            outputImage.AddRectangleToRegion(null, contentBound.Input, RasterRegionCombineMode.Set); 
            new FillCommand(new RasterColor(255, 0, 0)).Run(outputImage); 
            outputImage.AddRectangleToRegion(null, contentBound.Content, RasterRegionCombineMode.Set); 
            new FillCommand(new RasterColor(0, 255, 0)).Run(outputImage); 
 
            // Populate the output image with each object's region 
            foreach (ExObjObject @object in objects) 
               foreach (ExObjSegment segment in @object.RegionHorizontal) 
               { 
                  // Update the region to the current segment 
                  outputImage.AddRectangleToRegion(null, segment.Bounds, RasterRegionCombineMode.Set); 
 
                  // Fill the region with black 
                  new FillCommand(RasterColor.Black).Run(outputImage); 
               } 
 
            // Clear the output image's region 
            outputImage.MakeRegionEmpty(); 
 
            // Save the output image 
            codecs.Save(outputImage, Path.Combine(LEAD_VARS.ImagesDir, "ExtractObjects.png"), RasterImageFormat.Png, 0); 
         } 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.IOException; 
import java.util.ArrayList; 
import java.util.Collection; 
import java.util.Collections; 
import java.util.Iterator; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.imageprocessing.FillCommand; 
import leadtools.imageprocessing.core.*; 
import leadtools.internal.Tuple; 
 
 
public void extractObjectsCommandExample() { 
 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
 
   RasterCodecs codecs = new RasterCodecs(); 
   // Load the original image 
   RasterImage inputImage = codecs.load(combine(LEAD_VARS_IMAGES_DIR, "demoicr2.tif")); 
 
   // Setup the extraction options 
   ExtractObjectsCommand command = new ExtractObjectsCommand(); 
   command.setDetectChildren(true); 
   command.setEightConnectivity(true); 
   command.setOutline(true); 
 
   // Extract the objects 
   command.run(inputImage); 
 
   ExObjData data = command.getData(); 
 
   // Log the number of objects from the first list 
   ExObjObjectList objects = data.iterator().next().getObjects(); 
   System.out.println("Number of objects (before filtering): " + objects.size()); 
 
   // Log the number of points around the first object (braces for scope) 
   System.out.println(objects.iterator().next().getOutline().size()); 
 
   // Setup the filter options 
   ExObjFilterOptions filterOptions = new ExObjFilterOptions(); 
   filterOptions.setLargeObjectThreshold(-1); 
   filterOptions.setSmallObjectThreshold(10); 
 
   // Filter the objects 
   data.filterList(objects, filterOptions); 
 
   // Log the number of objects again 
   System.out.println("Number of objects (after filtering): " + objects.size()); 
 
   // Setup the content bound options 
   ExObjContentBound contentBound = new ExObjContentBound(new LeadRect(192, 260, 323, 146)); 
   Collection<ExObjContentBound> col = Collections.singleton(contentBound); 
   ExObjContentBoundOptions contentBoundOptions = new ExObjContentBoundOptions(); 
   contentBoundOptions.setObjectsOfInterest(null); 
 
   // Calculate the content bounds 
   data.calculateContentBound(col, contentBoundOptions); 
 
   // Setup the region options 
   ExObjRegionOptions regionOptions = new ExObjRegionOptions(); 
   regionOptions.setHorizontal(true); 
 
   // Calculate each object's region 
   data.calculateRegion(objects, regionOptions); 
 
   // Create an output image 
   RasterImage outputImage = RasterImage.create(inputImage.getWidth(), inputImage.getHeight(), 24, 
         inputImage.getXResolution(), RasterColor.WHITE); 
 
   // Fill the output image with white 
   new FillCommand(RasterColor.WHITE).run(outputImage); 
 
   // Draw the content bound rects for the first word. Red for the input, green for 
   // the output. 
   outputImage.addRectangleToRegion(null, contentBound.getInput(), RasterRegionCombineMode.SET); 
   new FillCommand(new RasterColor(255, 0, 0)).run(outputImage); 
   outputImage.addRectangleToRegion(null, contentBound.getContent(), RasterRegionCombineMode.SET); 
   new FillCommand(new RasterColor(0, 255, 0)).run(outputImage); 
 
   // Populate the output image with each object's region 
   Iterator<ExObjObject> it = objects.iterator(); 
   while (it.hasNext()) { 
      Iterator<ExObjSegment> segments = it.next().getRegionHorizontal().iterator(); 
      while (segments.hasNext()) { 
         outputImage.addRectangleToRegion(null, segments.next().getBounds(), RasterRegionCombineMode.SET); 
         new FillCommand(RasterColor.BLACK).run(outputImage); 
      } 
   } 
 
   // Clear the output image's region 
   outputImage.makeRegionEmpty(); 
 
   // Save the output image 
   codecs.save(outputImage, combine(LEAD_VARS_IMAGES_DIR, "ExtractObjects.png"), RasterImageFormat.PNG, 0); 
 
   System.out.println("Command run and image saved to: " + combine(LEAD_VARS_IMAGES_DIR, "ExtractObjects.png")); 
   assertTrue(new File(combine(LEAD_VARS_IMAGES_DIR, "ExtractObjects.png")).exists()); 
 
   outputImage.dispose(); 
   data.dispose(); 
   inputImage.dispose(); 
   codecs.dispose(); 
} 
Requirements

Target Platforms

Help Version 23.0.2024.3.3
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.ImageProcessing.Core Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.